From f4b381febb25cbd6657b706e5e748a33585f04e0 Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Fri, 8 Mar 2019 16:11:42 +0100 Subject: [PATCH] Replace valloc() with posix_memalign(). valloc() no longer exists in some toolchains like Android arm64. --- block_to_imp.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/block_to_imp.c b/block_to_imp.c index f70c1c7..1dbb89c 100644 --- a/block_to_imp.c +++ b/block_to_imp.c @@ -56,11 +56,6 @@ void __clear_cache(void* start, void* end); #define PROT_EXEC 0x1 #endif -static void *valloc(size_t len) -{ - return VirtualAlloc(NULL, len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); -} - static int mprotect(void *buffer, size_t len, int prot) { DWORD oldProt = 0, newProt = PAGE_NOACCESS; @@ -165,8 +160,11 @@ static id invalid(id self, SEL _cmd) static struct trampoline_set *alloc_trampolines(char *start, char *end) { struct trampoline_set *metadata = calloc(1, sizeof(struct trampoline_set)); - metadata->buffers = - valloc(sizeof(struct trampoline_buffers)); +#if _WIN32 + metadata->buffers = VirtualAlloc(NULL, sizeof(struct trampoline_buffers), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); +#else + posix_memalign((void **)&metadata->buffers, getpagesize(), sizeof(struct trampoline_buffers)); +#endif for (int i=0 ; ibuffers->headers[i].fnptr = (void(*)(void))invalid;