about summary refs log tree commit diff stats
path: root/src/wrapped32/wrappedmount.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2025-04-12 18:34:03 +0200
committerptitSeb <sebastien.chev@gmail.com>2025-04-12 18:34:03 +0200
commita89748e9e5e2ea979ea9fb0c181040dc4096dadb (patch)
treec06e4df1220f7452ff11523c72a3ef0be30d3e4e /src/wrapped32/wrappedmount.c
parent91f9a58b3058732259e8a86d830493ad87fa9ff5 (diff)
downloadbox64-a89748e9e5e2ea979ea9fb0c181040dc4096dadb.tar.gz
box64-a89748e9e5e2ea979ea9fb0c181040dc4096dadb.zip
[BOX32][WRAPPER] Added wrapped libmount and libblkid, plus 1 new wrapped function on libgbm
Diffstat (limited to 'src/wrapped32/wrappedmount.c')
-rw-r--r--src/wrapped32/wrappedmount.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/wrapped32/wrappedmount.c b/src/wrapped32/wrappedmount.c
new file mode 100644
index 00000000..543e5604
--- /dev/null
+++ b/src/wrapped32/wrappedmount.c
@@ -0,0 +1,115 @@
+#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 "wrapper32.h"
+#include "bridge.h"
+#include "librarian/library_private.h"
+#include "x64emu.h"
+#include "emu/x64emu_private.h"
+#include "callback.h"
+#include "librarian.h"
+#include "box32context.h"
+#include "emu/x64emu_private.h"
+#include "converter32.h"
+
+static const char* mountName = "libmount.so.1";
+#define LIBNAME mount
+
+#include "generated/wrappedmounttypes32.h"
+
+#include "wrappercallback32.h"
+
+typedef struct my_libmnt_optmap_s
+{
+        /*const*/ char *name;
+        int             id;
+        int             mask;
+} my_libmnt_optmap_t;
+typedef struct my_libmnt_optmap_32_s
+{
+        ptr_t           name;   //const char      *
+        int             id;
+        int             mask;
+} my_libmnt_optmap_32_t;
+
+void convert_libmnt_optmap_32(void* d, void* s)
+{
+    if(!s || !d) return;
+    my_libmnt_optmap_t* src = s;
+    my_libmnt_optmap_32_t* dst = d;
+    dst->name = to_ptrv(src->name);
+    dst->id = src->id;
+    dst->mask = src->mask;
+}
+void convert_libmnt_optmap_64(void* d, void* s)
+{
+    if(!s || !d) return;
+    my_libmnt_optmap_32_t* src = s;
+    my_libmnt_optmap_t* dst = d;
+    dst->mask = src->mask;
+    dst->id = src->id;
+    dst->name = from_ptrv(src->name);
+}
+
+#define N 4
+static my_libmnt_optmap_t* optmap_64[N] = {0};
+static my_libmnt_optmap_32_t optmap_32[N] = {0};
+my_libmnt_optmap_32_t* shrink_libmnt_optmap(void* a)
+{
+    if(!a) return NULL;
+    for(int i; i<N; ++i) {
+        if(optmap_64[i]==a)
+            return &optmap_32[i];
+    }
+    // look for free slot
+    for(int i; i<N; ++i)
+        if(!optmap_64[i]) {
+            optmap_64[i] = a;
+            convert_libmnt_optmap_32(&optmap_32[i], a);
+            return &optmap_32[i];
+        }
+    // no more slot... use a local static and print a warning
+    static int warned = 0;
+    if(!warned) {
+        printf_log(LOG_INFO, "Warning: no more slot for libmnt_optmap\n");
+        warned = 1;
+    }
+    static my_libmnt_optmap_32_t ret = {0};
+    convert_libmnt_optmap_32(&ret, a);
+    return &ret;
+}
+my_libmnt_optmap_t* enlarge_libmnt_optmap(void* a)
+{
+    if(!a) return NULL;
+    for(int i; i<N; ++i) {
+        if(&optmap_32[i]==a)
+            return optmap_64[i];
+    }
+    static int warned = 0;
+    if(!warned) {
+        printf_log(LOG_INFO, "Warning: 32bit version of libmnt_optmap not found\n");
+        warned = 1;
+    }
+    static my_libmnt_optmap_t ret = {0};
+    convert_libmnt_optmap_64(&ret, a);
+    return &ret;
+}
+
+EXPORT void* my32_mnt_get_builtin_optmap(x64emu_t* emu, int a)
+{
+    return shrink_libmnt_optmap(my->mnt_get_builtin_optmap(a));
+}
+
+EXPORT int my32_mnt_optstr_get_flags(x64emu_t* emu, void* optstr, void* flag, void* map)
+{
+    return my->mnt_optstr_get_flags(optstr, flag, enlarge_libmnt_optmap(map));
+}
+
+#include "wrappedlib_init32.h"
+