[llvm-commits] [compiler-rt] r161169 - in /compiler-rt/trunk/lib/interception: interception_win.cc interception_win.h

Alexey Samsonov samsonov at google.com
Thu Aug 2 04:29:14 PDT 2012


Author: samsonov
Date: Thu Aug  2 06:29:14 2012
New Revision: 161169

URL: http://llvm.org/viewvc/llvm-project?rev=161169&view=rev
Log:
Follow-up for r161168 for Windows

Modified:
    compiler-rt/trunk/lib/interception/interception_win.cc
    compiler-rt/trunk/lib/interception/interception_win.h

Modified: compiler-rt/trunk/lib/interception/interception_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_win.cc?rev=161169&r1=161168&r2=161169&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/interception_win.cc (original)
+++ compiler-rt/trunk/lib/interception/interception_win.cc Thu Aug  2 06:29:14 2012
@@ -14,22 +14,23 @@
 
 #ifdef _WIN32
 
+#include "interception.h"
 #include <windows.h>
 
 namespace __interception {
 
-bool GetRealFunctionAddress(const char *func_name, void **func_addr) {
+bool GetRealFunctionAddress(const char *func_name, uptr *func_addr) {
   const char *DLLS[] = {
     "msvcr80.dll",
     "msvcr90.dll",
     "kernel32.dll",
     NULL
   };
-  *func_addr = NULL;
-  for (size_t i = 0; *func_addr == NULL && DLLS[i]; ++i) {
+  *func_addr = 0;
+  for (size_t i = 0; *func_addr == 0 && DLLS[i]; ++i) {
     *func_addr = GetProcAddress(GetModuleHandleA(DLLS[i]), func_name);
   }
-  return (*func_addr != NULL);
+  return (*func_addr != 0);
 }
 
 // FIXME: internal_str* and internal_mem* functions should be moved from the
@@ -55,7 +56,7 @@
   *(ptrdiff_t*)(jmp_from + 1) = offset;
 }
 
-bool OverrideFunction(void *old_func, void *new_func, void **orig_old_func) {
+bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func) {
 #ifdef _WIN64
 # error OverrideFunction was not tested on x64
 #endif
@@ -125,20 +126,21 @@
 
   // Now put the "jump to trampoline" instruction into the original code.
   DWORD old_prot, unused_prot;
-  if (!VirtualProtect(old_func, head, PAGE_EXECUTE_READWRITE, &old_prot))
+  if (!VirtualProtect((void*)old_func, head, PAGE_EXECUTE_READWRITE,
+                      &old_prot))
     return false;
 
   // Put the needed instructions into the trampoline bytes.
   _memcpy(trampoline, old_bytes, head);
   WriteJumpInstruction(trampoline + head, old_bytes + head);
-  *orig_old_func = trampoline;
+  *orig_old_func = (uptr)trampoline;
   pool_used += head + 5;
 
   // Intercept the 'old_func'.
   WriteJumpInstruction(old_bytes, (char*)new_func);
   _memset(old_bytes + 5, 0xCC /* int 3 */, head - 5);
 
-  if (!VirtualProtect(old_func, head, old_prot, &unused_prot))
+  if (!VirtualProtect((void*)old_func, head, old_prot, &unused_prot))
     return false;  // not clear if this failure bothers us.
 
   return true;

Modified: compiler-rt/trunk/lib/interception/interception_win.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_win.h?rev=161169&r1=161168&r2=161169&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/interception_win.h (original)
+++ compiler-rt/trunk/lib/interception/interception_win.h Thu Aug  2 06:29:14 2012
@@ -23,19 +23,22 @@
 
 namespace __interception {
 // returns true if a function with the given name was found.
-bool GetRealFunctionAddress(const char *func_name, void **func_addr);
+bool GetRealFunctionAddress(const char *func_name, uptr *func_addr);
 
 // returns true if the old function existed, false on failure.
-bool OverrideFunction(void *old_func, void *new_func, void **orig_old_func);
+bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func);
 }  // namespace __interception
 
 #if defined(_DLL)
 # define INTERCEPT_FUNCTION_WIN(func) \
-    ::__interception::GetRealFunctionAddress(#func, (void**)&REAL(func))
+    ::__interception::GetRealFunctionAddress( \
+        #func, (::__interception::uptr*)&REAL(func))
 #else
 # define INTERCEPT_FUNCTION_WIN(func) \
-    ::__interception::OverrideFunction((void*)func, (void*)WRAP(func), \
-                                       (void**)&REAL(func))
+    ::__interception::OverrideFunction( \
+        (::__interception::uptr)func, \
+        (::__interception::uptr)WRAP(func), \
+        (::__interception::uptr*)&REAL(func))
 #endif
 
 #endif  // INTERCEPTION_WIN_H





More information about the llvm-commits mailing list