aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subhook_unix.c21
1 files changed, 12 insertions, 9 deletions
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) {