about summary refs log tree commit diff stats
path: root/src/os/os_linux.c
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-04-09 01:12:55 +0800
committerGitHub <noreply@github.com>2025-04-08 19:12:55 +0200
commitd592c1996d74e9e6e728026486cdab6a75f43aaa (patch)
tree935f142dff05d4640f2cd5865f8d63f8c3ca8cf9 /src/os/os_linux.c
parent8b3d4404d77bcc806631e17038f046d409cb6b69 (diff)
downloadbox64-d592c1996d74e9e6e728026486cdab6a75f43aaa.tar.gz
box64-d592c1996d74e9e6e728026486cdab6a75f43aaa.zip
[WOW64] Add wow64 PE build scaffolding (#2513)
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