about summary refs log tree commit diff stats
path: root/src/wrapped/wrappedlibc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wrapped/wrappedlibc.c')
-rw-r--r--src/wrapped/wrappedlibc.c98
1 files changed, 42 insertions, 56 deletions
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index 625ec087..06e68715 100644
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -38,6 +38,7 @@
 #include <syslog.h>
 #include <malloc.h>
 #include <getopt.h>
+#include <sys/resource.h>
 #include <sys/prctl.h>
 #include <sys/ptrace.h>
 #undef LOG_INFO
@@ -2454,28 +2455,6 @@ EXPORT void* my___deregister_frame_info(void* a)
 
 EXPORT void* my____brk_addr = NULL;
 
-// longjmp / setjmp
-typedef struct jump_buff_x64_s {
-    uint64_t save_rbx;
-    uint64_t save_rbp;
-    uint64_t save_r12;
-    uint64_t save_r13;
-    uint64_t save_r14;
-    uint64_t save_r15;
-    uint64_t save_rsp;
-    uint64_t save_rip;
-} jump_buff_x64_t;
-
-typedef struct __jmp_buf_tag_s {
-    jump_buff_x64_t __jmpbuf;
-    int              __mask_was_saved;
-    #ifdef ANDROID
-    sigset_t         __saved_mask;
-    #else
-    __sigset_t       __saved_mask;
-    #endif
-} __jmp_buf_tag_t;
-
 void EXPORT my_longjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p, int32_t __val)
 {
     jump_buff_x64_t *jpbuff = &((__jmp_buf_tag_t*)p)->__jmpbuf;
@@ -2627,46 +2606,46 @@ EXPORT void* my_mremap(x64emu_t* emu, void* old_addr, size_t old_size, size_t ne
     dynarec_log(LOG_DEBUG, "mremap(%p, %lu, %lu, %d, %p)=>", old_addr, old_size, new_size, flags, new_addr);
     void* ret = mremap(old_addr, old_size, new_size, flags, new_addr);
     dynarec_log(LOG_DEBUG, "%p\n", ret);
-    if(ret==(void*)-1)
-        return ret; // failed...
-    uint32_t prot = getProtection((uintptr_t)old_addr)&~PROT_CUSTOM;
-    if(ret==old_addr) {
-        if(old_size && old_size<new_size) {
-            setProtection_mmap((uintptr_t)ret+old_size, new_size-old_size, prot);
-            #ifdef DYNAREC
-            if(box64_dynarec)
-                addDBFromAddressRange((uintptr_t)ret+old_size, new_size-old_size);
-            #endif
-        } else if(old_size && new_size<old_size) {
-            freeProtection((uintptr_t)ret+new_size, old_size-new_size);
-            #ifdef DYNAREC
-            if(box64_dynarec)
-                cleanDBFromAddressRange((uintptr_t)ret+new_size, old_size-new_size, 1);
+    if(ret!=(void*)-1) {
+        uint32_t prot = getProtection((uintptr_t)old_addr)&~PROT_CUSTOM;
+        if(ret==old_addr) {
+            if(old_size && old_size<new_size) {
+                setProtection_mmap((uintptr_t)ret+old_size, new_size-old_size, prot);
+                #ifdef DYNAREC
+                if(box64_dynarec)
+                    addDBFromAddressRange((uintptr_t)ret+old_size, new_size-old_size);
+                #endif
+            } else if(old_size && new_size<old_size) {
+                freeProtection((uintptr_t)ret+new_size, old_size-new_size);
+                #ifdef DYNAREC
+                if(box64_dynarec)
+                    cleanDBFromAddressRange((uintptr_t)ret+new_size, old_size-new_size, 1);
+                #endif
+            } else if(!old_size) {
+                setProtection_mmap((uintptr_t)ret, new_size, prot);
+                #ifdef DYNAREC
+                if(box64_dynarec)
+                    addDBFromAddressRange((uintptr_t)ret, new_size);
+                #endif
+            }
+        } else {
+            if(old_size
+            #ifdef MREMAP_DONTUNMAP
+            && ((flags&MREMAP_DONTUNMAP)==0)
             #endif
-        } else if(!old_size) {
-            setProtection_mmap((uintptr_t)ret, new_size, prot);
+            ) {
+                freeProtection((uintptr_t)old_addr, old_size);
+                #ifdef DYNAREC
+                if(box64_dynarec)
+                    cleanDBFromAddressRange((uintptr_t)old_addr, old_size, 1);
+                #endif
+            }
+            setProtection_mmap((uintptr_t)ret, new_size, prot); // should copy the protection from old block
             #ifdef DYNAREC
             if(box64_dynarec)
                 addDBFromAddressRange((uintptr_t)ret, new_size);
             #endif
         }
-    } else {
-        if(old_size
-        #ifdef MREMAP_DONTUNMAP
-        && ((flags&MREMAP_DONTUNMAP)==0)
-        #endif
-        ) {
-            freeProtection((uintptr_t)old_addr, old_size);
-            #ifdef DYNAREC
-            if(box64_dynarec)
-                cleanDBFromAddressRange((uintptr_t)old_addr, old_size, 1);
-            #endif
-        }
-        setProtection_mmap((uintptr_t)ret, new_size, prot); // should copy the protection from old block
-        #ifdef DYNAREC
-        if(box64_dynarec)
-            addDBFromAddressRange((uintptr_t)ret, new_size);
-        #endif
     }
     return ret;
 }
@@ -2879,6 +2858,13 @@ EXPORT void* my_malloc(unsigned long size)
     return calloc(1, size);
 }
 
+EXPORT int my_setrlimit(x64emu_t* emu, int ressource, const struct rlimit *rlim)
+{
+    int ret = (ressource==RLIMIT_AS)?0:setrlimit(ressource, rlim);
+    if(ressource==RLIMIT_AS) printf_log(LOG_DEBUG, " (ignored) RLIMIT_AS, cur=0x%lx, max=0x%lx ", rlim->rlim_cur, rlim->rlim_max);
+    return ret;
+}
+
 #if 0
 #ifdef PANDORA
 #define RENAME_NOREPLACE	(1 << 0)