about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-04-16 15:04:43 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-04-16 15:04:43 +0200
commit9e37c04fb24dc30b129d8c858b956aa9d4784a97 (patch)
tree83878d3c26839b65b97a1e51dcb8bcda6dc3999d /src
parent7870940532b7adb8339a1526ed6a6bb196d5e9ab (diff)
downloadbox64-9e37c04fb24dc30b129d8c858b956aa9d4784a97.tar.gz
box64-9e37c04fb24dc30b129d8c858b956aa9d4784a97.zip
Improved support for musl programs
Diffstat (limited to 'src')
-rwxr-xr-xsrc/library_list.h3
-rw-r--r--src/wrapped/generated/functions_list.txt16
-rw-r--r--src/wrapped/generated/wrappedlibcmusldefs.h8
-rw-r--r--src/wrapped/generated/wrappedlibcmusltypes.h17
-rw-r--r--src/wrapped/generated/wrappedlibcmuslundefs.h8
-rw-r--r--src/wrapped/generated/wrappedtbbbinddefs.h8
-rw-r--r--src/wrapped/generated/wrappedtbbbindtypes.h30
-rw-r--r--src/wrapped/generated/wrappedtbbbindundefs.h8
-rw-r--r--src/wrapped/generated/wrapper.c3
-rw-r--r--src/wrapped/generated/wrapper.h1
-rw-r--r--src/wrapped/wrappedlibcmusl.c35
-rw-r--r--src/wrapped/wrappedlibcmusl_private.h4
-rw-r--r--src/wrapped/wrappedtbbbind.c54
-rw-r--r--src/wrapped/wrappedtbbbind_private.h14
14 files changed, 208 insertions, 1 deletions
diff --git a/src/library_list.h b/src/library_list.h
index 15dbaebe..68a07e77 100755
--- a/src/library_list.h
+++ b/src/library_list.h
@@ -3,7 +3,7 @@
 #endif
 
 GO("libc.so.6", libc)
-GO("libc.musl-x86_64.so.1", libdl)
+GO("libc.musl-x86_64.so.1", libcmusl)
 GO("libpthread.so.0", libpthread)
 GO("librt.so.1", librt)
 GO("libEGL.so.1", libegl)
@@ -168,6 +168,7 @@ GO("libncurses.so.6", libncurses6)
 GO("libtinfo.so.6", libtinfo6)
 GO("libtbbmalloc.so.2", tbbmalloc)
 GO("libtbbmalloc_proxy.so.2", tbbmallocproxy)
+GO("libtbbbind_2_5.so", tbbbind)
 GO("libtcmalloc_minimal.so.0", tcmallocminimal)
 GO("libtcmalloc_minimal.so.4", tcmallocminimal)
 GO("libmpg123.so.0", mpg123)
diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt
index f5806243..a7466c1c 100644
--- a/src/wrapped/generated/functions_list.txt
+++ b/src/wrapped/generated/functions_list.txt
@@ -1146,6 +1146,7 @@
 #() vFUUppp
 #() vFfffff
 #() vFddddp
+#() vFLpppp
 #() vFpiiii
 #() vFpiiiI
 #() vFpiiiu
@@ -3426,6 +3427,7 @@ wrappedlibc:
   - __libc_start_main
 - iFppipppp:
   - clone
+wrappedlibcmusl:
 wrappedlibcrypt:
 wrappedlibcups:
 - iFuipuupp:
@@ -4359,6 +4361,20 @@ wrappedsmpeg2:
   - SMPEG_new_rwops
 wrappedsoftokn3:
 wrappedssl3:
+wrappedtbbbind:
+- vFv:
+  - __TBB_internal_destroy_system_topology
+- vFp:
+  - __TBB_internal_deallocate_binding_handler
+- vFpi:
+  - __TBB_internal_apply_affinity
+  - __TBB_internal_restore_affinity
+- iFiii:
+  - __TBB_internal_get_default_concurrency
+- pFiiii:
+  - __TBB_internal_allocate_binding_handler
+- vFLpppp:
+  - __TBB_internal_initialize_system_topology
 wrappedtbbmalloc:
 - vFp:
   - scalable_aligned_free
diff --git a/src/wrapped/generated/wrappedlibcmusldefs.h b/src/wrapped/generated/wrappedlibcmusldefs.h
new file mode 100644
index 00000000..663f6679
--- /dev/null
+++ b/src/wrapped/generated/wrappedlibcmusldefs.h
@@ -0,0 +1,8 @@
+/*******************************************************************
+ * File automatically generated by rebuild_wrappers.py (v2.2.0.17) *
+ *******************************************************************/
+#ifndef __wrappedlibcmuslDEFS_H_
+#define __wrappedlibcmuslDEFS_H_
+
+
+#endif // __wrappedlibcmuslDEFS_H_
diff --git a/src/wrapped/generated/wrappedlibcmusltypes.h b/src/wrapped/generated/wrappedlibcmusltypes.h
new file mode 100644
index 00000000..da781fc7
--- /dev/null
+++ b/src/wrapped/generated/wrappedlibcmusltypes.h
@@ -0,0 +1,17 @@
+/*******************************************************************
+ * File automatically generated by rebuild_wrappers.py (v2.2.0.17) *
+ *******************************************************************/
+#ifndef __wrappedlibcmuslTYPES_H_
+#define __wrappedlibcmuslTYPES_H_
+
+#ifndef LIBNAME
+#error You should only #include this file inside a wrapped*.c file
+#endif
+#ifndef ADDED_FUNCTIONS
+#define ADDED_FUNCTIONS() 
+#endif
+
+
+#define SUPER() ADDED_FUNCTIONS()
+
+#endif // __wrappedlibcmuslTYPES_H_
diff --git a/src/wrapped/generated/wrappedlibcmuslundefs.h b/src/wrapped/generated/wrappedlibcmuslundefs.h
new file mode 100644
index 00000000..d562391d
--- /dev/null
+++ b/src/wrapped/generated/wrappedlibcmuslundefs.h
@@ -0,0 +1,8 @@
+/*******************************************************************
+ * File automatically generated by rebuild_wrappers.py (v2.2.0.17) *
+ *******************************************************************/
+#ifndef __wrappedlibcmuslUNDEFS_H_
+#define __wrappedlibcmuslUNDEFS_H_
+
+
+#endif // __wrappedlibcmuslUNDEFS_H_
diff --git a/src/wrapped/generated/wrappedtbbbinddefs.h b/src/wrapped/generated/wrappedtbbbinddefs.h
new file mode 100644
index 00000000..68313639
--- /dev/null
+++ b/src/wrapped/generated/wrappedtbbbinddefs.h
@@ -0,0 +1,8 @@
+/*******************************************************************
+ * File automatically generated by rebuild_wrappers.py (v2.2.0.17) *
+ *******************************************************************/
+#ifndef __wrappedtbbbindDEFS_H_
+#define __wrappedtbbbindDEFS_H_
+
+
+#endif // __wrappedtbbbindDEFS_H_
diff --git a/src/wrapped/generated/wrappedtbbbindtypes.h b/src/wrapped/generated/wrappedtbbbindtypes.h
new file mode 100644
index 00000000..fddbb6c5
--- /dev/null
+++ b/src/wrapped/generated/wrappedtbbbindtypes.h
@@ -0,0 +1,30 @@
+/*******************************************************************
+ * File automatically generated by rebuild_wrappers.py (v2.2.0.17) *
+ *******************************************************************/
+#ifndef __wrappedtbbbindTYPES_H_
+#define __wrappedtbbbindTYPES_H_
+
+#ifndef LIBNAME
+#error You should only #include this file inside a wrapped*.c file
+#endif
+#ifndef ADDED_FUNCTIONS
+#define ADDED_FUNCTIONS() 
+#endif
+
+typedef void (*vFv_t)(void);
+typedef void (*vFp_t)(void*);
+typedef void (*vFpi_t)(void*, int32_t);
+typedef int32_t (*iFiii_t)(int32_t, int32_t, int32_t);
+typedef void* (*pFiiii_t)(int32_t, int32_t, int32_t, int32_t);
+typedef void (*vFLpppp_t)(uintptr_t, void*, void*, void*, void*);
+
+#define SUPER() ADDED_FUNCTIONS() \
+	GO(__TBB_internal_destroy_system_topology, vFv_t) \
+	GO(__TBB_internal_deallocate_binding_handler, vFp_t) \
+	GO(__TBB_internal_apply_affinity, vFpi_t) \
+	GO(__TBB_internal_restore_affinity, vFpi_t) \
+	GO(__TBB_internal_get_default_concurrency, iFiii_t) \
+	GO(__TBB_internal_allocate_binding_handler, pFiiii_t) \
+	GO(__TBB_internal_initialize_system_topology, vFLpppp_t)
+
+#endif // __wrappedtbbbindTYPES_H_
diff --git a/src/wrapped/generated/wrappedtbbbindundefs.h b/src/wrapped/generated/wrappedtbbbindundefs.h
new file mode 100644
index 00000000..d92da691
--- /dev/null
+++ b/src/wrapped/generated/wrappedtbbbindundefs.h
@@ -0,0 +1,8 @@
+/*******************************************************************
+ * File automatically generated by rebuild_wrappers.py (v2.2.0.17) *
+ *******************************************************************/
+#ifndef __wrappedtbbbindUNDEFS_H_
+#define __wrappedtbbbindUNDEFS_H_
+
+
+#endif // __wrappedtbbbindUNDEFS_H_
diff --git a/src/wrapped/generated/wrapper.c b/src/wrapped/generated/wrapper.c
index 7763e661..1d167ac8 100644
--- a/src/wrapped/generated/wrapper.c
+++ b/src/wrapped/generated/wrapper.c
@@ -1182,6 +1182,7 @@ typedef void (*vFupppp_t)(uint32_t, void*, void*, void*, void*);
 typedef void (*vFUUppp_t)(uint64_t, uint64_t, void*, void*, void*);
 typedef void (*vFfffff_t)(float, float, float, float, float);
 typedef void (*vFddddp_t)(double, double, double, double, void*);
+typedef void (*vFLpppp_t)(uintptr_t, void*, void*, void*, void*);
 typedef void (*vFpiiii_t)(void*, int32_t, int32_t, int32_t, int32_t);
 typedef void (*vFpiiiI_t)(void*, int32_t, int32_t, int32_t, int64_t);
 typedef void (*vFpiiiu_t)(void*, int32_t, int32_t, int32_t, uint32_t);
@@ -3584,6 +3585,7 @@ void vFupppp(x64emu_t *emu, uintptr_t fcn) { vFupppp_t fn = (vFupppp_t)fcn; fn((
 void vFUUppp(x64emu_t *emu, uintptr_t fcn) { vFUUppp_t fn = (vFUUppp_t)fcn; fn((uint64_t)R_RDI, (uint64_t)R_RSI, (void*)R_RDX, (void*)R_RCX, (void*)R_R8); }
 void vFfffff(x64emu_t *emu, uintptr_t fcn) { vFfffff_t fn = (vFfffff_t)fcn; fn(emu->xmm[0].f[0], emu->xmm[1].f[0], emu->xmm[2].f[0], emu->xmm[3].f[0], emu->xmm[4].f[0]); }
 void vFddddp(x64emu_t *emu, uintptr_t fcn) { vFddddp_t fn = (vFddddp_t)fcn; fn(emu->xmm[0].d[0], emu->xmm[1].d[0], emu->xmm[2].d[0], emu->xmm[3].d[0], (void*)R_RDI); }
+void vFLpppp(x64emu_t *emu, uintptr_t fcn) { vFLpppp_t fn = (vFLpppp_t)fcn; fn((uintptr_t)R_RDI, (void*)R_RSI, (void*)R_RDX, (void*)R_RCX, (void*)R_R8); }
 void vFpiiii(x64emu_t *emu, uintptr_t fcn) { vFpiiii_t fn = (vFpiiii_t)fcn; fn((void*)R_RDI, (int32_t)R_RSI, (int32_t)R_RDX, (int32_t)R_RCX, (int32_t)R_R8); }
 void vFpiiiI(x64emu_t *emu, uintptr_t fcn) { vFpiiiI_t fn = (vFpiiiI_t)fcn; fn((void*)R_RDI, (int32_t)R_RSI, (int32_t)R_RDX, (int32_t)R_RCX, (int64_t)R_R8); }
 void vFpiiiu(x64emu_t *emu, uintptr_t fcn) { vFpiiiu_t fn = (vFpiiiu_t)fcn; fn((void*)R_RDI, (int32_t)R_RSI, (int32_t)R_RDX, (int32_t)R_RCX, (uint32_t)R_R8); }
@@ -5790,6 +5792,7 @@ int isSimpleWrapper(wrapper_t fun) {
 	if (fun == &vFUUppp) return 1;
 	if (fun == &vFfffff) return 6;
 	if (fun == &vFddddp) return 5;
+	if (fun == &vFLpppp) return 1;
 	if (fun == &vFpiiii) return 1;
 	if (fun == &vFpiiiI) return 1;
 	if (fun == &vFpiiiu) return 1;
diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h
index 000d9e36..ededa59d 100644
--- a/src/wrapped/generated/wrapper.h
+++ b/src/wrapped/generated/wrapper.h
@@ -1183,6 +1183,7 @@ void vFupppp(x64emu_t *emu, uintptr_t fnc);
 void vFUUppp(x64emu_t *emu, uintptr_t fnc);
 void vFfffff(x64emu_t *emu, uintptr_t fnc);
 void vFddddp(x64emu_t *emu, uintptr_t fnc);
+void vFLpppp(x64emu_t *emu, uintptr_t fnc);
 void vFpiiii(x64emu_t *emu, uintptr_t fnc);
 void vFpiiiI(x64emu_t *emu, uintptr_t fnc);
 void vFpiiiu(x64emu_t *emu, uintptr_t fnc);
diff --git a/src/wrapped/wrappedlibcmusl.c b/src/wrapped/wrappedlibcmusl.c
new file mode 100644
index 00000000..787561e5
--- /dev/null
+++ b/src/wrapped/wrappedlibcmusl.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#define _GNU_SOURCE         /* See feature_test_macros(7) */
+#include <dlfcn.h>
+
+#include "wrappedlibs.h"
+
+#include "debug.h"
+#include "wrapper.h"
+#include "bridge.h"
+#include "librarian/library_private.h"
+#include "x64emu.h"
+#include "emu/x64emu_private.h"
+#include "elfloader.h"
+#include "box64context.h"
+#include "x64tls.h"
+
+
+// don't try to load the actual ld-linux (because name is variable), just use box64 itself, as it's linked to ld-linux
+const char* libcmuslName = "libc.musl-x86_64.so.1";
+#define LIBNAME libcmusl
+
+#define PRE_INIT\
+    if(1)                                                           \
+        lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);    \
+    else
+
+#define CUSTOM_INIT \
+    box64_musl = 1; \
+    setNeededLibs(lib, 5, "libtbbmalloc.so.2", "libtbbmalloc_proxy.so.2", "libtbbbind_2_5.so", "libc.so.6", "libdl.so.2");
+
+// define all standard library functions
+#include "wrappedlib_init.h"
+
diff --git a/src/wrapped/wrappedlibcmusl_private.h b/src/wrapped/wrappedlibcmusl_private.h
new file mode 100644
index 00000000..b295d350
--- /dev/null
+++ b/src/wrapped/wrappedlibcmusl_private.h
@@ -0,0 +1,4 @@
+#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA))
+#error meh!
+#endif
+
diff --git a/src/wrapped/wrappedtbbbind.c b/src/wrapped/wrappedtbbbind.c
new file mode 100644
index 00000000..997438e1
--- /dev/null
+++ b/src/wrapped/wrappedtbbbind.c
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#define _GNU_SOURCE         /* See feature_test_macros(7) */
+#include <dlfcn.h>
+
+#include "wrappedlibs.h"
+
+#include "wrapper.h"
+#include "bridge.h"
+#include "librarian/library_private.h"
+#include "x64emu.h"
+#include "debug.h"
+#include "myalign.h"
+#include "callback.h"
+#include "emu/x64emu_private.h"
+
+// Fake the lib for now, don't load it
+const char* tbbbindName = "libtbbbind_2_5.so";
+#define LIBNAME tbbbind
+
+EXPORT void my___TBB_internal_initialize_system_topology(size_t group, void* numa_code, void* numa_list, void* core_type, void* core_list)
+{ }
+
+EXPORT void* my___TBB_internal_allocate_binding_handler(int slot_num, int numa_id, int core_type_id, int max_threads_per_core)
+{
+    // dummy
+    return NULL;
+}
+
+EXPORT void my___TBB_internal_apply_affinity(void* handler, int slot)
+{ }
+
+EXPORT void my___TBB_internal_deallocate_binding_handler(void* handler)
+{ }
+
+EXPORT void my___TBB_internal_destroy_system_topology()
+{ }
+
+int getNCpu();
+EXPORT int my___TBB_internal_get_default_concurrency(int numa_id, int core_type, int max_threads_per_core)
+{
+    return getNCpu();
+}
+
+EXPORT void my___TBB_internal_restore_affinity(void* handler, int slot)
+{ }
+
+// this preinit basically open "box64" as dlopen
+#define PRE_INIT\
+    lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);    \
+    if(0)
+
+#include "wrappedlib_init.h"
diff --git a/src/wrapped/wrappedtbbbind_private.h b/src/wrapped/wrappedtbbbind_private.h
new file mode 100644
index 00000000..9df20a38
--- /dev/null
+++ b/src/wrapped/wrappedtbbbind_private.h
@@ -0,0 +1,14 @@
+#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA))
+#error Meh...
+#endif
+
+GOM(__TBB_internal_allocate_binding_handler, pFiiii)    //%%noE
+GOM(__TBB_internal_apply_affinity, vFpi)   //%%noE
+GOM(__TBB_internal_deallocate_binding_handler, vFp) //%%noE
+GOM(__TBB_internal_destroy_system_topology, vFv)    //%%noE
+GOM(__TBB_internal_get_default_concurrency, iFiii)  //%%noE
+GOM(__TBB_internal_initialize_system_topology, vFLpppp) //%%noE
+GOM(__TBB_internal_restore_affinity, vFpi)  //%%noE
+//GO(_ZN3tbb6detail2r115runtime_warningEPKcz, 
+//DATA(_ZN3tbb6detail2r115system_topology12instance_ptrE, 
+//GO(_ZN3tbb6detail2r117assertion_failureEPKciS3_S3_,