about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-03-25 18:52:26 +0100
committerptitSeb <sebastien.chev@gmail.com>2021-03-25 18:52:26 +0100
commit40e6f460133f758500b070d1ba44f1b70d1e23ab (patch)
treedebf4330e8344c942fe001a61ffc17f1c0d4bd9c /src
parenta701ff87ecb8c74d0a1da2e5b3d00c3ccde91aae (diff)
downloadbox64-40e6f460133f758500b070d1ba44f1b70d1e23ab.tar.gz
box64-40e6f460133f758500b070d1ba44f1b70d1e23ab.zip
Fixed to ElfLoader and TLS, Syscall, mmap & co functions signature and a few libc wrapped functions
Diffstat (limited to 'src')
-rwxr-xr-xsrc/elfs/elfload_dump.c2
-rwxr-xr-xsrc/elfs/elfloader.c16
-rwxr-xr-xsrc/emu/x64syscall.c38
-rwxr-xr-xsrc/include/regs.h3
-rw-r--r--src/wrapped/generated/functions_list.txt5
-rw-r--r--src/wrapped/generated/wrapper.c8
-rw-r--r--src/wrapped/generated/wrapper.h5
-rwxr-xr-xsrc/wrapped/wrappedlibc.c2
-rwxr-xr-xsrc/wrapped/wrappedlibc_private.h16
-rwxr-xr-xsrc/wrapped/wrappedlibpthread_private.h8
10 files changed, 65 insertions, 38 deletions
diff --git a/src/elfs/elfload_dump.c b/src/elfs/elfload_dump.c
index 459ac0b9..85d01dcb 100755
--- a/src/elfs/elfload_dump.c
+++ b/src/elfs/elfload_dump.c
@@ -351,7 +351,7 @@ void DumpRelATable(elfheader_t *h, int cnt, Elf64_Rela *rela, const char* name)
         const char* elfname = ElfName(h);
         printf_log(LOG_DUMP, "ELF Dump %s Table(%d) @%p\n", name, cnt, rela);
         for (int i = 0; i<cnt; ++i)
-            printf_log(LOG_DUMP, "  %s:RelA[%d] = %p (0x%lX: %s, sym=0x%lX/%s) Addend=%ld\n", elfname,
+            printf_log(LOG_DUMP, "  %s:RelA[%d] = %p (0x%lX: %s, sym=0x%lX/%s) Addend=0x%lx\n", elfname,
                 i, (void*)rela[i].r_offset, rela[i].r_info, DumpRelType(ELF64_R_TYPE(rela[i].r_info)), 
                 ELF64_R_SYM(rela[i].r_info), IdxSymName(h, ELF64_R_SYM(rela[i].r_info)), 
                 rela[i].r_addend);
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c
index e1dc2ca1..abe2b8d3 100755
--- a/src/elfs/elfloader.c
+++ b/src/elfs/elfloader.c
@@ -555,12 +555,14 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c
         intptr_t delta;
         switch(ELF64_R_TYPE(rela[i].r_info)) {
             case R_X86_64_NONE:
+                break;
             case R_X86_64_PC32:
+                // should be "S + A - P" with S=symbol offset, A=addend and P=place of the storage unit, write a word32
                 // can be ignored
                 break;
             case R_X86_64_RELATIVE:
-                printf_log(LOG_DUMP, "Apply %s R_X86_64_RELATIVE @%p (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, *(void**)p, (void*)((*p)+head->delta));
-                *p += head->delta;
+                printf_log(LOG_DUMP, "Apply %s R_X86_64_RELATIVE @%p (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, *(void**)p, (void*)(head->delta+ rela[i].r_addend));
+                *p = head->delta+ rela[i].r_addend;
                 break;
             case R_X86_64_COPY:
                 if(!strcmp(symname, "stdin") || !strcmp(symname, "stdout") || !strcmp(symname, "stderr")) {
@@ -589,7 +591,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c
                     offs = sym->st_value + head->delta;
                     end = offs + sym->st_size;
                     printf_log(LOG_DUMP, "Apply %s R_X86_64_GLOB_DAT with R_X86_64_COPY @%p/%p (%p/%p -> %p/%p) size=%ld on sym=%s \n", (bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0), (void*)(globp?(*globp):0), (void*)offs, (void*)globoffs, sym->st_size, symname);
-                    *p = globoffs + rela[i].r_addend;
+                    *p = globoffs/* + rela[i].r_addend*/;   //no addend?
                     AddWeakSymbol(GetGlobalData(maplib), symname, offs, end-offs+1);
                 } else {
                     // Look for same symbol already loaded but not in self (so no need for local_maplib here)
@@ -602,7 +604,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c
                             printf_log(LOG_NONE, "Error: Global Symbol %s not found, cannot apply R_X86_64_GLOB_DAT @%p (%p) in %s\n", symname, p, *(void**)p, head->name);
                     } else {
                         printf_log(LOG_DUMP, "Apply %s R_X86_64_GLOB_DAT @%p (%p -> %p) on sym=%s\n", (bind==STB_LOCAL)?"Local":"Global", p, (void*)(p?(*p):0), (void*)offs, symname);
-                        *p = offs + rela[i].r_addend;
+                        *p = offs/* + rela[i].r_addend*/;   // not addend it seems
                     }
                 }
                 break;
@@ -659,9 +661,9 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c
                             h_tls = GetGlobalSymbolElf(maplib, symname);
                     }
                     if(h_tls) {
-                        delta = *(int*)p;
-                        printf_log(LOG_DUMP, "Applying %s %s on %s @%p (%ld -> %ld)\n", (bind==STB_LOCAL)?"Local":"Global", DumpRelType(t), symname, p, delta, (int64_t)offs + h_tls->tlsbase);
-                        *p = (uintptr_t)((int64_t)offs + h_tls->tlsbase);
+                        delta = *(int64_t*)p;
+                        printf_log(LOG_DUMP, "Applying %s %s on %s @%p (%ld -> %ld)\n", (bind==STB_LOCAL)?"Local":"Global", DumpRelType(t), symname, p, delta, (int64_t)offs + rela[i].r_addend + h_tls->tlsbase);
+                        *p = (uintptr_t)((int64_t)offs + rela[i].r_addend + h_tls->tlsbase);
                     } else {
                         printf_log(LOG_INFO, "Warning, cannot apply %s %s on %s @%p (%ld), no elf_header found\n", (bind==STB_LOCAL)?"Local":"Global", DumpRelType(t), symname, p, (int64_t)offs);
                     }
diff --git a/src/emu/x64syscall.c b/src/emu/x64syscall.c
index bec0562b..a1c23c5b 100755
--- a/src/emu/x64syscall.c
+++ b/src/emu/x64syscall.c
@@ -42,10 +42,9 @@ int32_t my_open(x64emu_t* emu, void* pathname, int32_t flags, uint32_t mode);
 
 //int my_sigaction(x64emu_t* emu, int signum, const x86_sigaction_t *act, x86_sigaction_t *oldact);
 //int32_t my_execve(x64emu_t* emu, const char* path, char* const argv[], char* const envp[]);
-//void* my_mmap(x64emu_t* emu, void *addr, unsigned long length, int prot, int flags, int fd, int offset);
-//void* my_mmap64(x64emu_t* emu, void *addr, unsigned long length, int prot, int flags, int fd, int64_t offset);
-//int my_munmap(x64emu_t* emu, void* addr, unsigned long length);
-//int my_mprotect(x64emu_t* emu, void *addr, unsigned long len, int prot);
+void* my_mmap64(x64emu_t* emu, void *addr, unsigned long length, int prot, int flags, int fd, int64_t offset);
+int my_munmap(x64emu_t* emu, void* addr, unsigned long length);
+int my_mprotect(x64emu_t* emu, void *addr, unsigned long len, int prot);
 
 // cannot include <fcntl.h>, it conflict with some asm includes...
 #ifndef O_NONBLOCK
@@ -62,13 +61,16 @@ typedef struct scwrap_s {
 } scwrap_t;
 
 scwrap_t syscallwrap[] = {
-    //{ 0, __NR_read, 3 },  // wrapped so SA_RESTART can be handled by libc
-    //{ 1, __NR_write, 3 }, // same
-    //{ 2, __NR_open, 3 },  // flags need transformation
-    //{ 3, __NR_close, 1 },   // wrapped so SA_RESTART can be handled by libc
-
+    //{ 0, __NR_read, 3 },      // wrapped so SA_RESTART can be handled by libc
+    //{ 1, __NR_write, 3 },     // same
+    //{ 2, __NR_open, 3 },      // flags need transformation
+    //{ 3, __NR_close, 1 },     // wrapped so SA_RESTART can be handled by libc
+    //{ 9, __NR_mmap, 6},       // wrapped to track mmap
+    //{ 10, __NR_mprotect, 3},  // same
+    //{ 11, __NR_munmap, 2},    // same
     { 5, __NR_fstat, 2},
     { 186, __NR_gettid, 0 },
+    { 202, __NR_futex, 6},
 };
 
 struct mmap_arg_struct {
@@ -152,6 +154,15 @@ void EXPORT x64Syscall(x64emu_t *emu)
         case 3:  // sys_close
             R_EAX = (uint32_t)close((int)R_EDI);
             break;
+        case 9: // sys_mmap
+            R_RAX = (uintptr_t)my_mmap64(emu, (void*)R_RDI, R_RSI, (int)R_EDX, (int)R_R10d, (int)R_R8d, R_R9);
+            break;
+        case 10: // sys_mprotect
+            R_EAX = (uint32_t)my_mprotect(emu, (void*)R_RDI, R_RSI, (int)R_EDX);
+            break;
+        case 11: // sys_munmap
+            R_EAX = (uint32_t)my_munmap(emu, (void*)R_RDI, R_RSI);
+            break;
         default:
             printf_log(LOG_INFO, "Error: Unsupported Syscall 0x%02Xh (%d)\n", s, s);
             emu->quit = 1;
@@ -164,10 +175,11 @@ void EXPORT x64Syscall(x64emu_t *emu)
 #define stack(n) (R_RSP+8+n)
 #define i32(n)  *(int32_t*)stack(n)
 #define u32(n)  *(uint32_t*)stack(n)
+#define i64(n)  *(int64_t*)stack(n)
 #define u64(n)  *(uint64_t*)stack(n)
 #define p(n)    *(void**)stack(n)
 
-uint32_t EXPORT my_syscall(x64emu_t *emu)
+uintptr_t EXPORT my_syscall(x64emu_t *emu)
 {
     uint32_t s = R_EDI;;
     printf_log(LOG_DUMP, "%p: Calling libc syscall 0x%02X (%d) %p %p %p %p %p\n", (void*)R_RIP, s, s, (void*)R_RSI, (void*)R_RDX, (void*)R_RCX, (void*)R_R8, (void*)R_R9); 
@@ -200,6 +212,12 @@ uint32_t EXPORT my_syscall(x64emu_t *emu)
             return my_open(emu, (char*)R_RSI, of_convert(R_EDX), R_ECX);
         case 3:  // sys_close
             return (uint32_t)close(R_ESI);
+        case 9: // sys_mmap
+            return (uintptr_t)my_mmap64(emu, (void*)R_RSI, R_RDX, (int)R_RCX, (int)R_R8d, (int)R_R9, i64(0));
+        case 10: // sys_mprotect
+            return (uint32_t)my_mprotect(emu, (void*)R_RSI, R_RDX, (int)R_ECX);
+        case 11: // sys_munmap
+            return (uint32_t)my_munmap(emu, (void*)R_RSI, R_RDX);
         default:
             printf_log(LOG_INFO, "Error: Unsupported libc Syscall 0x%02X (%d)\n", s, s);
             emu->quit = 1;
diff --git a/src/include/regs.h b/src/include/regs.h
index 91deee65..4eacf160 100755
--- a/src/include/regs.h
+++ b/src/include/regs.h
@@ -285,6 +285,9 @@ typedef union {
 #define R_ESI emu->regs[_SI].dword[0]
 #define R_ESP emu->regs[_SP].dword[0]
 #define R_EBP emu->regs[_BP].dword[0]
+#define R_R8d emu->regs[_R8].dword[0]
+#define R_R9d emu->regs[_R9].dword[0]
+#define R_R10d emu->regs[_R10].dword[0]
 #define R_AX emu->regs[_AX].word[0]
 #define R_BX emu->regs[_BX].word[0]
 #define R_CX emu->regs[_CX].word[0]
diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt
index 7dcdcc32..7db4e8cd 100644
--- a/src/wrapped/generated/functions_list.txt
+++ b/src/wrapped/generated/functions_list.txt
@@ -12,7 +12,6 @@
 #() cFf
 #() cFp
 #() wFp
-#() iFE
 #() iFv
 #() iFi
 #() iFu
@@ -45,6 +44,7 @@
 #() lFE
 #() lFi
 #() lFp
+#() LFE
 #() LFv
 #() LFL
 #() LFp
@@ -249,6 +249,7 @@
 #() iFpli
 #() iFplp
 #() iFpLi
+#() iFpLL
 #() iFpLp
 #() iFppi
 #() iFppI
@@ -1021,8 +1022,8 @@
 #!defined(HAVE_LD80BITS) KFK
 #!defined(HAVE_LD80BITS) KFKK
 #!defined(HAVE_LD80BITS) KFKp
-#() iFEv -> iFE
 #() lFEv -> lFE
+#() LFEv -> LFE
 #() pFEv -> pFE
 #() pFppv -> pFpp
 #() iFEvpp -> iFEpp
diff --git a/src/wrapped/generated/wrapper.c b/src/wrapped/generated/wrapper.c
index 6924df29..aea3f778 100644
--- a/src/wrapped/generated/wrapper.c
+++ b/src/wrapped/generated/wrapper.c
@@ -45,7 +45,6 @@ typedef int8_t (*cFu_t)(uint32_t);
 typedef int8_t (*cFf_t)(float);
 typedef int8_t (*cFp_t)(void*);
 typedef int16_t (*wFp_t)(void*);
-typedef int32_t (*iFE_t)(x64emu_t*);
 typedef int32_t (*iFv_t)(void);
 typedef int32_t (*iFi_t)(int32_t);
 typedef int32_t (*iFu_t)(uint32_t);
@@ -78,6 +77,7 @@ typedef double (*dFp_t)(void*);
 typedef intptr_t (*lFE_t)(x64emu_t*);
 typedef intptr_t (*lFi_t)(int32_t);
 typedef intptr_t (*lFp_t)(void*);
+typedef uintptr_t (*LFE_t)(x64emu_t*);
 typedef uintptr_t (*LFv_t)(void);
 typedef uintptr_t (*LFL_t)(uintptr_t);
 typedef uintptr_t (*LFp_t)(void*);
@@ -282,6 +282,7 @@ typedef int32_t (*iFpff_t)(void*, float, float);
 typedef int32_t (*iFpli_t)(void*, intptr_t, int32_t);
 typedef int32_t (*iFplp_t)(void*, intptr_t, void*);
 typedef int32_t (*iFpLi_t)(void*, uintptr_t, int32_t);
+typedef int32_t (*iFpLL_t)(void*, uintptr_t, uintptr_t);
 typedef int32_t (*iFpLp_t)(void*, uintptr_t, void*);
 typedef int32_t (*iFppi_t)(void*, void*, int32_t);
 typedef int32_t (*iFppI_t)(void*, void*, int64_t);
@@ -1075,7 +1076,6 @@ void cFu(x64emu_t *emu, uintptr_t fcn) { cFu_t fn = (cFu_t)fcn; R_RAX=fn((uint32
 void cFf(x64emu_t *emu, uintptr_t fcn) { cFf_t fn = (cFf_t)fcn; R_RAX=fn(emu->xmm[0].f[0]); }
 void cFp(x64emu_t *emu, uintptr_t fcn) { cFp_t fn = (cFp_t)fcn; R_RAX=fn((void*)R_RDI); }
 void wFp(x64emu_t *emu, uintptr_t fcn) { wFp_t fn = (wFp_t)fcn; R_RAX=fn((void*)R_RDI); }
-void iFE(x64emu_t *emu, uintptr_t fcn) { iFE_t fn = (iFE_t)fcn; R_RAX=fn(emu); }
 void iFv(x64emu_t *emu, uintptr_t fcn) { iFv_t fn = (iFv_t)fcn; R_RAX=fn(); }
 void iFi(x64emu_t *emu, uintptr_t fcn) { iFi_t fn = (iFi_t)fcn; R_RAX=fn((int32_t)R_RDI); }
 void iFu(x64emu_t *emu, uintptr_t fcn) { iFu_t fn = (iFu_t)fcn; R_RAX=fn((uint32_t)R_RDI); }
@@ -1108,6 +1108,7 @@ void dFp(x64emu_t *emu, uintptr_t fcn) { dFp_t fn = (dFp_t)fcn; emu->xmm[0].d[0]
 void lFE(x64emu_t *emu, uintptr_t fcn) { lFE_t fn = (lFE_t)fcn; R_RAX=(intptr_t)fn(emu); }
 void lFi(x64emu_t *emu, uintptr_t fcn) { lFi_t fn = (lFi_t)fcn; R_RAX=(intptr_t)fn((int32_t)R_RDI); }
 void lFp(x64emu_t *emu, uintptr_t fcn) { lFp_t fn = (lFp_t)fcn; R_RAX=(intptr_t)fn((void*)R_RDI); }
+void LFE(x64emu_t *emu, uintptr_t fcn) { LFE_t fn = (LFE_t)fcn; R_RAX=(uintptr_t)fn(emu); }
 void LFv(x64emu_t *emu, uintptr_t fcn) { LFv_t fn = (LFv_t)fcn; R_RAX=(uintptr_t)fn(); }
 void LFL(x64emu_t *emu, uintptr_t fcn) { LFL_t fn = (LFL_t)fcn; R_RAX=(uintptr_t)fn((uintptr_t)R_RDI); }
 void LFp(x64emu_t *emu, uintptr_t fcn) { LFp_t fn = (LFp_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI); }
@@ -1312,6 +1313,7 @@ void iFpff(x64emu_t *emu, uintptr_t fcn) { iFpff_t fn = (iFpff_t)fcn; R_RAX=fn((
 void iFpli(x64emu_t *emu, uintptr_t fcn) { iFpli_t fn = (iFpli_t)fcn; R_RAX=fn((void*)R_RDI, (intptr_t)R_RSI, (int32_t)R_RDX); }
 void iFplp(x64emu_t *emu, uintptr_t fcn) { iFplp_t fn = (iFplp_t)fcn; R_RAX=fn((void*)R_RDI, (intptr_t)R_RSI, (void*)R_RDX); }
 void iFpLi(x64emu_t *emu, uintptr_t fcn) { iFpLi_t fn = (iFpLi_t)fcn; R_RAX=fn((void*)R_RDI, (uintptr_t)R_RSI, (int32_t)R_RDX); }
+void iFpLL(x64emu_t *emu, uintptr_t fcn) { iFpLL_t fn = (iFpLL_t)fcn; R_RAX=fn((void*)R_RDI, (uintptr_t)R_RSI, (uintptr_t)R_RDX); }
 void iFpLp(x64emu_t *emu, uintptr_t fcn) { iFpLp_t fn = (iFpLp_t)fcn; R_RAX=fn((void*)R_RDI, (uintptr_t)R_RSI, (void*)R_RDX); }
 void iFppi(x64emu_t *emu, uintptr_t fcn) { iFppi_t fn = (iFppi_t)fcn; R_RAX=fn((void*)R_RDI, (void*)R_RSI, (int32_t)R_RDX); }
 void iFppI(x64emu_t *emu, uintptr_t fcn) { iFppI_t fn = (iFppI_t)fcn; R_RAX=fn((void*)R_RDI, (void*)R_RSI, (int64_t)R_RDX); }
@@ -2091,8 +2093,8 @@ void KFKK(x64emu_t *emu, uintptr_t fcn) { KFKK_t fn = (KFKK_t)fcn; double db=fn(
 void KFKp(x64emu_t *emu, uintptr_t fcn) { KFKp_t fn = (KFKp_t)fcn; double db=fn(FromLD((void*)(R_RSP + 8)), (void*)R_RDI); fpu_do_push(emu); ST0val = db; }
 #endif
 
-void iFEv(x64emu_t *emu, uintptr_t fcn) { iFE_t fn = (iFE_t)fcn; R_RAX=fn(emu); }
 void lFEv(x64emu_t *emu, uintptr_t fcn) { lFE_t fn = (lFE_t)fcn; R_RAX=(intptr_t)fn(emu); }
+void LFEv(x64emu_t *emu, uintptr_t fcn) { LFE_t fn = (LFE_t)fcn; R_RAX=(uintptr_t)fn(emu); }
 void pFEv(x64emu_t *emu, uintptr_t fcn) { pFE_t fn = (pFE_t)fcn; R_RAX=(uintptr_t)fn(emu); }
 void pFppv(x64emu_t *emu, uintptr_t fcn) { pFpp_t fn = (pFpp_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI, (void*)R_RSI); }
 void iFEvpp(x64emu_t *emu, uintptr_t fcn) { iFEpp_t fn = (iFEpp_t)fcn; R_RAX=fn(emu, (void*)R_RSI, (void*)R_RDX); }
diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h
index bd960aff..6b9d4035 100644
--- a/src/wrapped/generated/wrapper.h
+++ b/src/wrapped/generated/wrapper.h
@@ -42,7 +42,6 @@ void cFu(x64emu_t *emu, uintptr_t fnc);
 void cFf(x64emu_t *emu, uintptr_t fnc);
 void cFp(x64emu_t *emu, uintptr_t fnc);
 void wFp(x64emu_t *emu, uintptr_t fnc);
-void iFE(x64emu_t *emu, uintptr_t fnc);
 void iFv(x64emu_t *emu, uintptr_t fnc);
 void iFi(x64emu_t *emu, uintptr_t fnc);
 void iFu(x64emu_t *emu, uintptr_t fnc);
@@ -75,6 +74,7 @@ void dFp(x64emu_t *emu, uintptr_t fnc);
 void lFE(x64emu_t *emu, uintptr_t fnc);
 void lFi(x64emu_t *emu, uintptr_t fnc);
 void lFp(x64emu_t *emu, uintptr_t fnc);
+void LFE(x64emu_t *emu, uintptr_t fnc);
 void LFv(x64emu_t *emu, uintptr_t fnc);
 void LFL(x64emu_t *emu, uintptr_t fnc);
 void LFp(x64emu_t *emu, uintptr_t fnc);
@@ -279,6 +279,7 @@ void iFpff(x64emu_t *emu, uintptr_t fnc);
 void iFpli(x64emu_t *emu, uintptr_t fnc);
 void iFplp(x64emu_t *emu, uintptr_t fnc);
 void iFpLi(x64emu_t *emu, uintptr_t fnc);
+void iFpLL(x64emu_t *emu, uintptr_t fnc);
 void iFpLp(x64emu_t *emu, uintptr_t fnc);
 void iFppi(x64emu_t *emu, uintptr_t fnc);
 void iFppI(x64emu_t *emu, uintptr_t fnc);
@@ -1058,8 +1059,8 @@ void KFKK(x64emu_t *emu, uintptr_t fnc);
 void KFKp(x64emu_t *emu, uintptr_t fnc);
 #endif
 
-void iFEv(x64emu_t *emu, uintptr_t fnc);
 void lFEv(x64emu_t *emu, uintptr_t fnc);
+void LFEv(x64emu_t *emu, uintptr_t fnc);
 void pFEv(x64emu_t *emu, uintptr_t fnc);
 void pFppv(x64emu_t *emu, uintptr_t fnc);
 void iFEvpp(x64emu_t *emu, uintptr_t fnc);
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index 1662f1bf..3806a369 100755
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -387,7 +387,7 @@ EXPORT void my___libc_init_first(x64emu_t* emu, int argc, char* arg0, char** b)
     // do nothing specific for now
     return;
 }
-uint64_t my_syscall(x64emu_t *emu); // implemented in x64syscall.c
+uintptr_t my_syscall(x64emu_t *emu); // implemented in x64syscall.c
 void EXPORT my___stack_chk_fail(x64emu_t* emu)
 {
     char buff[200];
diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h
index 4e2666d7..5733c7c8 100755
--- a/src/wrapped/wrappedlibc_private.h
+++ b/src/wrapped/wrappedlibc_private.h
@@ -1091,8 +1091,8 @@ GOW(lseek64, IFiIi)
 //GO(lutimes, 
 GOM(__lxstat, iFEipp)
 GOM(__lxstat64, iFEipp)
-//GO(__madvise, 
-//GOW(madvise, 
+GO(__madvise, iFpLi)
+GOW(madvise, iFpLi)
 GOM(makecontext, iFEppiV)   //weak
 //GOW(mallinfo, 
 GO(malloc, pFL) // need to wrap to clear allocated memory?
@@ -1165,8 +1165,8 @@ GO(mlock, iFpL)
 //GO(mlock2, 
 GO(mlockall, iFi)
 //GO(__mmap, 
-GOW(mmap, pFEpLiiiI)
-GOW(mmap64, pFEpLiiiI)
+GOM(mmap, pFEpLiiiI)    //weak
+GOM(mmap64, pFEpLiiiI)  //weak
 //GOW(modf, 
 //GOW(modff, 
 //GOW(modfl, 
@@ -1178,10 +1178,10 @@ GOW(mmap64, pFEpLiiiI)
 //GOW(mount, 
 //GO(mprobe, 
 //GO(__mprotect, 
-GOW(mprotect, iFEpLi)
+GOM(mprotect, iFEpLi) //weak
 //GO(mrand48, 
 //GO(mrand48_r, 
-GOW(mremap, pFEpLLiN)
+GOM(mremap, pFEpLLiN) //weal
 //GO(msgctl, 
 //GO(msgget, 
 //GOW(msgrcv, 
@@ -1312,7 +1312,7 @@ GOW(poll, iFpLi)
 //GO(posix_fallocate64, 
 //GO(__posix_getopt, 
 //GO(posix_madvise, 
-//GOW(posix_memalign, 
+GOW(posix_memalign, iFpLL)
 //GOW(posix_openpt, 
 //GO(posix_spawn, 
 //GO(posix_spawn, 
@@ -1914,7 +1914,7 @@ GOM(swapcontext, iFEpp) //Weak
 //GO(sync, 
 //GO(sync_file_range, 
 //GO(syncfs, 
-GOM(syscall, iFEv)
+GOM(syscall, LFEv)
 GO(__sysconf, lFi)
 GOW(sysconf, lFi)
 //GO(__sysctl, 
diff --git a/src/wrapped/wrappedlibpthread_private.h b/src/wrapped/wrappedlibpthread_private.h
index 1b25b659..3c3f9ed2 100755
--- a/src/wrapped/wrappedlibpthread_private.h
+++ b/src/wrapped/wrappedlibpthread_private.h
@@ -148,11 +148,11 @@ GO(pthread_rwlock_rdlock, iFp)
 // pthread_rwlock_timedrdlock
 // pthread_rwlock_timedwrlock
 // __pthread_rwlock_tryrdlock
-//GO(pthread_rwlock_tryrdlock, iFp)
+GO(pthread_rwlock_tryrdlock, iFp)
 // __pthread_rwlock_trywrlock
-//GO(pthread_rwlock_trywrlock, iFp)
-//GO(__pthread_rwlock_unlock, iFp)
-//GO2(pthread_rwlock_unlock, iFp, __pthread_rwlock_unlock)   // not always defined
+GO(pthread_rwlock_trywrlock, iFp)
+GO(__pthread_rwlock_unlock, iFp)
+GO(pthread_rwlock_unlock, iFp)
 GO(__pthread_rwlock_wrlock, iFp)
 GO(pthread_rwlock_wrlock, iFp)
 GO(pthread_self, LFv)