about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-10-19 10:38:11 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-10-19 10:38:11 +0200
commita5797da100bebf3941cecfb0fe0ed094f963f108 (patch)
tree03a99ab13052e6c632f8a36951e2de587f256a99
parent0821e6acc230b4cc9806ce29f4def74c76465394 (diff)
downloadbox64-a5797da100bebf3941cecfb0fe0ed094f963f108.tar.gz
box64-a5797da100bebf3941cecfb0fe0ed094f963f108.zip
[BOX32][WRAPPER] Added some more libc wrapped function, and 32bits globalsymbol infrastructure
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/include/globalsymbols.h10
-rw-r--r--src/librarian/globalsymbols32.c108
-rw-r--r--src/wrapped32/generated/functions_list.txt3
-rw-r--r--src/wrapped32/generated/wrappedlibctypes32.h2
-rw-r--r--src/wrapped32/generated/wrapper32.c2
-rw-r--r--src/wrapped32/generated/wrapper32.h1
-rwxr-xr-xsrc/wrapped32/wrappedlibc.c2
-rwxr-xr-xsrc/wrapped32/wrappedlibc_private.h2
9 files changed, 129 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3809a5d9..6a813cda 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -396,6 +396,7 @@ if(BOX32)
         "${BOX64_ROOT}/src/elfs/elfload_dump32.c"
         "${BOX64_ROOT}/src/tools/box32stack.c"
         "${BOX64_ROOT}/src/emu/x86int3.c"
+        "${BOX64_ROOT}/src/librarian/globalsymbols32.c"
         "${BOX64_ROOT}/src/libtools/myalign32.c"
         "${BOX64_ROOT}/src/libtools/myalign64_32.c"
         "${BOX64_ROOT}/src/libtools/signal32.c"
diff --git a/src/include/globalsymbols.h b/src/include/globalsymbols.h
index 6344d5b1..bd840ed9 100644
--- a/src/include/globalsymbols.h
+++ b/src/include/globalsymbols.h
@@ -16,6 +16,16 @@ void my_updateGlobalTInfo(void);
 void my_checkGlobalOpt(void);

 void my_updateGlobalOpt(void);

 

+#ifdef BOX32

+// NCurse / TInfo

+void my32_checkGlobalTInfo(void);

+void my32_updateGlobalTInfo(void);

+

+// getopt

+void my32_checkGlobalOpt(void);

+void my32_updateGlobalOpt(void);

+#endif

+

 // libxslt

 void my_checkGlobalXslt(void);

 void my_updateGlobalXslt(void);

diff --git a/src/librarian/globalsymbols32.c b/src/librarian/globalsymbols32.c
new file mode 100644
index 00000000..b4c83682
--- /dev/null
+++ b/src/librarian/globalsymbols32.c
@@ -0,0 +1,108 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#include "wrappedlibs.h"
+
+#include "debug.h"
+#include "wrapper32.h"
+#include "bridge.h"
+#include "callback.h"
+#include "box32context.h"
+#include "librarian.h"
+#include "library.h"
+
+// workaround for Globals symbols
+
+#define GLOB(A, B, C) \
+    if (GetGlobalNoWeakSymbolStartEnd(my_context->maplib, #A, &globoffs, &globend, -1, NULL, 0, NULL)) {  \
+        printf_log(LOG_DEBUG, "Global " #A " workaround, @%p <- %p\n", (void*)globoffs, &A);              \
+        memcpy((void*)globoffs, &A, C);                                                                   \
+    }                                                                                                     \
+    if (B && GetGlobalNoWeakSymbolStartEnd(my_context->maplib, #A, &globoffs, &globend, 2, B, 1, NULL)) { \
+        printf_log(LOG_DEBUG, "Global " #A " workaround, @%p <- %p\n", (void*)globoffs, &A);              \
+        memcpy((void*)globoffs, &A, C);                                                                   \
+    }
+
+#define TOGLOB(A, B, C) \
+    if (GetGlobalNoWeakSymbolStartEnd(my_context->maplib, #A, &globoffs, &globend, -1, NULL, 0, NULL)) {  \
+        printf_log(LOG_DEBUG, "Global " #A " workaround, @%p -> %p\n", (void*)globoffs, &A);              \
+        memcpy(&A, (void*)globoffs, C);                                                                   \
+    }                                                                                                     \
+    if (B && GetGlobalNoWeakSymbolStartEnd(my_context->maplib, #A, &globoffs, &globend, 2, B, 1, NULL)) { \
+        printf_log(LOG_DEBUG, "Global " #A " workaround, @%p -> %p\n", (void*)globoffs, &A);              \
+        memcpy(&A, (void*)globoffs, C);                                                                   \
+    }
+
+
+// **************** NCurses ****************
+extern int COLS;
+extern int LINES;
+extern int TABSIZE;
+extern void* curscr;
+extern void* newscr;
+extern void* stdscr;
+extern void* acs_map[128];
+extern void* UP;
+extern void* BC;
+extern uint8_t PC;
+extern uint16_t ospeed;
+extern void* ttytype;
+
+void my32_checkGlobalTInfo()
+{
+    uintptr_t globoffs, globend;
+    GLOB(COLS, NULL, sizeof(int))
+    GLOB(LINES, NULL, sizeof(int))
+    GLOB(TABSIZE, NULL, sizeof(int))
+    GLOB(curscr, NULL, sizeof(ptr_t))
+    GLOB(newscr, NULL, sizeof(ptr_t))
+    GLOB(stdscr, NULL, sizeof(ptr_t))
+    GLOB(acs_map, NULL, sizeof(ptr_t))
+    GLOB(UP, NULL, sizeof(ptr_t))
+    GLOB(BC, NULL, sizeof(ptr_t))
+    GLOB(PC, NULL, sizeof(uint8_t))
+    GLOB(ospeed, NULL, sizeof(uint16_t))
+    GLOB(ttytype, NULL, sizeof(ptr_t))
+}
+
+void my32_updateGlobalTInfo()
+{
+    uintptr_t globoffs, globend;
+    TOGLOB(COLS, NULL, sizeof(int))
+    TOGLOB(LINES, NULL, sizeof(int))
+    TOGLOB(TABSIZE, NULL, sizeof(int))
+    TOGLOB(curscr, NULL, sizeof(ptr_t))
+    TOGLOB(newscr, NULL, sizeof(ptr_t))
+    TOGLOB(stdscr, NULL, sizeof(ptr_t))
+    TOGLOB(acs_map, NULL, sizeof(ptr_t))
+    TOGLOB(UP, NULL, sizeof(ptr_t))
+    TOGLOB(BC, NULL, sizeof(ptr_t))
+    TOGLOB(PC, NULL, sizeof(uint8_t))
+    TOGLOB(ospeed, NULL, sizeof(uint16_t))
+    TOGLOB(ttytype, NULL, sizeof(ptr_t))
+}
+
+// **************** getopts ****************
+extern char *optarg;
+extern int optind, opterr, optopt;
+
+void my32_updateGlobalOpt()
+{
+    uintptr_t globoffs, globend;
+    TOGLOB(optarg, "GLIBC_2.2.5", sizeof(ptr_t));
+    TOGLOB(optind, "GLIBC_2.2.5", sizeof(int));
+    TOGLOB(opterr, "GLIBC_2.2.5", sizeof(int));
+    TOGLOB(optopt, "GLIBC_2.2.5", sizeof(int));
+}
+
+void my32_checkGlobalOpt()
+{
+    uintptr_t globoffs, globend;
+    GLOB(optarg, "GLIBC_2.2.5", sizeof(ptr_t));
+    GLOB(optind, "GLIBC_2.2.5", sizeof(int));
+    GLOB(opterr, "GLIBC_2.2.5", sizeof(int));
+    GLOB(optopt, "GLIBC_2.2.5", sizeof(int));
+}
diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt
index 00a1b693..ea90095d 100644
--- a/src/wrapped32/generated/functions_list.txt
+++ b/src/wrapped32/generated/functions_list.txt
@@ -1001,6 +1001,7 @@
 #() iFiLLLL -> iFiLLLL
 #() iFipLLi -> iFipLLi
 #() iFippLi -> iFippLi
+#() iFipppp -> iFipppp
 #() iFuiuup -> iFuiuup
 #() iFpiiuu -> iFpiiuu
 #() iFpippp -> iFpippp
@@ -1736,6 +1737,8 @@ wrappedlibc:
 - iFSvpV:
 - LFpBp_iv:
 - iFiippi:
+- iFipppp:
+  - getopt_long
 - iFuppLp:
   - getgrgid_r
   - getpwuid_r
diff --git a/src/wrapped32/generated/wrappedlibctypes32.h b/src/wrapped32/generated/wrappedlibctypes32.h
index 3ee8fcef..7f8d7aab 100644
--- a/src/wrapped32/generated/wrappedlibctypes32.h
+++ b/src/wrapped32/generated/wrappedlibctypes32.h
@@ -92,6 +92,7 @@ typedef int32_t (*iFSvpp_t)(void*, void, void*, void*);
 typedef int32_t (*iFSvpV_t)(void*, void, void*, ...);
 typedef uintptr_t (*LFpBp_iv_t)(void*, struct_p_t*, int32_t, void);
 typedef int32_t (*iFiippi_t)(int32_t, int32_t, void*, void*, int32_t);
+typedef int32_t (*iFipppp_t)(int32_t, void*, void*, void*, void*);
 typedef int32_t (*iFuppLp_t)(uint32_t, void*, void*, uintptr_t, void*);
 typedef int32_t (*iFpvvpV_t)(void*, void, void, void*, ...);
 typedef int32_t (*iFpiLpp_t)(void*, int32_t, uintptr_t, void*, void*);
@@ -175,6 +176,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void
 	GO(utimensat, iFippi_t) \
 	GO(readlinkat, iFippL_t) \
 	GO(getaddrinfo, iFpppp_t) \
+	GO(getopt_long, iFipppp_t) \
 	GO(getgrgid_r, iFuppLp_t) \
 	GO(getpwuid_r, iFuppLp_t) \
 	GO(posix_spawn_file_actions_addopen, iFpipOi_t) \
diff --git a/src/wrapped32/generated/wrapper32.c b/src/wrapped32/generated/wrapper32.c
index 818aec2e..21c36577 100644
--- a/src/wrapped32/generated/wrapper32.c
+++ b/src/wrapped32/generated/wrapper32.c
@@ -1091,6 +1091,7 @@ typedef int32_t (*iFiiipp_t)(int32_t, int32_t, int32_t, void*, void*);
 typedef int32_t (*iFiLLLL_t)(int32_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
 typedef int32_t (*iFipLLi_t)(int32_t, void*, uintptr_t, uintptr_t, int32_t);
 typedef int32_t (*iFippLi_t)(int32_t, void*, void*, uintptr_t, int32_t);
+typedef int32_t (*iFipppp_t)(int32_t, void*, void*, void*, void*);
 typedef int32_t (*iFuiuup_t)(uint32_t, int32_t, uint32_t, uint32_t, void*);
 typedef int32_t (*iFpiiuu_t)(void*, int32_t, int32_t, uint32_t, uint32_t);
 typedef int32_t (*iFpippp_t)(void*, int32_t, void*, void*, void*);
@@ -2593,6 +2594,7 @@ void iFiiipp_32(x64emu_t *emu, uintptr_t fcn) { iFiiipp_t fn = (iFiiipp_t)fcn; R
 void iFiLLLL_32(x64emu_t *emu, uintptr_t fcn) { iFiLLLL_t fn = (iFiLLLL_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ulong(from_ptri(ulong_t, R_ESP + 12)), from_ulong(from_ptri(ulong_t, R_ESP + 16)), from_ulong(from_ptri(ulong_t, R_ESP + 20))); }
 void iFipLLi_32(x64emu_t *emu, uintptr_t fcn) { iFipLLi_t fn = (iFipLLi_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ulong(from_ptri(ulong_t, R_ESP + 12)), from_ulong(from_ptri(ulong_t, R_ESP + 16)), from_ptri(int32_t, R_ESP + 20)); }
 void iFippLi_32(x64emu_t *emu, uintptr_t fcn) { iFippLi_t fn = (iFippLi_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ulong(from_ptri(ulong_t, R_ESP + 16)), from_ptri(int32_t, R_ESP + 20)); }
+void iFipppp_32(x64emu_t *emu, uintptr_t fcn) { iFipppp_t fn = (iFipppp_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); }
 void iFuiuup_32(x64emu_t *emu, uintptr_t fcn) { iFuiuup_t fn = (iFuiuup_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptriv(R_ESP + 20)); }
 void iFpiiuu_32(x64emu_t *emu, uintptr_t fcn) { iFpiiuu_t fn = (iFpiiuu_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptri(uint32_t, R_ESP + 20)); }
 void iFpippp_32(x64emu_t *emu, uintptr_t fcn) { iFpippp_t fn = (iFpippp_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); }
diff --git a/src/wrapped32/generated/wrapper32.h b/src/wrapped32/generated/wrapper32.h
index 49e9c30b..a4ef1dcb 100644
--- a/src/wrapped32/generated/wrapper32.h
+++ b/src/wrapped32/generated/wrapper32.h
@@ -1042,6 +1042,7 @@ void iFiiipp_32(x64emu_t *emu, uintptr_t fnc);
 void iFiLLLL_32(x64emu_t *emu, uintptr_t fnc);
 void iFipLLi_32(x64emu_t *emu, uintptr_t fnc);
 void iFippLi_32(x64emu_t *emu, uintptr_t fnc);
+void iFipppp_32(x64emu_t *emu, uintptr_t fnc);
 void iFuiuup_32(x64emu_t *emu, uintptr_t fnc);
 void iFpiiuu_32(x64emu_t *emu, uintptr_t fnc);
 void iFpippp_32(x64emu_t *emu, uintptr_t fnc);
diff --git a/src/wrapped32/wrappedlibc.c b/src/wrapped32/wrappedlibc.c
index 935a88dc..e120f7bc 100755
--- a/src/wrapped32/wrappedlibc.c
+++ b/src/wrapped32/wrappedlibc.c
@@ -2284,6 +2284,7 @@ EXPORT int my32_getopt(int argc, char* const argv[], const char *optstring)
     return ret;
 }
 
+#endif
 EXPORT int my32_getopt_long(int argc, char* const argv[], const char* optstring, const struct option *longopts, int *longindex)
 {
     int ret = getopt_long(argc, argv, optstring, longopts, longindex);
@@ -2297,7 +2298,6 @@ EXPORT int my32_getopt_long_only(int argc, char* const argv[], const char* optst
     my32_checkGlobalOpt();
     return ret;
 }
-#endif
 
 EXPORT int my32_alphasort64(x64emu_t* emu, ptr_t* d1_, ptr_t* d2_)
 {
diff --git a/src/wrapped32/wrappedlibc_private.h b/src/wrapped32/wrappedlibc_private.h
index 47c2ae8d..9bfdf013 100755
--- a/src/wrapped32/wrappedlibc_private.h
+++ b/src/wrapped32/wrappedlibc_private.h
@@ -532,7 +532,7 @@ GO(getnameinfo, iFpupupui)
 GOW(get_nprocs, iFv)
 //GOW(get_nprocs_conf, iFv)
 //GOM(getopt, iFipp)             //%noE
-//GOM(getopt_long, iFipppp)      //%noE
+GOM(getopt_long, iFipppp)      //%noE
 //GOM(getopt_long_only, iFipppp) //%noE
 GOW(getpagesize, iFv)
 GO(__getpagesize, iFv)