Skip to content

Commit

Permalink
Preserve errno on mmap / munmap speicifc memory traqking operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Nov 10, 2024
1 parent b46925e commit 5d941f7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/wrapped/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,7 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, size_t length, int prot, int f
errno = EEXIST;
return MAP_FAILED;
}
int e = errno;
if((ret==MAP_FAILED && (emu || box64_is32bits)) && (box64_log>=LOG_DEBUG || box64_dynarec_log>=LOG_DEBUG)) {printf_log(LOG_NONE, "%s (%d)\n", strerror(errno), errno);}
if(((ret!=MAP_FAILED) && (emu || box64_is32bits)) && (box64_log>=LOG_DEBUG || box64_dynarec_log>=LOG_DEBUG)) {printf_log(LOG_NONE, "%p\n", ret);}
#ifdef DYNAREC
Expand Down Expand Up @@ -3084,8 +3085,9 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, size_t length, int prot, int f
else
setProtection((uintptr_t)ret, length, prot);
if(old_addr && ret!=old_addr)
errno = EEXIST;
e = EEXIST;
}
errno = e; // preserve errno
return ret;
}
EXPORT void* my_mmap(x64emu_t* emu, void *addr, size_t length, int prot, int flags, int fd, ssize_t offset) __attribute__((alias("my_mmap64")));
Expand Down Expand Up @@ -3145,6 +3147,7 @@ EXPORT int my_munmap(x64emu_t* emu, void* addr, size_t length)
(void)emu;
if((emu || box64_is32bits) && (box64_log>=LOG_DEBUG || box64_dynarec_log>=LOG_DEBUG)) {printf_log(LOG_NONE, "munmap(%p, 0x%lx)\n", addr, length);}
int ret = internal_munmap(addr, length);
int e = errno;
#ifdef DYNAREC
if(!ret && box64_dynarec && length) {
cleanDBFromAddressRange((uintptr_t)addr, length, 1);
Expand All @@ -3153,6 +3156,7 @@ EXPORT int my_munmap(x64emu_t* emu, void* addr, size_t length)
if(!ret) {
freeProtection((uintptr_t)addr, length);
}
errno = e; // preseve errno
return ret;
}

Expand Down

0 comments on commit 5d941f7

Please sign in to comment.