about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-09-01 17:09:54 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-09-01 17:09:54 +0200
commit759cef6e015a7fe99bc94cd70da92e8f00584db9 (patch)
tree9461b79c03e5cbe0c7454109a53aebd952b2ec44 /src
parent02364151bcba524825838140f3d1a61db59dab88 (diff)
downloadbox64-759cef6e015a7fe99bc94cd70da92e8f00584db9.tar.gz
box64-759cef6e015a7fe99bc94cd70da92e8f00584db9.zip
[BOX32] Fixes and hacks to get steamcmd shows the prompt
Diffstat (limited to 'src')
-rwxr-xr-xsrc/emu/x86int3.c2
-rw-r--r--src/emu/x86syscall_32.c73
-rw-r--r--src/libtools/threads.c8
-rw-r--r--src/wrapped32/generated/functions_list.txt6
-rw-r--r--src/wrapped32/generated/wrappedlibctypes32.h3
-rw-r--r--src/wrapped32/generated/wrapper32.c4
-rw-r--r--src/wrapped32/generated/wrapper32.h3
-rwxr-xr-xsrc/wrapped32/wrappedlibc_private.h4
8 files changed, 89 insertions, 14 deletions
diff --git a/src/emu/x86int3.c b/src/emu/x86int3.c
index b2d800c9..3dbc5461 100755
--- a/src/emu/x86int3.c
+++ b/src/emu/x86int3.c
@@ -289,7 +289,7 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr)
                     post = 5;
                     snprintf(buff, 255, "%04d|%p: Calling %s(%p, \"%s\")", tid, from_ptrv(*(ptr_t*)from_ptr(R_ESP)), s, from_ptrv(*(ptr_t*)from_ptr(R_ESP+4)), from_ptrv(*(ptr_t*)from_ptr(R_ESP+8)));
                 } else  if(!strcmp(s, "syscall")) {
-                    snprintf(buff, 255, "%04d|%p: Calling %s(%d, %p, %p, %p...)", tid, from_ptrv(*(ptr_t*)from_ptr(R_ESP)), s, *(int32_t*)from_ptr(R_ESP+4), from_ptrv(*(ptr_t*)from_ptr(R_ESP+8)), *(void**)from_ptr(R_ESP+12), *(void**)from_ptr(R_ESP+16));
+                    snprintf(buff, 255, "%04d|%p: Calling %s(%d, %p, %p, %p...)", tid, from_ptrv(*(ptr_t*)from_ptr(R_ESP)), s, *(int32_t*)from_ptr(R_ESP+4), from_ptrv(*(ptr_t*)from_ptr(R_ESP+8)), from_ptrv(*(ptr_t*)from_ptr(R_ESP+12)), from_ptrv(*(ptr_t*)from_ptr(R_ESP+16)));
                     perr = 1;
                 } else {
                     snprintf(buff, 255, "%04d|%p: Calling %s (%08X, %08X, %08X...)", tid, from_ptrv(*(ptr_t*)from_ptr(R_ESP)), s, *(uint32_t*)from_ptr(R_ESP+4), *(uint32_t*)from_ptr(R_ESP+8), *(uint32_t*)from_ptr(R_ESP+12));
diff --git a/src/emu/x86syscall_32.c b/src/emu/x86syscall_32.c
index 2bc41ff9..7c723ca5 100644
--- a/src/emu/x86syscall_32.c
+++ b/src/emu/x86syscall_32.c
@@ -158,7 +158,7 @@ static const scwrap_t syscallwrap[] = {
     //{ 292, __NR_inotify_add_watch, 3},
     //{ 293, __NR_inotify_rm_watch, 2},
     //{ 311, __NR_set_robust_list, 2 },
-    //{ 312, __NR_get_robust_list, 4 },
+    //{ 312, __NR_get_robust_list, 4 }, // need wrapping of 3rd arg
     //{ 318, __NR_getcpu, 3},
     //{ 328, __NR_eventfd2, 2},
     //{ 329, __NR_epoll_create1, 1 },
@@ -231,6 +231,17 @@ struct i386_user_desc {
     unsigned int  useable:1;
 };
 
+struct i386_robust_list {
+        ptr_t next; // struct i386_robust_list *
+};
+struct i386_robust_list_head {
+        struct i386_robust_list list;
+        long_t futex_offset;
+        ptr_t  list_op_pending; // struct robust_list *
+};
+
+
+
 int32_t my32_open(x64emu_t* emu, void* pathname, int32_t flags, uint32_t mode);
 int32_t my32_execve(x64emu_t* emu, const char* path, char* const argv[], char* const envp[]);
 ssize_t my32_read(int fd, void* buf, size_t count);
@@ -242,6 +253,8 @@ void EXPORT x86Syscall(x64emu_t *emu)
     printf_log(LOG_DEBUG, "%p: Calling 32bits syscall 0x%02X (%d) %p %p %p %p %p", (void*)R_RIP, s, s, (void*)(uintptr_t)R_EBX, (void*)(uintptr_t)R_ECX, (void*)(uintptr_t)R_EDX, (void*)(uintptr_t)R_ESI, (void*)(uintptr_t)R_EDI); 
     // check wrapper first
     int cnt = sizeof(syscallwrap) / sizeof(scwrap_t);
+    void* tmp;
+    size_t tmps;
     for (int i=0; i<cnt; i++) {
         if(syscallwrap[i].x86s == s) {
             int sc = syscallwrap[i].nats;
@@ -295,6 +308,28 @@ void EXPORT x86Syscall(x64emu_t *emu)
             if(R_EAX==0xffffffff && errno>0)
                 R_EAX = (uint32_t)-errno;
             break;
+        case 312: // get_robust_list
+            {
+                static struct i386_robust_list_head h;
+                ulong_t *arg2 = from_ptrv(R_EDX);
+                ptr_t* arg1 = from_ptrv(R_ECX);
+                tmp = arg1?(from_ptrv(*arg1)):NULL;
+                tmps = arg2?(from_ulong(*arg2)):0;
+                tmp = R_ECX?from_ptrv(*(ptr_t*)from_ptrv(R_ECX)):NULL;
+                tmps = R_EDX?from_ulong(*(ulong_t*)from_ptrv(R_EDX)):0;
+                R_EAX = syscall(__NR_get_robust_list, S_EBX, arg1?(&tmp):NULL, arg2?(&tmps):NULL);
+                if(!R_EAX) {
+                    if(arg1) {
+                        h.list.next = (*(void**)tmp==tmp)?to_ptrv(&h):to_ptrv(*(void**)tmp); // set head
+                        h.futex_offset = to_long(((long*)tmp)[1]);
+                        h.list_op_pending = to_ptrv(((void**)tmp)[2]);
+                        *arg1 = to_ptrv(&h);   // should wrap all the structures, and keep it alive...
+                    }
+                    if(arg2) *arg2 = to_ulong(tmps/2);    // it's 2 times smaller in x86
+                } else if(R_EAX==0xffffffff && errno>0)
+                    R_EAX = (uint32_t)-errno;
+            }
+            break;
         default:
             printf_log(LOG_INFO, "Warning: Unsupported Syscall 0x%02Xh (%d)\n", s, s);
             R_EAX = (uint32_t)-ENOSYS;
@@ -316,6 +351,9 @@ uint32_t EXPORT my32_syscall(x64emu_t *emu, ptr_t* b)
     printf_log(LOG_DEBUG, "%p: Calling libc syscall 0x%02X (%d) %p %p %p %p %p\n", from_ptrv(R_EIP), s, s, from_ptrv(u32(4)), from_ptrv(u32(8)), from_ptrv(u32(12)), from_ptrv(u32(16)), from_ptrv(u32(20))); 
     // check wrapper first
     int cnt = sizeof(syscallwrap) / sizeof(scwrap_t);
+    size_t tmps;
+    void* tmp;
+    int ret;
     for (int i=0; i<cnt; i++) {
         if(syscallwrap[i].x86s == s) {
             int sc = syscallwrap[i].nats;
@@ -422,6 +460,37 @@ uint32_t EXPORT my32_syscall(x64emu_t *emu, ptr_t* b)
                 printf_log(LOG_INFO, "Warning: ignoring libc Syscall tgkill (%u, %u, %u)\n", u32(4), u32(8), u32(12));
             }*/
             return 0;
+#endif
+        case 312: // get_robust_list
+            {
+                // will wrap only head for now
+                static uint8_t i386_nothing[0x14] = {0};  // for faking steamcmd use of get_robust_list
+                static struct i386_robust_list_head h;
+                ulong_t *arg2 = p(12);
+                ptr_t* arg1 = p(8);
+                tmp = arg1?(from_ptrv(*arg1)):NULL;
+                tmps = arg2?(from_ulong(*arg2)):0;
+                ret = syscall(__NR_get_robust_list, u32(4), arg1?(&tmp):NULL, arg2?(&tmps):NULL);
+                if(!ret) {
+                    if(box64_steamcmd) {
+                        h.list.next = to_ptrv(&h);
+                        h.futex_offset = -0x14;
+                        h.list_op_pending = 0;
+                        *arg1 = to_ptrv(&h);
+                        *arg2 = 12;
+                    } else {
+                        if(arg1) {
+                            h.list.next = to_ptrv(((void**)tmp)[0]);//(*(void**)tmp==tmp)?to_ptrv(&h):to_ptrv(*(void**)tmp); // set head
+                            h.futex_offset = to_long(((long*)tmp)[1]);
+                            h.list_op_pending = to_ptrv(((void**)tmp)[2]);
+                            *arg1 = to_ptrv(&h);   // should wrap all the structures, and keep it alive...
+                        }
+                        if(arg2) *arg2 = to_ulong(tmps/2);    // it's 2 times smaller in x86
+                    }
+                }
+            }
+            return ret;
+#if 0
 #ifndef NOALIGN
         case 329:   // epoll_create1
             return my32_epoll_create1(emu, of_convert32(i32(4)));
@@ -432,7 +501,7 @@ uint32_t EXPORT my32_syscall(x64emu_t *emu, ptr_t* b)
 #endif
 #ifndef __NR_memfd_create
         case 356:  // memfd_create
-            return (uint32_t)my32_memfd_create(emu, (void*)R_EBX, R_ECX);
+            return (uint32_t)my32_memfd_create(emu, p(4), u32(8));
 #endif
 #endif
         default:
diff --git a/src/libtools/threads.c b/src/libtools/threads.c
index 0973d658..8de7f5e9 100644
--- a/src/libtools/threads.c
+++ b/src/libtools/threads.c
@@ -140,8 +140,8 @@ static void emuthread_destroy(void* p)
         free_tlsdatasize(ptr);*/
 	// free x64emu
 	#ifdef BOX32
-	if(box64_is32bits && !et->join)
-		to_hash_d(et->self);
+	/*if(box64_is32bits && !et->join)	// not removing  hash key from old pthread_t
+		to_hash_d(et->self);*/
 	#endif
 	if(et) {
 		FreeX64Emu(&et->emu);
@@ -161,8 +161,8 @@ static void emuthread_cancel(void* p)
 		DynaRun(et->emu);	// will return after a __pthread_unwind_next()
 	}
 	#ifdef BOX32
-	if(box64_is32bits)
-		to_hash_d(et->self);
+	/*if(box64_is32bits)
+		to_hash_d(et->self);*/ // not removing hash for old pthread_t
 	#endif
 	box_free(et->cancels);
 	et->cancels=NULL;
diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt
index 579519ca..d4c0741c 100644
--- a/src/wrapped32/generated/functions_list.txt
+++ b/src/wrapped32/generated/functions_list.txt
@@ -201,6 +201,7 @@
 #() iFEppp -> iFEppp
 #() iFEppV -> iFEppV
 #() iFEpOu -> iFEpOu
+#() iFEhpp -> iFEhpp
 #() iFEhpV -> iFEhpV
 #() iFiiip -> iFiiip
 #() iFiiiN -> iFiiiN
@@ -273,7 +274,7 @@
 #() pFEppv -> pFEpp
 #() LFpBp_iv -> LFpBp_i
 #() iFEivpV -> iFEipV
-#() iFEpvpp -> iFEppp
+#() iFEhvpp -> iFEhpp
 #() iFEhvpV -> iFEhpV
 #() iFEpvvpV -> iFEppV
 #() iFEpuvvppp -> iFEpuppp
@@ -361,6 +362,7 @@ wrappedlibc:
   - fscanf
   - swscanf
 - iFpOu:
+- iFhpp:
 - KFppa:
   - __strtold_l
   - strtold_l
@@ -380,12 +382,12 @@ wrappedlibc:
 - iFiiip:
 - iFipii:
 - iFLLLL:
-- iFpvpp:
 - iFpupV:
 - iFpLpV:
 - iFppiV:
 - iFpppp:
   - getaddrinfo
+- iFhvpp:
 - iFhvpV:
 - LFppiv:
 - iFpvvpV:
diff --git a/src/wrapped32/generated/wrappedlibctypes32.h b/src/wrapped32/generated/wrappedlibctypes32.h
index 0e84d953..147135fe 100644
--- a/src/wrapped32/generated/wrappedlibctypes32.h
+++ b/src/wrapped32/generated/wrappedlibctypes32.h
@@ -55,6 +55,7 @@ typedef int32_t (*iFppL_t)(void*, void*, uintptr_t);
 typedef int32_t (*iFppp_t)(void*, void*, void*);
 typedef int32_t (*iFppV_t)(void*, void*, ...);
 typedef int32_t (*iFpOu_t)(void*, int32_t, uint32_t);
+typedef int32_t (*iFhpp_t)(uintptr_t, void*, void*);
 typedef double (*KFppa_t)(void*, void*, void*);
 typedef intptr_t (*lFipi_t)(int32_t, void*, int32_t);
 typedef intptr_t (*lFipL_t)(int32_t, void*, uintptr_t);
@@ -68,11 +69,11 @@ typedef int32_t (*iFivpV_t)(int32_t, void, void*, ...);
 typedef int32_t (*iFiiip_t)(int32_t, int32_t, int32_t, void*);
 typedef int32_t (*iFipii_t)(int32_t, void*, int32_t, int32_t);
 typedef int32_t (*iFLLLL_t)(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
-typedef int32_t (*iFpvpp_t)(void*, void, void*, void*);
 typedef int32_t (*iFpupV_t)(void*, uint32_t, void*, ...);
 typedef int32_t (*iFpLpV_t)(void*, uintptr_t, void*, ...);
 typedef int32_t (*iFppiV_t)(void*, void*, int32_t, ...);
 typedef int32_t (*iFpppp_t)(void*, void*, void*, void*);
+typedef int32_t (*iFhvpp_t)(uintptr_t, void, void*, void*);
 typedef int32_t (*iFhvpV_t)(uintptr_t, void, void*, ...);
 typedef uintptr_t (*LFppiv_t)(void*, void*, int32_t, void);
 typedef int32_t (*iFpvvpV_t)(void*, void, void, void*, ...);
diff --git a/src/wrapped32/generated/wrapper32.c b/src/wrapped32/generated/wrapper32.c
index 6451d60a..79a898e9 100644
--- a/src/wrapped32/generated/wrapper32.c
+++ b/src/wrapped32/generated/wrapper32.c
@@ -275,6 +275,7 @@ typedef int32_t (*iFEppL_t)(x64emu_t*, void*, void*, uintptr_t);
 typedef int32_t (*iFEppp_t)(x64emu_t*, void*, void*, void*);
 typedef int32_t (*iFEppV_t)(x64emu_t*, void*, void*, void*);
 typedef int32_t (*iFEpOu_t)(x64emu_t*, void*, int32_t, uint32_t);
+typedef int32_t (*iFEhpp_t)(x64emu_t*, uintptr_t, void*, void*);
 typedef int32_t (*iFEhpV_t)(x64emu_t*, uintptr_t, void*, void*);
 typedef int32_t (*iFiiip_t)(int32_t, int32_t, int32_t, void*);
 typedef int32_t (*iFiiiN_t)(int32_t, int32_t, int32_t, ...);
@@ -555,6 +556,7 @@ void iFEppL_32(x64emu_t *emu, uintptr_t fcn) { iFEppL_t fn = (iFEppL_t)fcn; R_EA
 void iFEppp_32(x64emu_t *emu, uintptr_t fcn) { iFEppp_t fn = (iFEppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); }
 void iFEppV_32(x64emu_t *emu, uintptr_t fcn) { iFEppV_t fn = (iFEppV_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptrv(R_ESP + 12)); }
 void iFEpOu_32(x64emu_t *emu, uintptr_t fcn) { iFEpOu_t fn = (iFEpOu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), of_convert32(from_ptri(int32_t, R_ESP + 8)), from_ptri(uint32_t, R_ESP + 12)); }
+void iFEhpp_32(x64emu_t *emu, uintptr_t fcn) { iFEhpp_t fn = (iFEhpp_t)fcn; R_EAX = fn(emu, from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); }
 void iFEhpV_32(x64emu_t *emu, uintptr_t fcn) { iFEhpV_t fn = (iFEhpV_t)fcn; R_EAX = fn(emu, from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptrv(R_ESP + 12)); }
 void iFiiip_32(x64emu_t *emu, uintptr_t fcn) { iFiiip_t fn = (iFiiip_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16)); }
 void iFiiiN_32(x64emu_t *emu, uintptr_t fcn) { iFiiiN_t fn = (iFiiiN_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16)); }
@@ -637,7 +639,7 @@ void UFsvvs_32(x64emu_t *emu, uintptr_t fcn) { UFss_t fn = (UFss_t)fcn; ui64_t r
 void pFEppv_32(x64emu_t *emu, uintptr_t fcn) { pFEpp_t fn = (pFEpp_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8))); }
 void LFpBp_iv_32(x64emu_t *emu, uintptr_t fcn) { LFpBp_i_t fn = (LFpBp_i_t)fcn; struct_p_t arg_8; R_EAX = to_ulong(fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL, from_ptri(int32_t, R_ESP + 12))); if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); }
 void iFEivpV_32(x64emu_t *emu, uintptr_t fcn) { iFEipV_t fn = (iFEipV_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 12), from_ptrv(R_ESP + 16)); }
-void iFEpvpp_32(x64emu_t *emu, uintptr_t fcn) { iFEppp_t fn = (iFEppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16)); }
+void iFEhvpp_32(x64emu_t *emu, uintptr_t fcn) { iFEhpp_t fn = (iFEhpp_t)fcn; R_EAX = fn(emu, from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16)); }
 void iFEhvpV_32(x64emu_t *emu, uintptr_t fcn) { iFEhpV_t fn = (iFEhpV_t)fcn; R_EAX = fn(emu, from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptriv(R_ESP + 12), from_ptrv(R_ESP + 16)); }
 void iFEpvvpV_32(x64emu_t *emu, uintptr_t fcn) { iFEppV_t fn = (iFEppV_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 16), from_ptrv(R_ESP + 20)); }
 void iFEpuvvppp_32(x64emu_t *emu, uintptr_t fcn) { iFEpuppp_t fn = (iFEpuppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptriv(R_ESP + 20), from_ptriv(R_ESP + 24), from_ptriv(R_ESP + 28)); }
diff --git a/src/wrapped32/generated/wrapper32.h b/src/wrapped32/generated/wrapper32.h
index a5b66b50..6e6adf78 100644
--- a/src/wrapped32/generated/wrapper32.h
+++ b/src/wrapped32/generated/wrapper32.h
@@ -241,6 +241,7 @@ void iFEppL_32(x64emu_t *emu, uintptr_t fnc);
 void iFEppp_32(x64emu_t *emu, uintptr_t fnc);
 void iFEppV_32(x64emu_t *emu, uintptr_t fnc);
 void iFEpOu_32(x64emu_t *emu, uintptr_t fnc);
+void iFEhpp_32(x64emu_t *emu, uintptr_t fnc);
 void iFEhpV_32(x64emu_t *emu, uintptr_t fnc);
 void iFiiip_32(x64emu_t *emu, uintptr_t fnc);
 void iFiiiN_32(x64emu_t *emu, uintptr_t fnc);
@@ -323,7 +324,7 @@ void UFsvvs_32(x64emu_t *emu, uintptr_t fnc);
 void pFEppv_32(x64emu_t *emu, uintptr_t fnc);
 void LFpBp_iv_32(x64emu_t *emu, uintptr_t fnc);
 void iFEivpV_32(x64emu_t *emu, uintptr_t fnc);
-void iFEpvpp_32(x64emu_t *emu, uintptr_t fnc);
+void iFEhvpp_32(x64emu_t *emu, uintptr_t fnc);
 void iFEhvpV_32(x64emu_t *emu, uintptr_t fnc);
 void iFEpvvpV_32(x64emu_t *emu, uintptr_t fnc);
 void iFEpuvvppp_32(x64emu_t *emu, uintptr_t fnc);
diff --git a/src/wrapped32/wrappedlibc_private.h b/src/wrapped32/wrappedlibc_private.h
index c3da65ed..4a93f576 100755
--- a/src/wrapped32/wrappedlibc_private.h
+++ b/src/wrapped32/wrappedlibc_private.h
@@ -1883,8 +1883,8 @@ GOM(__vasprintf_chk, iFEpippp) //%%
 //GO(versionsort64, iFpp) //need to align dirent64?
 GOWM(vfork, iFEv) //%%
 // __vfork
-//GOM(vfprintf, iFEppp) //%%
-GOM(__vfprintf_chk, iFEpvpp) //%%
+GOM(vfprintf, iFEhpp) //%%
+GOM(__vfprintf_chk, iFEhvpp) //%%
 //GOWM(vfscanf, iFEppp)  //%%
 // __vfscanf
 //GOWM(vfwprintf, iFEppp)    //%%