From 944f608f097ca5a74574ae885364d786c560dcba Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Mon, 4 Feb 2013 07:31:32 -0600 Subject: [PATCH] Fixed hamsandwich vtable patching on Linux for newer GCC binaries. --- dlls/hamsandwich/hook.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dlls/hamsandwich/hook.h b/dlls/hamsandwich/hook.h index 2d2c6ee4..46b75b7e 100644 --- a/dlls/hamsandwich/hook.h +++ b/dlls/hamsandwich/hook.h @@ -35,6 +35,8 @@ // This is just a simple container for data so I only have to add 1 extra // parameter to calls that get trampolined +#define ALIGN(ar) ((intptr_t)ar & ~(sysconf(_SC_PAGESIZE)-1)) + class Hook { public: @@ -66,7 +68,8 @@ public: DWORD OldFlags; VirtualProtect(&ivtable[entry],sizeof(int*),PAGE_READWRITE,&OldFlags); #elif defined __linux__ - mprotect(&ivtable[entry],sizeof(int*),PROT_READ|PROT_WRITE); + void *addr = (void *)ALIGN(&ivtable[entry]); + mprotect(addr,sysconf(_SC_PAGESIZE),PROT_READ|PROT_WRITE); #endif ivtable[entry]=(int*)tramp; @@ -84,8 +87,9 @@ public: #if defined _WIN32 DWORD OldFlags; VirtualProtect(&ivtable[entry],sizeof(int*),PAGE_READWRITE,&OldFlags); -#elif defined __linux__ - mprotect(&ivtable[entry],sizeof(int*),PROT_READ|PROT_WRITE); +#elif defined __linux_ + void *addr = (void *)ALIGN(&ivtable[entry]); + mprotect(addr,sysconf(_SC_PAGESIZE),PROT_READ|PROT_WRITE); #endif ivtable[entry]=(int *)func;