From a292bd33e1212057f7abc86210b5eeefc3c68e7f Mon Sep 17 00:00:00 2001 From: Zeex Date: Wed, 11 Nov 2020 01:54:03 +0600 Subject: Don't use MAP_32BIT on macOS This flag requires use of entitlements i.e. code signing... --- subhook_unix.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'subhook_unix.c') diff --git a/subhook_unix.c b/subhook_unix.c index d0d1251..6a5410b 100644 --- a/subhook_unix.c +++ b/subhook_unix.c @@ -40,15 +40,18 @@ int subhook_unprotect(void *address, size_t size) { } void *subhook_alloc_code(size_t size) { - return mmap(NULL, - size, - SUBHOOK_CODE_PROTECT_FLAGS, - #ifdef MAP_32BIT - MAP_32BIT | - #endif - MAP_PRIVATE | MAP_ANONYMOUS, - -1, - 0); + void *address; + + address = mmap(NULL, + size, + SUBHOOK_CODE_PROTECT_FLAGS, + #if defined MAP_32BIT && !defined __APPLE__ + MAP_32BIT | + #endif + MAP_PRIVATE | MAP_ANONYMOUS, + -1, + 0); + return address == MAP_FAILED ? NULL : address; } int subhook_free_code(void *address, size_t size) { -- cgit v1.1