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

@ -77,18 +77,20 @@ inline unsigned char *AllocatePageMemory(size_t size)
#elif defined __GNUC__
#if defined __APPLE__
unsigned char *addr = (unsigned char *)valloc(size);
#else
unsigned char *addr = (unsigned char *)memalign(sysconf(_SC_PAGESIZE), size);
#endif
mprotect(addr, size, PROT_READ | PROT_WRITE | PROT_EXEC);
#else
unsigned char *addr = (unsigned char *)mmap(nullptr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#endif
return addr;
#endif
}
inline void FreePageMemory(void *addr)
inline void FreePageMemory(void *addr, size_t size)
{
#if defined(WIN32)
VirtualFree(addr, 0, MEM_RELEASE);
#elif defined(__linux__)
munmap(addr, size);
#else
free(addr);
#endif

View File

@ -186,6 +186,7 @@ jit_rewind:
//spengine->SetReadWrite(wr.outbase);
wr.outptr = wr.outbase;
detour_trampoline = wr.outbase;
detour_trampolineSize = CodeSize;
goto jit_rewind;
}
@ -206,7 +207,7 @@ void CDetour::DeleteDetour()
if (detour_trampoline)
{
/* Free the allocated trampoline memory */
FreePageMemory(detour_trampoline);
FreePageMemory(detour_trampoline, detour_trampolineSize);
detour_trampoline = NULL;
}
}

View File

@ -199,6 +199,7 @@ private:
void *detour_address;
/* Address of the allocated trampoline function */
void *detour_trampoline;
size_t detour_trampolineSize;
/* Address of the callback handler */
void *detour_callback;
/* The function pointer used to call our trampoline */