about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2025-05-20 16:40:04 +0200
committerptitSeb <sebastien.chev@gmail.com>2025-05-20 16:40:04 +0200
commitb13811259ae3e71efc5d3f098ce7bdd0b0d66269 (patch)
treebafb17eaf4d4d1518d00c2fdea9a9a45a1e79ebd /src
parenta7f40416041da33091409b27d8b17292eb5039a9 (diff)
downloadbox64-b13811259ae3e71efc5d3f098ce7bdd0b0d66269.tar.gz
box64-b13811259ae3e71efc5d3f098ce7bdd0b0d66269.zip
[BOX32][WRAPPER] Try to fix some of the issues with wrapped libdbus-1 and arrays/strings
Diffstat (limited to 'src')
-rw-r--r--src/wrapped32/generated/functions_list.txt2
-rw-r--r--src/wrapped32/generated/wrappeddbustypes32.h2
-rw-r--r--src/wrapped32/wrappeddbus.c82
-rw-r--r--src/wrapped32/wrappeddbus_private.h2
4 files changed, 79 insertions, 9 deletions
diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt
index 8fbaf9d0..4c79e3ec 100644
--- a/src/wrapped32/generated/functions_list.txt
+++ b/src/wrapped32/generated/functions_list.txt
@@ -2149,6 +2149,8 @@ wrappedcairo:
   - cairo_xlib_surface_create_for_bitmap
 wrappedcrashhandler:
 wrappeddbus:
+- vFp:
+  - dbus_free_string_array
 - vFppp:
   - dbus_connection_remove_filter
   - dbus_timeout_set_data
diff --git a/src/wrapped32/generated/wrappeddbustypes32.h b/src/wrapped32/generated/wrappeddbustypes32.h
index c0df7cdf..e9f489cb 100644
--- a/src/wrapped32/generated/wrappeddbustypes32.h
+++ b/src/wrapped32/generated/wrappeddbustypes32.h
@@ -11,6 +11,7 @@
 #define ADDED_FUNCTIONS() 
 #endif
 
+typedef void (*vFp_t)(void*);
 typedef void (*vFppp_t)(void*, void*, void*);
 typedef uint32_t (*uFpip_t)(void*, int32_t, void*);
 typedef uint32_t (*uFpiV_t)(void*, int32_t, ...);
@@ -24,6 +25,7 @@ typedef uint32_t (*uFppppbppuuuuup__t)(void*, void*, void*, void*, struct_ppuuuu
 typedef uint32_t (*uFpppppp_t)(void*, void*, void*, void*, void*, void*);
 
 #define SUPER() ADDED_FUNCTIONS() \
+	GO(dbus_free_string_array, vFp_t) \
 	GO(dbus_connection_remove_filter, vFppp_t) \
 	GO(dbus_timeout_set_data, vFppp_t) \
 	GO(dbus_watch_set_data, vFppp_t) \
diff --git a/src/wrapped32/wrappeddbus.c b/src/wrapped32/wrappeddbus.c
index 09aa100c..4ee0cd27 100644
--- a/src/wrapped32/wrappeddbus.c
+++ b/src/wrapped32/wrappeddbus.c
@@ -411,6 +411,28 @@ EXPORT void my32_dbus_connection_remove_filter(x64emu_t* emu, void* connection,
     my->dbus_connection_remove_filter(connection, find_DBusHandleMessageFunction_Fct(fnc), data);
 }
 
+static void* inplace_shrink_arraystring(void* a, int n)
+{
+    if(!a || !n) return a;
+    void** src = a;
+    ptr_t* dst = a;
+    for(int i=0; i<=n; ++i) // convert last NULL value
+        dst[i] = to_ptrv(src[i]);
+}
+
+static void* inplace_expand_arraystring(void* a)
+{
+    if(!a) return a;
+    void** dst = a;
+    ptr_t* src = a;
+    // need to find n first
+    int n = 0;
+    while(src[n]) ++n;
+    for(int i=n; i>=0; --i) //expand, including final NULL
+        dst[i] = from_ptrv(src[i]);
+    return a;
+}
+
 EXPORT int my32_dbus_message_get_args(x64emu_t* emu, void* message, void* e, int arg, ptr_t* V)
 {
     (void)emu;
@@ -419,8 +441,9 @@ EXPORT int my32_dbus_message_get_args(x64emu_t* emu, void* message, void* e, int
     int nstr = 0;
     // count
     while(type) {
-        if(type == ((int)'s')) nstr++;
+        if(type == ((int)'a')) {idx++; nstr++;}
         type = V[idx*2+1];
+        nstr++;
         idx++;
     }
     int count = idx*2;
@@ -431,13 +454,16 @@ EXPORT int my32_dbus_message_get_args(x64emu_t* emu, void* message, void* e, int
     nstr = 0;
     // prepare the array
     while(type) {
-        void* value = from_ptrv(V[idx*2]);
-        if(type == ((int)'s')) {
-            array[count + nstr] = from_ptrv(*(ptr_t*)value);
-            array[idx*2+0] = &array[count + nstr];
+        if(type == ((int)'a')) {
+            array[idx*2+0] = from_ptrv(V[idx*2+0]);
+            array[idx*2+1] = &array[count + nstr];
             ++nstr;
+            array[idx*2+2] = &array[count + nstr];   // size of the array
+            ++nstr;
+            ++idx;
         } else {
-            array[idx*2+0] = value;
+            array[idx*2+0] = &array[count+nstr];
+            ++nstr;
         }
         //go next
         type = V[idx*2+1];
@@ -453,7 +479,15 @@ EXPORT int my32_dbus_message_get_args(x64emu_t* emu, void* message, void* e, int
         nstr = 0;
         // done
         while(type) {
-            if(type == ((int)'s')) {
+            if(type == ((int)'a')) {
+                int subtype = V[idx*2];
+                void* value = array[count + nstr++];
+                V[idx*2] = to_ptrv(value);
+                int* n = array[count + nstr++];
+                V[idx*2] = to_ptrv(n);
+                if(subtype==(int)'s') inplace_shrink_arraystring(value, *n);
+                ++idx;
+            } else {
                 void* value = array[count + nstr++];
                 V[idx*2] = to_ptrv(value);
             }
@@ -475,6 +509,15 @@ EXPORT int my32_dbus_message_append_args(x64emu_t* emu, void* message, int arg,
     // count
     while(type) {
         if(type == ((int)'s')) nstr++;
+        else if(type == ((int)'a')) {
+            nstr++; 
+            type = V[idx*2+0];
+            if(type == ((int)'s')) {
+                int n = V[idx*2+2];
+                nstr += n;
+            }
+            idx++;
+        }
         type = V[idx*2+1];
         idx++;
     }
@@ -487,9 +530,27 @@ EXPORT int my32_dbus_message_append_args(x64emu_t* emu, void* message, int arg,
     // fill the array
     while(type) {
         void* value = from_ptrv(V[idx*2]);
-        if(type == ((int)'s')) {
+        if((type == (int)'s')) {
             array[count + nstr] = from_ptrv(*(ptr_t*)value);
             array[idx*2+0] = &array[count + nstr++];
+        } else if(type == ((int)'a')) {
+            array[idx*2+0] = value;
+            int subtype = (int)(uintptr_t)value;
+            value = from_ptrv(V[idx*2+1]);  // array pointer
+            array[count + nstr] = from_ptrv(*(ptr_t*)value);
+            array[idx*2+1] = &array[count + nstr];
+            ++nstr;
+            int n = V[idx*2+2];
+            array[idx*2+2] = from_ptrv(n); // size of the array
+            if(subtype==(int)'s') {
+                // expand string array
+                ptr_t* pvalue = value;
+                for(int i=0; i<n; ++i)
+                    array[count + nstr + i] = from_ptrv(pvalue[i]);
+                array[count + nstr -1] = &array[count + nstr];
+                nstr += n;
+            }
+            ++idx;
         } else {
             array[idx*2+0] = value;
         }
@@ -653,4 +714,9 @@ printf_log(LOG_INFO, "  string is %p\n", str);
     return my->dbus_message_iter_append_basic(iter, type, &value_l);
 }
 
+EXPORT void my32_dbus_free_string_array(x64emu_t* emu, void* l)
+{
+    my->dbus_free_string_array(inplace_expand_arraystring(l));
+}
+
 #include "wrappedlib_init32.h"
diff --git a/src/wrapped32/wrappeddbus_private.h b/src/wrapped32/wrappeddbus_private.h
index 291d9cdf..4dc0a002 100644
--- a/src/wrapped32/wrappeddbus_private.h
+++ b/src/wrapped32/wrappeddbus_private.h
@@ -85,7 +85,7 @@ GO(dbus_error_has_name, uFbppuuuuup_p)
 GO(dbus_error_init, vFbppuuuuup_)
 GO(dbus_error_is_set, uFbppuuuuup_)
 GO(dbus_free, vFp)
-GO(dbus_free_string_array, vFbp_)
+GOM(dbus_free_string_array, vFEp)
 GO(dbus_get_local_machine_id, pFv)
 GO(dbus_get_version, vFppp)
 //GO(dbus_internal_do_not_use_create_uuid,