about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-04-28 20:59:16 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-04-28 20:59:16 +0200
commit34a6e81f72f8ec276bea8d440ec6d36239daa354 (patch)
tree83eb055f9268583e8b560a85a705ea6fa6d2be62 /src
parent57a9b520b0cc5f2b0d48c96b310356850a75e252 (diff)
downloadbox64-34a6e81f72f8ec276bea8d440ec6d36239daa354.tar.gz
box64-34a6e81f72f8ec276bea8d440ec6d36239daa354.zip
Introduced RunFunctionFmt (should help RV64 and other signe extended platform), conversion not finished
Diffstat (limited to 'src')
-rwxr-xr-xsrc/include/callback.h1
-rwxr-xr-xsrc/tools/callback.c93
-rwxr-xr-xsrc/wrapped/wrappedatk.c8
-rwxr-xr-xsrc/wrapped/wrappedatspi.c4
-rwxr-xr-xsrc/wrapped/wrappedbz2.c4
-rwxr-xr-xsrc/wrapped/wrappedcrypto.c22
-rwxr-xr-xsrc/wrapped/wrappedcrypto3.c28
-rwxr-xr-xsrc/wrapped/wrappedcurl.c22
-rwxr-xr-xsrc/wrapped/wrappeddbus.c30
-rwxr-xr-xsrc/wrapped/wrappedgobject2.c2
-rwxr-xr-xsrc/wrapped/wrappedpulse.c10
11 files changed, 163 insertions, 61 deletions
diff --git a/src/include/callback.h b/src/include/callback.h
index eecbc3d2..836c858c 100755
--- a/src/include/callback.h
+++ b/src/include/callback.h
@@ -6,6 +6,7 @@
 typedef struct x64emu_s x64emu_t;
 
 uint64_t RunFunction(box64context_t *context, uintptr_t fnc, int nargs, ...);
+uint64_t RunFunctionFmt(box64context_t *context, uintptr_t fnc, const char* fmt, ...);
 // save all modified register
 uint64_t RunSafeFunction(box64context_t *context, uintptr_t fnc, int nargs, ...);
 // use emu state to run function
diff --git a/src/tools/callback.c b/src/tools/callback.c
index 9aafa6d8..f954869f 100755
--- a/src/tools/callback.c
+++ b/src/tools/callback.c
@@ -56,6 +56,99 @@ uint64_t RunFunction(box64context_t *context, uintptr_t fnc, int nargs, ...)
 }
 
 EXPORTDYN
+uint64_t RunFunctionFmt(box64context_t *context, uintptr_t fnc, const char* fmt, ...)
+{
+    (void)context;
+
+    x64emu_t *emu = thread_get_emu();
+    int nargs = 0;
+    int ni = 0;
+    int ndf = 0;
+    for (int i=0; fmt[i]; ++i) {
+        switch(fmt[i]) {
+            case 'f': 
+            case 'd': if(ndf<8) ++ndf; else ++nargs; break;
+            case 'p': 
+            case 'i': 
+            case 'u': 
+            case 'I': 
+            case 'U': 
+            case 'L': 
+            case 'l': 
+            case 'w': 
+            case 'W': 
+            case 'c': 
+            case 'C': if(ni<6) ++ni; else ++nargs; break;
+            default:
+                if(ni<6) ++ni; else ++nargs; break;
+        }
+    }
+    ni = 0;
+    ndf = 0;
+    int align = nargs&1;
+    int stackn = align + nargs;
+
+    Push64(emu, R_RBP); // push rbp
+    R_RBP = R_RSP;      // mov rbp, rsp
+
+    R_RSP -= stackn*sizeof(void*);   // need to push in reverse order
+
+    uint64_t *p = (uint64_t*)R_RSP;
+
+    static const int nn[] = {_DI, _SI, _DX, _CX, _R8, _R9};
+    #define GO(c, A, B, B2, C) case c: if(ni<6) emu->regs[nn[ni++]].A[0] = C va_arg(va, B2); else {*p = 0; *((B*)p) = va_arg(va, B2); ++p;}; break;
+    va_list va;
+    va_start (va, fmt);
+    for (int i=0; fmt[i]; ++i) {
+        switch(fmt[i]) {
+            case 'f':   if(ndf<8)
+                            emu->xmm[ndf++].f[0] = va_arg(va, double);  // float are promoted to double in ...
+                        else {
+                            *p = 0;
+                            *((float*)p) = va_arg(va, double);
+                            ++p;
+                        }
+                        break;
+            case 'd':   if(ndf<8)
+                            emu->xmm[ndf++].d[0] = va_arg(va, double);
+                        else {
+                            *((double*)p) = va_arg(va, double);
+                            ++p;
+                        }
+                        break;
+            GO('p', q, void*, void*, (uintptr_t))
+            GO('i', sdword, int, int, )
+            GO('u', dword, uint32_t, uint32_t, )
+            GO('I', sq, int64_t, int64_t, )
+            GO('U', q, uint64_t, uint64_t, )
+            GO('L', q, uint64_t, uint64_t, )
+            GO('l', sq, int64_t, int64_t, )
+            GO('w', sword, int16_t, int, )
+            GO('W', word, uint16_t, int, )
+            GO('c', sbyte, int8_t, int, )
+            GO('C', byte, uint8_t, int, )
+            default:
+                printf_log(LOG_NONE, "Error, unhandled arg %d: '%c' in RunFunctionFmt\n", i, fmt[i]);
+                if(ni<6) emu->regs[nn[ni++]].q[0] = va_arg(va, uint64_t); else {*p = va_arg(va, uint64_t); ++p;}; 
+                break;
+        }
+    }
+    va_end (va);
+
+    uintptr_t oldip = R_RIP;
+    DynaCall(emu, fnc);
+
+    if(oldip==R_RIP) {
+        R_RSP = R_RBP;          // mov rsp, rbp
+        R_RBP = Pop64(emu);     // pop rbp
+    }
+
+    uint64_t ret = R_RAX;
+
+    return ret;
+}
+
+EXPORTDYN
 uint64_t RunSafeFunction(box64context_t *context, uintptr_t fnc, int nargs, ...)
 {
     (void)context;
diff --git a/src/wrapped/wrappedatk.c b/src/wrapped/wrappedatk.c
index d6b71c31..e1a23aef 100755
--- a/src/wrapped/wrappedatk.c
+++ b/src/wrapped/wrappedatk.c
@@ -44,7 +44,7 @@ GO(4)
 static uintptr_t my_AtkEventListenerInit_fct_##A = 0;               \
 static void my_AtkEventListenerInit_##A()                           \
 {                                                                   \
-    RunFunction(my_context, my_AtkEventListenerInit_fct_##A, 0);    \
+    RunFunctionFmt(my_context, my_AtkEventListenerInit_fct_##A, "");\
 }
 SUPER()
 #undef GO
@@ -66,7 +66,7 @@ static void* find_AtkEventListenerInit_Fct(void* fct)
 static uintptr_t my_AtkEventListener_fct_##A = 0;               \
 static void my_AtkEventListener_##A(void* a)                    \
 {                                                               \
-    RunFunction(my_context, my_AtkEventListener_fct_##A, 1, a); \
+    RunFunctionFmt(my_context, my_AtkEventListener_fct_##A, "p", a); \
 }
 SUPER()
 #undef GO
@@ -88,7 +88,7 @@ static void* find_AtkEventListener_Fct(void* fct)
 static uintptr_t my_AtkKeySnoopFunc_fct_##A = 0;                                \
 static int my_AtkKeySnoopFunc_##A(void* a, void* b)                             \
 {                                                                               \
-    return (int)RunFunction(my_context, my_AtkKeySnoopFunc_fct_##A, 2, a, b);   \
+    return (int)RunFunctionFmt(my_context, my_AtkKeySnoopFunc_fct_##A, "pp", a, b);   \
 }
 SUPER()
 #undef GO
@@ -110,7 +110,7 @@ static void* find_AtkKeySnoopFunc_Fct(void* fct)
 static uintptr_t my_GSignalEmissionHook_fct_##A = 0;                                    \
 static int my_GSignalEmissionHook_##A(void* a, uint32_t b, void* c, void* d)            \
 {                                                                                       \
-    return (int)RunFunction(my_context, my_GSignalEmissionHook_fct_##A, 4, a, b, c, d); \
+    return (int)RunFunctionFmt(my_context, my_GSignalEmissionHook_fct_##A, "pupp", a, b, c, d); \
 }
 SUPER()
 #undef GO
diff --git a/src/wrapped/wrappedatspi.c b/src/wrapped/wrappedatspi.c
index dcf9aa1f..59a07cce 100755
--- a/src/wrapped/wrappedatspi.c
+++ b/src/wrapped/wrappedatspi.c
@@ -40,7 +40,7 @@ GO(4)
 static uintptr_t my_GDestroyNotify_fct_##A = 0;                 \
 static void my_GDestroyNotify_##A(void* a)                      \
 {                                                               \
-    RunFunction(my_context, my_GDestroyNotify_fct_##A, 1, a);   \
+    RunFunctionFmt(my_context, my_GDestroyNotify_fct_##A, "p", a);   \
 }
 SUPER()
 #undef GO
@@ -62,7 +62,7 @@ static void* find_GDestroyNotify_Fct(void* fct)
 static uintptr_t my_AtspiEventListenerCB_fct_##A = 0;                   \
 static void my_AtspiEventListenerCB_##A(void* a, void* b)               \
 {                                                                       \
-    RunFunction(my_context, my_AtspiEventListenerCB_fct_##A, 2, a, b);  \
+    RunFunctionFmt(my_context, my_AtspiEventListenerCB_fct_##A, "pp", a, b);  \
 }
 SUPER()
 #undef GO
diff --git a/src/wrapped/wrappedbz2.c b/src/wrapped/wrappedbz2.c
index e3ff920e..bcf1477d 100755
--- a/src/wrapped/wrappedbz2.c
+++ b/src/wrapped/wrappedbz2.c
@@ -37,7 +37,7 @@ GO(4)
 static uintptr_t my_alloc_fct_##A = 0;                                          \
 static void* my_alloc_##A(void* opaque, int m, int n)                           \
 {                                                                               \
-    return (void*)RunFunction(my_context, my_alloc_fct_##A, 3, opaque, m, n);   \
+    return (void*)RunFunctionFmt(my_context, my_alloc_fct_##A, "pii", opaque, m, n);   \
 }
 SUPER()
 #undef GO
@@ -69,7 +69,7 @@ static void* reverse_alloc_Fct(void* fct)
 static uintptr_t my_free_fct_##A = 0;                       \
 static void my_free_##A(void* opaque, void* p)              \
 {                                                           \
-    RunFunction(my_context, my_free_fct_##A, 2, opaque, p); \
+    RunFunctionFmt(my_context, my_free_fct_##A, "pp", opaque, p); \
 }
 SUPER()
 #undef GO
diff --git a/src/wrapped/wrappedcrypto.c b/src/wrapped/wrappedcrypto.c
index 21941bbf..5455f19e 100755
--- a/src/wrapped/wrappedcrypto.c
+++ b/src/wrapped/wrappedcrypto.c
@@ -40,7 +40,7 @@ GO(4)
 static uintptr_t my_ENGINE_ctrl_cb_fct_##A = 0;                                                      \
 static void my_ENGINE_ctrl_cb_##A()                    \
 {                                                                                                   \
-    RunFunction(my_context, my_ENGINE_ctrl_cb_fct_##A, 0);  \
+    RunFunctionFmt(my_context, my_ENGINE_ctrl_cb_fct_##A, "");  \
 }
 SUPER()
 #undef GO
@@ -64,7 +64,7 @@ static void* find_ENGINE_ctrl_cb_Fct(void* fct)
 static uintptr_t my_cmp_fnc_fct_##A = 0;                                \
 static int my_cmp_fnc_##A(void* a, void* b)                             \
 {                                                                       \
-    return (int)RunFunction(my_context, my_cmp_fnc_fct_##A, 2, a, b);   \
+    return (int)RunFunctionFmt(my_context, my_cmp_fnc_fct_##A, "pp", a, b);   \
 }
 SUPER()
 #undef GO
@@ -88,7 +88,7 @@ static void* find_cmp_fnc_Fct(void* fct)
 static uintptr_t my_free_fnc_fct_##A = 0;               \
 static void my_free_fnc_##A(void* p)                    \
 {                                                       \
-    RunFunction(my_context, my_free_fnc_fct_##A, 1, p); \
+    RunFunctionFmt(my_context, my_free_fnc_fct_##A, "p", p); \
 }
 SUPER()
 #undef GO
@@ -112,7 +112,7 @@ static void* find_free_fnc_Fct(void* fct)
 static uintptr_t my_id_func_fct_##A = 0;                                    \
 static unsigned long my_id_func_##A()                                       \
 {                                                                           \
-    return (unsigned long)RunFunction(my_context, my_id_func_fct_##A, 0);   \
+    return (unsigned long)RunFunctionFmt(my_context, my_id_func_fct_##A, "");   \
 }
 SUPER()
 #undef GO
@@ -136,7 +136,7 @@ static void* find_id_func_Fct(void* fct)
 static uintptr_t my_lock_func_fct_##A = 0;                              \
 static void my_lock_func_##A(int mode, int n, void* f, int l)           \
 {                                                                       \
-    RunFunction(my_context, my_lock_func_fct_##A, 4, mode, n, f, l);    \
+    RunFunctionFmt(my_context, my_lock_func_fct_##A, "iipi", mode, n, f, l);    \
 }
 SUPER()
 #undef GO
@@ -160,7 +160,7 @@ static void* find_lock_func_Fct(void* fct)
 static uintptr_t my_passphrase_fct_##A = 0;                                             \
 static int my_passphrase_##A(void* buff, int size, int rw, void* u)                     \
 {                                                                                       \
-    return (int)RunFunction(my_context, my_passphrase_fct_##A, 4, buff, size, rw, u);   \
+    return (int)RunFunctionFmt(my_context, my_passphrase_fct_##A, "piip", buff, size, rw, u);   \
 }
 SUPER()
 #undef GO
@@ -184,7 +184,7 @@ static void* find_passphrase_Fct(void* fct)
 static uintptr_t my_xnew_fct_##A = 0;                           \
 static void* my_xnew_##A()                                      \
 {                                                               \
-    return (void*)RunFunction(my_context, my_xnew_fct_##A, 0);  \
+    return (void*)RunFunctionFmt(my_context, my_xnew_fct_##A, "");  \
 }
 SUPER()
 #undef GO
@@ -208,7 +208,7 @@ static void* find_xnew_Fct(void* fct)
 static uintptr_t my_d2i_fct_##A = 0;                            \
 static void* my_d2i_##A()                                       \
 {                                                               \
-    return (void*)RunFunction(my_context, my_d2i_fct_##A, 0);   \
+    return (void*)RunFunctionFmt(my_context, my_d2i_fct_##A, "");   \
 }
 SUPER()
 #undef GO
@@ -232,7 +232,7 @@ static void* find_d2i_Fct(void* fct)
 static uintptr_t my_i2d_fct_##A = 0;                        \
 static int my_i2d_##A()                                     \
 {                                                           \
-    return (int)RunFunction(my_context, my_i2d_fct_##A, 0); \
+    return (int)RunFunctionFmt(my_context, my_i2d_fct_##A, ""); \
 }
 SUPER()
 #undef GO
@@ -256,7 +256,7 @@ static void* find_i2d_Fct(void* fct)
 static uintptr_t my_pem_password_cb_fct_##A = 0;                                    \
 static int my_pem_password_cb_##A(void* a, int b, int c, void* d)                   \
 {                                                                                   \
-    return (int)RunFunction(my_context, my_pem_password_cb_fct_##A, 4, a, b, c, d); \
+    return (int)RunFunctionFmt(my_context, my_pem_password_cb_fct_##A, "piip", a, b, c, d); \
 }
 SUPER()
 #undef GO
@@ -280,7 +280,7 @@ static void* find_pem_password_cb_Fct(void* fct)
 static uintptr_t my_verify_cb_fct_##A = 0;                              \
 static int my_verify_cb_##A(int a, void* b)                             \
 {                                                                       \
-    return (int)RunFunction(my_context, my_verify_cb_fct_##A, 2, a, b); \
+    return (int)RunFunctionFmt(my_context, my_verify_cb_fct_##A, "ip", a, b); \
 }
 SUPER()
 #undef GO
diff --git a/src/wrapped/wrappedcrypto3.c b/src/wrapped/wrappedcrypto3.c
index 442237a1..296f4cb6 100755
--- a/src/wrapped/wrappedcrypto3.c
+++ b/src/wrapped/wrappedcrypto3.c
@@ -38,7 +38,7 @@ GO(4)
 static uintptr_t my3_ENGINE_ctrl_cb_fct_##A = 0;                                                      \
 static void my3_ENGINE_ctrl_cb_##A()                    \
 {                                                                                                   \
-    RunFunction(my_context, my3_ENGINE_ctrl_cb_fct_##A, 0);  \
+    RunFunctionFmt(my_context, my3_ENGINE_ctrl_cb_fct_##A, "");  \
 }
 SUPER()
 #undef GO
@@ -62,7 +62,7 @@ static void* find_ENGINE_ctrl_cb_Fct(void* fct)
 static uintptr_t my3_cmp_fnc_fct_##A = 0;                                \
 static int my3_cmp_fnc_##A(void* a, void* b)                             \
 {                                                                       \
-    return (int)RunFunction(my_context, my3_cmp_fnc_fct_##A, 2, a, b);   \
+    return (int)RunFunctionFmt(my_context, my3_cmp_fnc_fct_##A, "pp", a, b);   \
 }
 SUPER()
 #undef GO
@@ -86,7 +86,7 @@ static void* find_cmp_fnc_Fct(void* fct)
 static uintptr_t my3_free_fnc_fct_##A = 0;               \
 static void my3_free_fnc_##A(void* p)                    \
 {                                                       \
-    RunFunction(my_context, my3_free_fnc_fct_##A, 1, p); \
+    RunFunctionFmt(my_context, my3_free_fnc_fct_##A, "p", p); \
 }
 SUPER()
 #undef GO
@@ -110,7 +110,7 @@ static void* find_free_fnc_Fct(void* fct)
 static uintptr_t my3_id_func_fct_##A = 0;                                    \
 static unsigned long my3_id_func_##A()                                       \
 {                                                                           \
-    return (unsigned long)RunFunction(my_context, my3_id_func_fct_##A, 0);   \
+    return (unsigned long)RunFunctionFmt(my_context, my3_id_func_fct_##A, "");   \
 }
 SUPER()
 #undef GO
@@ -134,7 +134,7 @@ static void* find_id_func_Fct(void* fct)
 static uintptr_t my3_lock_func_fct_##A = 0;                              \
 static void my3_lock_func_##A(int mode, int n, void* f, int l)           \
 {                                                                       \
-    RunFunction(my_context, my3_lock_func_fct_##A, 4, mode, n, f, l);    \
+    RunFunctionFmt(my_context, my3_lock_func_fct_##A, "iipi", mode, n, f, l);    \
 }
 SUPER()
 #undef GO
@@ -158,7 +158,7 @@ static void* find_lock_func_Fct(void* fct)
 static uintptr_t my3_passphrase_fct_##A = 0;                                             \
 static int my3_passphrase_##A(void* buff, int size, int rw, void* u)                     \
 {                                                                                       \
-    return (int)RunFunction(my_context, my3_passphrase_fct_##A, 4, buff, size, rw, u);   \
+    return (int)RunFunctionFmt(my_context, my3_passphrase_fct_##A, "piip", buff, size, rw, u);   \
 }
 SUPER()
 #undef GO
@@ -182,7 +182,7 @@ static void* find_passphrase_Fct(void* fct)
 static uintptr_t my3_xnew_fct_##A = 0;                           \
 static void* my3_xnew_##A()                                      \
 {                                                               \
-    return (void*)RunFunction(my_context, my3_xnew_fct_##A, 0);  \
+    return (void*)RunFunctionFmt(my_context, my3_xnew_fct_##A, "");  \
 }
 SUPER()
 #undef GO
@@ -206,7 +206,7 @@ static void* find_xnew_Fct(void* fct)
 static uintptr_t my3_d2i_fct_##A = 0;                            \
 static void* my3_d2i_##A()                                       \
 {                                                               \
-    return (void*)RunFunction(my_context, my3_d2i_fct_##A, 0);   \
+    return (void*)RunFunctionFmt(my_context, my3_d2i_fct_##A, "");   \
 }
 SUPER()
 #undef GO
@@ -230,7 +230,7 @@ static void* find_d2i_Fct(void* fct)
 static uintptr_t my3_i2d_fct_##A = 0;                        \
 static int my3_i2d_##A()                                     \
 {                                                           \
-    return (int)RunFunction(my_context, my3_i2d_fct_##A, 0); \
+    return (int)RunFunctionFmt(my_context, my3_i2d_fct_##A, ""); \
 }
 SUPER()
 #undef GO
@@ -254,7 +254,7 @@ static void* find_i2d_Fct(void* fct)
 static uintptr_t my3_pem_password_cb_fct_##A = 0;                                    \
 static int my3_pem_password_cb_##A(void* a, int b, int c, void* d)                   \
 {                                                                                   \
-    return (int)RunFunction(my_context, my3_pem_password_cb_fct_##A, 4, a, b, c, d); \
+    return (int)RunFunctionFmt(my_context, my3_pem_password_cb_fct_##A, "piip", a, b, c, d); \
 }
 SUPER()
 #undef GO
@@ -275,10 +275,10 @@ static void* find_pem_password_cb_Fct(void* fct)
 
 // verify_cb
 #define GO(A)   \
-static uintptr_t my3_verify_cb_fct_##A = 0;                              \
-static int my3_verify_cb_##A(int a, void* b)                             \
-{                                                                       \
-    return (int)RunFunction(my_context, my3_verify_cb_fct_##A, 2, a, b); \
+static uintptr_t my3_verify_cb_fct_##A = 0;                                     \
+static int my3_verify_cb_##A(int a, void* b)                                    \
+{                                                                               \
+    return (int)RunFunctionFmt(my_context, my3_verify_cb_fct_##A, "ip", a, b);  \
 }
 SUPER()
 #undef GO
diff --git a/src/wrapped/wrappedcurl.c b/src/wrapped/wrappedcurl.c
index ceda973b..873990f2 100755
--- a/src/wrapped/wrappedcurl.c
+++ b/src/wrapped/wrappedcurl.c
@@ -346,7 +346,7 @@ typedef enum {
 static uintptr_t my_write_fct_##A = 0;   \
 static size_t my_write_##A(char* ptr, size_t size, size_t nmemb, void* userdata)     \
 {                                       \
-    return (size_t)RunFunction(my_context, my_write_fct_##A, 4, ptr, size, nmemb, userdata);\
+    return (size_t)RunFunctionFmt(my_context, my_write_fct_##A, "pLLp", ptr, size, nmemb, userdata);\
 }
 SUPER()
 #undef GO
@@ -369,7 +369,7 @@ static void* find_write_Fct(void* fct)
 static uintptr_t my_read_fct_##A = 0;   \
 static size_t my_read_##A(char* buffer, size_t size, size_t nitems, void* userdata)     \
 {                                       \
-    return (size_t)RunFunction(my_context, my_read_fct_##A, 4, buffer, size, nitems, userdata);\
+    return (size_t)RunFunctionFmt(my_context, my_read_fct_##A, "pLLp", buffer, size, nitems, userdata);\
 }
 SUPER()
 #undef GO
@@ -392,7 +392,7 @@ static void* find_read_Fct(void* fct)
 static uintptr_t my_ioctl_fct_##A = 0;   \
 static size_t my_ioctl_##A(void* handle, int32_t fnc, void* userdata)     \
 {                                       \
-    return (size_t)RunFunction(my_context, my_ioctl_fct_##A, 3, handle, fnc, userdata);\
+    return (size_t)RunFunctionFmt(my_context, my_ioctl_fct_##A, "pip", handle, fnc, userdata);\
 }
 SUPER()
 #undef GO
@@ -415,7 +415,7 @@ static void* find_ioctl_Fct(void* fct)
 static uintptr_t my_seek_fct_##A = 0;   \
 static int32_t my_seek_##A(void* userdata, int64_t off, int32_t origin)     \
 {                                       \
-    return (int32_t)RunFunction(my_context, my_seek_fct_##A, 4, userdata, (off&0xffffffff), ((off>>32)&0xffffffff), origin);\
+    return (int32_t)RunFunctionFmt(my_context, my_seek_fct_##A, "pIi", userdata, off, origin);\
 }
 SUPER()
 #undef GO
@@ -438,7 +438,7 @@ static void* find_seek_Fct(void* fct)
 static uintptr_t my_header_fct_##A = 0;   \
 static size_t my_header_##A(char* buffer, size_t size, size_t nitems, void* userdata)     \
 {                                       \
-    return (size_t)RunFunction(my_context, my_header_fct_##A, 4, buffer, size, nitems, userdata);\
+    return (size_t)RunFunctionFmt(my_context, my_header_fct_##A, "pLLp", buffer, size, nitems, userdata);\
 }
 SUPER()
 #undef GO
@@ -461,7 +461,7 @@ static void* find_header_Fct(void* fct)
 static uintptr_t my_progress_fct_##A = 0;   \
 static int my_progress_##A(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)     \
 {                                       \
-    return (int)RunFunction(my_context, my_progress_fct_##A, 5, clientp, dltotal, dlnow, ultotal, ulnow);\
+    return (int)RunFunctionFmt(my_context, my_progress_fct_##A, "pdddd", clientp, dltotal, dlnow, ultotal, ulnow);\
 }
 SUPER()
 #undef GO
@@ -484,7 +484,7 @@ static void* find_progress_Fct(void* fct)
 static uintptr_t my_progress_int_fct_##A = 0;   \
 static int my_progress_int_##A(void *clientp, uint64_t dltotal, uint64_t dlnow, uint64_t ultotal, uint64_t ulnow)     \
 {                                       \
-    return (int)RunFunction(my_context, my_progress_int_fct_##A, 5, clientp, dltotal, dlnow, ultotal, ulnow);\
+    return (int)RunFunctionFmt(my_context, my_progress_int_fct_##A, "pUUUU", clientp, dltotal, dlnow, ultotal, ulnow);\
 }
 SUPER()
 #undef GO
@@ -507,7 +507,7 @@ static void* find_progress_int_Fct(void* fct)
 static uintptr_t my_socket_fct_##A = 0;                                         \
 static int my_socket_##A(void *a, int b, int c, void* d, void* e)               \
 {                                                                               \
-    return (int)RunFunction(my_context, my_socket_fct_##A, 5, a, b, c, d, e);   \
+    return (int)RunFunctionFmt(my_context, my_socket_fct_##A, "piipp", a, b, c, d, e);   \
 }
 SUPER()
 #undef GO
@@ -530,7 +530,7 @@ static void* find_socket_Fct(void* fct)
 static uintptr_t my_timer_fct_##A = 0;                                  \
 static int my_timer_##A(void *a, long b, void* c)                       \
 {                                                                       \
-    return (int)RunFunction(my_context, my_timer_fct_##A, 3, a, b, c);  \
+    return (int)RunFunctionFmt(my_context, my_timer_fct_##A, "plp", a, b, c);  \
 }
 SUPER()
 #undef GO
@@ -553,7 +553,7 @@ static void* find_timer_Fct(void* fct)
 static uintptr_t my_push_fct_##A = 0;                                       \
 static int my_push_##A(void *a, void* b, size_t c, void* d, void* e)        \
 {                                                                           \
-    return (int)RunFunction(my_context, my_push_fct_##A, 5, a, b, c, d, e); \
+    return (int)RunFunctionFmt(my_context, my_push_fct_##A, "ppLpp", a, b, c, d, e); \
 }
 SUPER()
 #undef GO
@@ -576,7 +576,7 @@ static void* find_push_Fct(void* fct)
 static uintptr_t my_debug_fct_##A = 0;                                          \
 static int my_debug_##A(void *a, int b, void* c, size_t d, void* e)             \
 {                                                                               \
-    return (int)RunFunction(my_context, my_debug_fct_##A, 5, a, b, c, d, e);    \
+    return (int)RunFunctionFmt(my_context, my_debug_fct_##A, "pipLp", a, b, c, d, e);    \
 }
 SUPER()
 #undef GO
diff --git a/src/wrapped/wrappeddbus.c b/src/wrapped/wrappeddbus.c
index 5f554771..487d0c25 100755
--- a/src/wrapped/wrappeddbus.c
+++ b/src/wrapped/wrappeddbus.c
@@ -38,7 +38,7 @@ GO(3)
 static uintptr_t my_DBusFreeFunction_fct_##A = 0;               \
 static void my_DBusFreeFunction_##A(void* p)                    \
 {                                                               \
-    RunFunction(my_context, my_DBusFreeFunction_fct_##A, 1, p); \
+    RunFunctionFmt(my_context, my_DBusFreeFunction_fct_##A, "p", p); \
 }
 SUPER()
 #undef GO
@@ -60,7 +60,7 @@ static void* find_DBusFreeFunction_Fct(void* fct)
 static uintptr_t my_DBusHandleMessageFunction_fct_##A = 0;                              \
 static int my_DBusHandleMessageFunction_##A(void* a, void* b, void* c)                  \
 {                                                                                       \
-    return RunFunction(my_context, my_DBusHandleMessageFunction_fct_##A, 3, a, b, c);   \
+    return RunFunctionFmt(my_context, my_DBusHandleMessageFunction_fct_##A, "ppp", a, b, c);   \
 }
 SUPER()
 #undef GO
@@ -82,7 +82,7 @@ static void* find_DBusHandleMessageFunction_Fct(void* fct)
 static uintptr_t my_DBusAddTimeoutFunction_fct_##A = 0;                         \
 static int my_DBusAddTimeoutFunction_##A(void* a, void* b)                      \
 {                                                                               \
-    return RunFunction(my_context, my_DBusAddTimeoutFunction_fct_##A, 2, a, b); \
+    return RunFunctionFmt(my_context, my_DBusAddTimeoutFunction_fct_##A, "pp", a, b); \
 }
 SUPER()
 #undef GO
@@ -104,7 +104,7 @@ static void* find_DBusAddTimeoutFunction_Fct(void* fct)
 static uintptr_t my_DBusRemoveTimeoutFunction_fct_##A = 0;                  \
 static void my_DBusRemoveTimeoutFunction_##A(void* a, void* b)              \
 {                                                                           \
-    RunFunction(my_context, my_DBusRemoveTimeoutFunction_fct_##A, 2, a, b); \
+    RunFunctionFmt(my_context, my_DBusRemoveTimeoutFunction_fct_##A, "pp", a, b); \
 }
 SUPER()
 #undef GO
@@ -126,7 +126,7 @@ static void* find_DBusRemoveTimeoutFunction_Fct(void* fct)
 static uintptr_t my_DBusTimeoutToggledFunction_fct_##A = 0;                     \
 static void my_DBusTimeoutToggledFunction_##A(void* a, void* b)                 \
 {                                                                               \
-    RunFunction(my_context, my_DBusTimeoutToggledFunction_fct_##A, 2, a, b);    \
+    RunFunctionFmt(my_context, my_DBusTimeoutToggledFunction_fct_##A, "pp", a, b);    \
 }
 SUPER()
 #undef GO
@@ -148,7 +148,7 @@ static void* find_DBusTimeoutToggledFunction_Fct(void* fct)
 static uintptr_t my_DBusWakeupMainFunction_fct_##A = 0;                 \
 static void my_DBusWakeupMainFunction_##A(void* a)                      \
 {                                                                       \
-    RunFunction(my_context, my_DBusWakeupMainFunction_fct_##A, 1, a);   \
+    RunFunctionFmt(my_context, my_DBusWakeupMainFunction_fct_##A, "p", a);   \
 }
 SUPER()
 #undef GO
@@ -171,7 +171,7 @@ static void* find_DBusWakeupMainFunction_Fct(void* fct)
 static uintptr_t my_DBusPendingCallNotifyFunction_fct_##A = 0;   \
 static void my_DBusPendingCallNotifyFunction_##A(void* pending, void* data)     \
 {                                       \
-    RunFunction(my_context, my_DBusPendingCallNotifyFunction_fct_##A, 2, pending, data);\
+    RunFunctionFmt(my_context, my_DBusPendingCallNotifyFunction_fct_##A, "pp", pending, data);\
 }
 SUPER()
 #undef GO
@@ -194,7 +194,7 @@ static void* findDBusPendingCallNotifyFunctionFct(void* fct)
 static uintptr_t my_DBusDispatchStatusFunction_fct_##A = 0;   \
 static void my_DBusDispatchStatusFunction_##A(void* connection, int new_status, void* data)     \
 {                                       \
-    RunFunction(my_context, my_DBusDispatchStatusFunction_fct_##A, 3, connection, new_status, data);\
+    RunFunctionFmt(my_context, my_DBusDispatchStatusFunction_fct_##A, "pip", connection, new_status, data);\
 }
 SUPER()
 #undef GO
@@ -217,7 +217,7 @@ static void* findDBusDispatchStatusFunctionFct(void* fct)
 static uintptr_t my_DBusAddWatchFunction_fct_##A = 0;   \
 static int my_DBusAddWatchFunction_##A(void* watch, void* data)     \
 {                                       \
-    return (int)RunFunction(my_context, my_DBusAddWatchFunction_fct_##A, 2, watch, data);\
+    return (int)RunFunctionFmt(my_context, my_DBusAddWatchFunction_fct_##A, "pp", watch, data);\
 }
 SUPER()
 #undef GO
@@ -240,7 +240,7 @@ static void* findDBusAddWatchFunctionFct(void* fct)
 static uintptr_t my_DBusRemoveWatchFunction_fct_##A = 0;   \
 static void my_DBusRemoveWatchFunction_##A(void* watch, void* data)     \
 {                                       \
-    RunFunction(my_context, my_DBusRemoveWatchFunction_fct_##A, 2, watch, data);\
+    RunFunctionFmt(my_context, my_DBusRemoveWatchFunction_fct_##A, "pp", watch, data);\
 }
 SUPER()
 #undef GO
@@ -263,7 +263,7 @@ static void* findDBusRemoveWatchFunctionFct(void* fct)
 static uintptr_t my_DBusWatchToggledFunction_fct_##A = 0;   \
 static void my_DBusWatchToggledFunction_##A(void* watch, void* data)     \
 {                                       \
-    RunFunction(my_context, my_DBusWatchToggledFunction_fct_##A, 2, watch, data);\
+    RunFunctionFmt(my_context, my_DBusWatchToggledFunction_fct_##A, "pp", watch, data);\
 }
 SUPER()
 #undef GO
@@ -286,7 +286,7 @@ static void* findDBusWatchToggledFunctionFct(void* fct)
 static uintptr_t my_DBusObjectPathUnregisterFunction_fct_##A = 0;   \
 static void my_DBusObjectPathUnregisterFunction_##A(void* connection, void* data)     \
 {                                       \
-    RunFunction(my_context, my_DBusObjectPathUnregisterFunction_fct_##A, 2, connection, data);\
+    RunFunctionFmt(my_context, my_DBusObjectPathUnregisterFunction_fct_##A, "pp", connection, data);\
 }
 SUPER()
 #undef GO
@@ -309,7 +309,7 @@ static void* findDBusObjectPathUnregisterFunctionFct(void* fct)
 static uintptr_t my_DBusObjectPathMessageFunction_fct_##A = 0;   \
 static void my_DBusObjectPathMessageFunction_##A(void* connection, void* message, void* data)     \
 {                                       \
-    RunFunction(my_context, my_DBusObjectPathMessageFunction_fct_##A, 3, connection, message, data);\
+    RunFunctionFmt(my_context, my_DBusObjectPathMessageFunction_fct_##A, "ppp", connection, message, data);\
 }
 SUPER()
 #undef GO
@@ -332,7 +332,7 @@ static void* findDBusObjectPathMessageFunctionFct(void* fct)
 static uintptr_t my_dbus_internal_pad_fct_##A = 0;   \
 static void my_dbus_internal_pad_##A(void* a, void* b, void* c, void* d)     \
 {                                       \
-    RunFunction(my_context, my_dbus_internal_pad_fct_##A, 4, a, b, c, d);\
+    RunFunctionFmt(my_context, my_dbus_internal_pad_fct_##A, "pppp", a, b, c, d);\
 }
 SUPER()
 #undef GO
@@ -355,7 +355,7 @@ static void* finddbus_internal_padFct(void* fct)
 static uintptr_t my_DBusNewConnectionFunction_fct_##A = 0;                      \
 static void my_DBusNewConnectionFunction_##A(void* a, void* b, void* c)         \
 {                                                                               \
-    RunFunction(my_context, my_DBusNewConnectionFunction_fct_##A, 3, a, b, c);  \
+    RunFunctionFmt(my_context, my_DBusNewConnectionFunction_fct_##A, "pppp", a, b, c);  \
 }
 SUPER()
 #undef GO
diff --git a/src/wrapped/wrappedgobject2.c b/src/wrapped/wrappedgobject2.c
index f9fc35b9..16f4e688 100755
--- a/src/wrapped/wrappedgobject2.c
+++ b/src/wrapped/wrappedgobject2.c
@@ -821,7 +821,7 @@ EXPORT void my_g_signal_emit_valist(x64emu_t* emu, void* inst, uint32_t id, void
     my->g_signal_emit_valist(inst, id, quark, VARARGS);
 }
 
-EXPORT void my_g_signal_emit(x64emu_t* emu, void* inst, uint32_t id, void* quark, x64_va_list_t b)
+EXPORT void my_g_signal_emit(x64emu_t* emu, void* inst, uint32_t id, void* quark, uintptr_t* b)
 {
     CREATE_VALIST_FROM_VAARG(b, emu->scratch, 3);
     my->g_signal_emit_valist(inst, id, quark, VARARGS);
diff --git a/src/wrapped/wrappedpulse.c b/src/wrapped/wrappedpulse.c
index 02233aa0..50bd3a3f 100755
--- a/src/wrapped/wrappedpulse.c
+++ b/src/wrapped/wrappedpulse.c
@@ -919,7 +919,15 @@ static void my_time_set_destroy(void* e, void* cb)
 static void* my_defer_new(void* api, void* cb, void* data)
 {
     uintptr_t b = (uintptr_t)cb;
-    void* fnc = GetNativeFnc((uintptr_t)my_mainloop_ref->defer_new);
+    static void* old_defer_new = NULL;
+    static void* old_fnc = NULL;
+    void* fnc = NULL;
+    if(old_defer_new == my_mainloop_ref->defer_new)
+        fnc = old_fnc;
+    else {
+        old_fnc = fnc = GetNativeFnc((uintptr_t)my_mainloop_ref->defer_new);
+        old_defer_new = my_mainloop_ref->defer_new;
+    }
     if(fnc) {
         if(api==my_mainloop_ref) api=my_mainloop_orig;    // need native version
         if(fnc==native_defer_new) fnc=my_mainloop_native.defer_new;