about summary refs log tree commit diff stats
path: root/src/os/os_linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/os_linux.c')
-rw-r--r--src/os/os_linux.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/os/os_linux.c b/src/os/os_linux.c
index 46a0434b..e11a41a2 100644
--- a/src/os/os_linux.c
+++ b/src/os/os_linux.c
@@ -2,6 +2,7 @@
 #include <sched.h>
 #include <unistd.h>
 #include <stdint.h>
+#include <sys/personality.h>
 
 #include "os.h"
 #include "signals.h"
@@ -62,3 +63,40 @@ void EmuX86Syscall(void* emu)
 {
     x86Syscall((x64emu_t*)emu);
 }
+
+void PersonalityAddrLimit32Bit(void)
+{
+    personality(ADDR_LIMIT_32BIT);
+}
+
+void* InternalMmap(void* addr, unsigned long length, int prot, int flags, int fd, ssize_t offset)
+{
+#if 1 // def STATICBUILD
+    void* ret = (void*)syscall(__NR_mmap, addr, length, prot, flags, fd, offset);
+#else
+    static int grab = 1;
+    typedef void* (*pFpLiiiL_t)(void*, unsigned long, int, int, int, size_t);
+    static pFpLiiiL_t libc_mmap64 = NULL;
+    if (grab) {
+        libc_mmap64 = dlsym(RTLD_NEXT, "mmap64");
+    }
+    void* ret = libc_mmap64(addr, length, prot, flags, fd, offset);
+#endif
+    return ret;
+}
+
+int InternalMunmap(void* addr, unsigned long length)
+{
+#if 1 // def STATICBUILD
+    int ret = syscall(__NR_munmap, addr, length);
+#else
+    static int grab = 1;
+    typedef int (*iFpL_t)(void*, unsigned long);
+    static iFpL_t libc_munmap = NULL;
+    if (grab) {
+        libc_munmap = dlsym(RTLD_NEXT, "munmap");
+    }
+    int ret = libc_munmap(addr, length);
+#endif
+    return ret;
+}
\ No newline at end of file