SELinux compatibility: memalign -> mmap

This commit is contained in:
WPMGPRoSToTeMa
2016-01-01 05:12:55 +03:00
parent 866339eff6
commit 48d7a04c73
7 changed files with 33 additions and 17 deletions

View File

@ -562,10 +562,10 @@ namespace Trampolines
#elif defined(__GNUC__)
# if defined(__APPLE__)
void *ret = valloc(m_size);
# else
void *ret=memalign(sysconf(_SC_PAGESIZE), m_size);
# endif
mprotect(ret,m_size,PROT_READ|PROT_WRITE|PROT_EXEC);
# else
void *ret=mmap(nullptr, m_size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
# endif
#endif
memcpy(ret, m_buffer, m_size);
@ -588,7 +588,7 @@ namespace Trampolines
/**
* Utility to make a generic trampoline.
*/
inline void *CreateGenericTrampoline(bool thiscall, bool voidcall, bool retbuf, int paramcount, void *extraptr, void *callee)
inline void *CreateGenericTrampoline(bool thiscall, bool voidcall, bool retbuf, int paramcount, void *extraptr, void *callee, int *size)
{
Trampolines::TrampolineMaker tramp;
@ -628,7 +628,7 @@ inline void *CreateGenericTrampoline(bool thiscall, bool voidcall, bool retbuf,
}
#endif
return tramp.Finish(NULL);
return tramp.Finish(size);
};

View File

@ -37,9 +37,10 @@ public:
int del; // 1 if this hook should be destroyed after exec
void *tramp; // trampoline for this hook
char *ent; // ent name that's being hooked
int trampSize;
Hook(void **vtable_, int entry_, void *target_, bool voidcall, bool retbuf, int paramcount, char *name) :
func(NULL), vtable(vtable_), entry(entry_), target(target_), exec(0), del(0), tramp(NULL)
func(NULL), vtable(vtable_), entry(entry_), target(target_), exec(0), del(0), tramp(NULL), trampSize(0)
{
// original function is vtable[entry]
// to not make the compiler whine, cast vtable to int **
@ -48,7 +49,7 @@ public:
// now install a trampoline
// (int thiscall, int voidcall, int paramcount, void *extraptr)
tramp = CreateGenericTrampoline(true, voidcall, retbuf, paramcount, (void*)this, target);
tramp = CreateGenericTrampoline(true, voidcall, retbuf, paramcount, (void*)this, target, &trampSize);
// Insert into vtable
#if defined(_WIN32)
@ -82,7 +83,9 @@ public:
ivtable[entry]=(int *)func;
#if defined(_WIN32)
VirtualFree(tramp, 0, MEM_RELEASE);
#elif defined(__linux__) || defined(__APPLE__)
#elif defined(__linux__)
munmap(tramp, trampSize);
#elif defined(__APPLE__)
free(tramp);
#endif