about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-08-31 00:10:10 +0800
committerGitHub <noreply@github.com>2025-08-30 18:10:10 +0200
commit373d778f6abf943f779328daa0a2b425d6469077 (patch)
treefa7a4becf8a0a2129a1e699594469808de75faa5 /src
parentfcd1aacef02a75ec74ff17edfcdb3ea46a9b4d2e (diff)
downloadbox64-373d778f6abf943f779328daa0a2b425d6469077.tar.gz
box64-373d778f6abf943f779328daa0a2b425d6469077.zip
[WRAPPER] Wrapped mallinfo2 for libc (#2983)
Diffstat (limited to 'src')
-rw-r--r--src/wrapped/generated/functions_list.txt1
-rw-r--r--src/wrapped/generated/wrappedlibctypes.h1
-rw-r--r--src/wrapped/wrappedlibc.c16
-rw-r--r--src/wrapped/wrappedlibc_private.h1
4 files changed, 19 insertions, 0 deletions
diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt
index a3b8aab8..140feef3 100644
--- a/src/wrapped/generated/functions_list.txt
+++ b/src/wrapped/generated/functions_list.txt
@@ -4619,6 +4619,7 @@ wrappedlibc:
 - pFp:
   - __deregister_frame_info
   - mallinfo
+  - mallinfo2
 - vFpi:
   - __longjmp_chk
   - _longjmp
diff --git a/src/wrapped/generated/wrappedlibctypes.h b/src/wrapped/generated/wrappedlibctypes.h
index 980283af..f22b2ee7 100644
--- a/src/wrapped/generated/wrappedlibctypes.h
+++ b/src/wrapped/generated/wrappedlibctypes.h
@@ -145,6 +145,7 @@ typedef int32_t (*iFppipppp_t)(void*, void*, int32_t, void*, void*, void*, void*
 	GO(_ZGTtnam, pFL_t) \
 	GO(__deregister_frame_info, pFp_t) \
 	GO(mallinfo, pFp_t) \
+	GO(mallinfo2, pFp_t) \
 	GO(__longjmp_chk, vFpi_t) \
 	GO(_longjmp, vFpi_t) \
 	GO(_obstack_newchunk, vFpi_t) \
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index f5a2771f..742ae677 100644
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -3190,6 +3190,22 @@ EXPORT void* my_mallinfo(x64emu_t* emu, void* p)
     return p;
 }
 
+typedef struct mallinfo2 (*mallinfo2_fnc)(void);
+EXPORT void* my_mallinfo2(x64emu_t* emu, void* p)
+{
+    static mallinfo2_fnc f = NULL;
+    static int inited = 0;
+    if(!inited) {
+        inited = 1;
+        f = (mallinfo2_fnc)dlsym(my_lib->w.lib, "mallinfo2");
+    }
+    if(f)
+        *(struct mallinfo2*)p=f();
+    else
+        memset(p, 0, sizeof(struct mallinfo2));
+    return p;
+}
+
 #ifdef STATICBUILD
 void my_updateGlobalOpt() {}
 void my_checkGlobalOpt() {}
diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h
index e5085322..d318f558 100644
--- a/src/wrapped/wrappedlibc_private.h
+++ b/src/wrapped/wrappedlibc_private.h
@@ -1250,6 +1250,7 @@ GO(__madvise, iFpLi)
 GOW(madvise, iFpLi)
 GOWM(makecontext, vFEppiV)
 GOWM(mallinfo, pFEp)
+GOWM(mallinfo2, pFEp)
 GO(malloc, pFL)
 //GO(malloc_get_state, 
 GOW(malloc_info, iFiS)