about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2025-04-12 16:11:41 +0200
committerptitSeb <sebastien.chev@gmail.com>2025-04-12 16:11:41 +0200
commite678e8428ba868e3a9e211beaaee79fa60fb2d30 (patch)
tree8a07d3d232b23bb6ee998ba9d2ad326f0ad98a84 /src
parent20377b992768be46a9deb526de748bc3b5619fda (diff)
downloadbox64-e678e8428ba868e3a9e211beaaee79fa60fb2d30.tar.gz
box64-e678e8428ba868e3a9e211beaaee79fa60fb2d30.zip
[BOX32][WRAPPER] Added a few more wrapped functions to libdrm
Diffstat (limited to 'src')
-rw-r--r--src/wrapped32/generated/functions_list.txt9
-rw-r--r--src/wrapped32/generated/wrappedlibdrmtypes32.h10
-rw-r--r--src/wrapped32/generated/wrapper32.c2
-rw-r--r--src/wrapped32/generated/wrapper32.h1
-rw-r--r--src/wrapped32/wrappedlibdrm.c317
-rw-r--r--src/wrapped32/wrappedlibdrm_private.h12
6 files changed, 344 insertions, 7 deletions
diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt
index 7fc7a475..eb6b7ec6 100644
--- a/src/wrapped32/generated/functions_list.txt
+++ b/src/wrapped32/generated/functions_list.txt
@@ -666,6 +666,7 @@
 #() LFXpi -> LFXpi
 #() LFXpp -> LFXpp
 #() pFEii -> pFEii
+#() pFEiu -> pFEiu
 #() pEEip -> pEEip
 #() pFEiV -> pFEiV
 #() pEEpi -> pEEpi
@@ -2463,8 +2464,16 @@ wrappedlibdl:
 wrappedlibdrm:
 - vFp:
   - drmFreeVersion
+  - drmModeFreeConnector
+  - drmModeFreeResources
 - pFi:
   - drmGetVersion
+  - drmModeGetResources
+- iFip:
+  - drmHandleEvent
+- pFiu:
+  - drmModeGetConnector
+  - drmModeGetConnectorCurrent
 wrappedlibegl:
 - pFp:
   - eglGetProcAddress
diff --git a/src/wrapped32/generated/wrappedlibdrmtypes32.h b/src/wrapped32/generated/wrappedlibdrmtypes32.h
index 3daa9521..28ede341 100644
--- a/src/wrapped32/generated/wrappedlibdrmtypes32.h
+++ b/src/wrapped32/generated/wrappedlibdrmtypes32.h
@@ -13,9 +13,17 @@
 
 typedef void (*vFp_t)(void*);
 typedef void* (*pFi_t)(int32_t);
+typedef int32_t (*iFip_t)(int32_t, void*);
+typedef void* (*pFiu_t)(int32_t, uint32_t);
 
 #define SUPER() ADDED_FUNCTIONS() \
 	GO(drmFreeVersion, vFp_t) \
-	GO(drmGetVersion, pFi_t)
+	GO(drmModeFreeConnector, vFp_t) \
+	GO(drmModeFreeResources, vFp_t) \
+	GO(drmGetVersion, pFi_t) \
+	GO(drmModeGetResources, pFi_t) \
+	GO(drmHandleEvent, iFip_t) \
+	GO(drmModeGetConnector, pFiu_t) \
+	GO(drmModeGetConnectorCurrent, pFiu_t)
 
 #endif // __wrappedlibdrmTYPES32_H_
diff --git a/src/wrapped32/generated/wrapper32.c b/src/wrapped32/generated/wrapper32.c
index feaf91e7..1bea7043 100644
--- a/src/wrapped32/generated/wrapper32.c
+++ b/src/wrapped32/generated/wrapper32.c
@@ -760,6 +760,7 @@ typedef uintptr_t (*LFXLC_t)(void*, uintptr_t, uint8_t);
 typedef uintptr_t (*LFXpi_t)(void*, void*, int32_t);
 typedef uintptr_t (*LFXpp_t)(void*, void*, void*);
 typedef void* (*pFEii_t)(x64emu_t*, int32_t, int32_t);
+typedef void* (*pFEiu_t)(x64emu_t*, int32_t, uint32_t);
 typedef void* (*pEEip_t)(x64emu_t*, int32_t, void*);
 typedef void* (*pFEiV_t)(x64emu_t*, int32_t, void*);
 typedef void* (*pEEpi_t)(x64emu_t*, void*, int32_t);
@@ -2820,6 +2821,7 @@ void LFXLC_32(x64emu_t *emu, uintptr_t fcn) { LFXLC_t fn = (LFXLC_t)fcn; R_EAX =
 void LFXpi_32(x64emu_t *emu, uintptr_t fcn) { LFXpi_t fn = (LFXpi_t)fcn; R_EAX = to_ulong(fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12))); }
 void LFXpp_32(x64emu_t *emu, uintptr_t fcn) { LFXpp_t fn = (LFXpp_t)fcn; R_EAX = to_ulong(fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12))); }
 void pFEii_32(x64emu_t *emu, uintptr_t fcn) { pFEii_t fn = (pFEii_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8))); }
+void pFEiu_32(x64emu_t *emu, uintptr_t fcn) { pFEiu_t fn = (pFEiu_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8))); }
 void pEEip_32(x64emu_t *emu, uintptr_t fcn) { pEEip_t fn = (pEEip_t)fcn; errno = emu->libc_err; R_EAX = to_ptrv(fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8))); emu->libc_err = errno; }
 void pFEiV_32(x64emu_t *emu, uintptr_t fcn) { pFEiV_t fn = (pFEiV_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptrv(R_ESP + 8))); }
 void pEEpi_32(x64emu_t *emu, uintptr_t fcn) { pEEpi_t fn = (pEEpi_t)fcn; errno = emu->libc_err; R_EAX = to_ptrv(fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8))); emu->libc_err = errno; }
diff --git a/src/wrapped32/generated/wrapper32.h b/src/wrapped32/generated/wrapper32.h
index c885116d..8c4e2be7 100644
--- a/src/wrapped32/generated/wrapper32.h
+++ b/src/wrapped32/generated/wrapper32.h
@@ -707,6 +707,7 @@ void LFXLC_32(x64emu_t *emu, uintptr_t fnc);
 void LFXpi_32(x64emu_t *emu, uintptr_t fnc);
 void LFXpp_32(x64emu_t *emu, uintptr_t fnc);
 void pFEii_32(x64emu_t *emu, uintptr_t fnc);
+void pFEiu_32(x64emu_t *emu, uintptr_t fnc);
 void pEEip_32(x64emu_t *emu, uintptr_t fnc);
 void pFEiV_32(x64emu_t *emu, uintptr_t fnc);
 void pEEpi_32(x64emu_t *emu, uintptr_t fnc);
diff --git a/src/wrapped32/wrappedlibdrm.c b/src/wrapped32/wrappedlibdrm.c
index f6f5331b..570d6d0d 100644
--- a/src/wrapped32/wrappedlibdrm.c
+++ b/src/wrapped32/wrappedlibdrm.c
@@ -27,6 +27,106 @@ static const char* libdrmName = "libdrm.so.2";
 
 #include "wrappercallback32.h"
 
+#define SUPER() \
+GO(0)   \
+GO(1)   \
+GO(2)   \
+GO(3)   \
+GO(4)
+
+// vblank_handler
+#define GO(A)                                                                           \
+static uintptr_t my32_vblank_handler_fct_##A = 0;                                       \
+static void my32_vblank_handler_##A(int a, uint32_t b, uint32_t c, uint32_t d, void* e) \
+{                                                                                       \
+    RunFunctionFmt(my32_vblank_handler_fct_##A, "iuuup", a, b, c, d, e);                \
+}
+SUPER()
+#undef GO
+static void* find_vblank_handler_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my32_vblank_handler_fct_##A == (uintptr_t)fct) return my32_vblank_handler_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my32_vblank_handler_fct_##A == 0) {my32_vblank_handler_fct_##A = (uintptr_t)fct; return my32_vblank_handler_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for libdrm 32bits vblank_handler callback\n");
+    return NULL;
+}
+
+// page_flip_handler
+#define GO(A)                                                                               \
+static uintptr_t my32_page_flip_handler_fct_##A = 0;                                        \
+static void my32_page_flip_handler_##A(int a, uint32_t b, uint32_t c, uint32_t d, void* e)  \
+{                                                                                           \
+    RunFunctionFmt(my32_page_flip_handler_fct_##A, "iuuup", a, b, c, d, e);                 \
+}
+SUPER()
+#undef GO
+static void* find_page_flip_handler_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my32_page_flip_handler_fct_##A == (uintptr_t)fct) return my32_page_flip_handler_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my32_page_flip_handler_fct_##A == 0) {my32_page_flip_handler_fct_##A = (uintptr_t)fct; return my32_page_flip_handler_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for libdrm 32bits page_flip_handler callback\n");
+    return NULL;
+}
+
+// page_flip_handler2
+#define GO(A)                                                                                           \
+static uintptr_t my32_page_flip_handler2_fct_##A = 0;                                                   \
+static void my32_page_flip_handler2_##A(int a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, void* f) \
+{                                                                                                       \
+    RunFunctionFmt(my32_page_flip_handler2_fct_##A, "iuuuup", a, b, c, d, e, f);                        \
+}
+SUPER()
+#undef GO
+static void* find_page_flip_handler2_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my32_page_flip_handler2_fct_##A == (uintptr_t)fct) return my32_page_flip_handler2_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my32_page_flip_handler2_fct_##A == 0) {my32_page_flip_handler2_fct_##A = (uintptr_t)fct; return my32_page_flip_handler2_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for libdrm 32bits page_flip_handler2 callback\n");
+    return NULL;
+}
+
+// sequence_handler
+#define GO(A)                                                                       \
+static uintptr_t my32_sequence_handler_fct_##A = 0;                                 \
+static void my32_sequence_handler_##A(int a, uint64_t b, uint64_t c, uint64_t d)    \
+{                                                                                   \
+    RunFunctionFmt(my32_sequence_handler_fct_##A, "iUUU", a, b, c, d);              \
+}
+SUPER()
+#undef GO
+static void* find_sequence_handler_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my32_sequence_handler_fct_##A == (uintptr_t)fct) return my32_sequence_handler_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my32_sequence_handler_fct_##A == 0) {my32_sequence_handler_fct_##A = (uintptr_t)fct; return my32_sequence_handler_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for libdrm 32bits sequence_handler callback\n");
+    return NULL;
+}
+#undef SUPER
+
 //EXPORT void my32_drmMsg(x64emu_t* emu, void* fmt, void* b) {
 //    myStackAlign(emu, (const char*)fmt, b, emu->scratch, R_EAX, 1);
 //    PREPARE_VALIST;
@@ -94,6 +194,185 @@ void* inplace_drmVersion_enlarge(void* a)
     return a;
 }
 
+typedef struct my_drmModeConnector_s {
+    uint32_t connector_id;
+    uint32_t encoder_id;
+    uint32_t connector_type;
+    uint32_t connector_type_id;
+    uint32_t connection;
+    uint32_t mmWidth, mmHeight;
+    uint32_t subpixel;
+    int count_modes;
+    void* modes;    //drmModeModeInfoPtr doesn't need conversion
+    int count_props;
+    uint32_t *props;
+    uint64_t *prop_values;
+    int count_encoders;
+    uint32_t *encoders;
+} my_drmModeConnector_t;
+typedef struct my_drmModeConnector_32_s {
+    uint32_t connector_id;
+    uint32_t encoder_id;
+    uint32_t connector_type;
+    uint32_t connector_type_id;
+    uint32_t connection;
+    uint32_t mmWidth, mmHeight;
+    uint32_t subpixel;
+    int count_modes;
+    ptr_t modes;    //drmModeModeInfoPtr doesn't need conversion
+    int count_props;
+    ptr_t props;    //uint32_t *
+    ptr_t prop_values;  //uint64_t *
+    int count_encoders;
+    ptr_t encoders; //uint32_t *
+} my_drmModeConnector_32_t;
+
+void* inplace_drmModeConnector_shrink(void* a)
+{
+    if(a) {
+        my_drmModeConnector_t* src = a;
+        my_drmModeConnector_32_t* dst = a;
+        dst->connector_id = src->connector_id;
+        dst->encoder_id = src->encoder_id;
+        dst->connector_type = src->connector_type;
+        dst->connector_type_id = src->connector_type_id;
+        dst->connection = src->connection;
+        dst->mmWidth = src->mmWidth;
+        dst->mmHeight = src->mmHeight;
+        dst->subpixel = src->subpixel;
+        dst->count_modes = src->count_modes;
+        dst->modes = to_ptrv(src->modes);
+        dst->count_props = src->count_props;
+        dst->props = to_ptrv(src->props);
+        dst->prop_values = to_ptrv(src->prop_values);
+        dst->count_encoders = src->count_encoders;
+        dst->encoders = to_ptrv(src->encoders);
+    }
+    return a;
+}
+void* inplace_drmModeConnector_enlarge(void* a)
+{
+    if(a) {
+        my_drmModeConnector_t* dst = a;
+        my_drmModeConnector_32_t* src = a;
+        dst->encoders = from_ptrv(src->encoders);
+        dst->count_encoders = src->count_encoders;
+        dst->prop_values = from_ptrv(src->prop_values);
+        dst->props = from_ptrv(src->props);
+        dst->count_props = src->count_props;
+        dst->modes = from_ptrv(src->modes);
+        dst->count_modes = src->count_modes;
+        dst->subpixel = src->subpixel;
+        dst->mmHeight = src->mmHeight;
+        dst->mmWidth = src->mmWidth;
+        dst->connection = src->connection;
+        dst->connector_type_id = src->connector_type_id;
+        dst->connector_type = src->connector_type;
+        dst->encoder_id = src->encoder_id;
+        dst->connector_id = src->connector_id;
+    }
+    return a;
+}
+
+typedef struct my_drmModeRes_s {
+    int count_fbs;
+    uint32_t *fbs;
+    int count_crtcs;
+    uint32_t *crtcs;
+    int count_connectors;
+    uint32_t *connectors;
+    int count_encoders;
+    uint32_t *encoders;
+    uint32_t min_width, max_width;
+    uint32_t min_height, max_height;
+} my_drmModeRes_t;
+typedef struct my_drmModeRes_32_s {
+    int count_fbs;
+    ptr_t fbs;  //uint32_t *
+    int count_crtcs;
+    ptr_t crtcs;    //uint32_t *
+    int count_connectors;
+    ptr_t connectors;   //uint32_t *
+    int count_encoders;
+    ptr_t encoders; //uint32_t *
+    uint32_t min_width, max_width;
+    uint32_t min_height, max_height;
+} my_drmModeRes_32_t;
+
+void* inplace_drmModeRes_shrink(void* a)
+{
+    if(a) {
+        my_drmModeRes_t* src = a;
+        my_drmModeRes_32_t* dst = a;
+        dst->count_fbs = src->count_fbs;
+        dst->fbs = to_ptrv(src->fbs);
+        dst->count_crtcs = src->count_crtcs;
+        dst->crtcs = to_ptrv(src->crtcs);
+        dst->count_connectors = src->count_connectors;
+        dst->connectors = to_ptrv(src->connectors);
+        dst->count_encoders = src->count_encoders;
+        dst->encoders = to_ptrv(src->encoders);
+        dst->min_width = src->min_width;
+        dst->max_width = src->max_width;
+        dst->min_height = src->min_height;
+        dst->max_height = src->max_height;
+    }
+    return a;
+}
+void* inplace_drmModeRes_enlarge(void* a)
+{
+    if(a) {
+        my_drmModeRes_t* dst = a;
+        my_drmModeRes_32_t* src = a;
+        dst->max_height = src->max_height;
+        dst->min_height = src->min_height;
+        dst->max_width = src->max_width;
+        dst->min_width = src->min_width;
+        dst->encoders = from_ptrv(src->encoders);
+        dst->count_encoders = src->count_encoders;
+        dst->connectors = from_ptrv(src->connectors);
+        dst->count_connectors = src->count_connectors;
+        dst->crtcs = from_ptrv(src->crtcs);
+        dst->count_crtcs = src->count_crtcs;
+        dst->fbs = from_ptrv(src->fbs);
+        dst->count_fbs = src->count_fbs;
+    }
+    return a;
+}
+
+typedef struct my_drmEventContext_s
+{
+    int version;
+    void (*vblank_handler)(int fd,
+                           unsigned int sequence, 
+                           unsigned int tv_sec,
+                           unsigned int tv_usec,
+                           void *user_data);
+    void (*page_flip_handler)(int fd,
+                              unsigned int sequence,
+                              unsigned int tv_sec,
+                              unsigned int tv_usec,
+                              void *user_data);
+    void (*page_flip_handler2)(int fd,
+                               unsigned int sequence,
+                               unsigned int tv_sec,
+                               unsigned int tv_usec,
+                               unsigned int crtc_id,
+                               void *user_data);
+    void (*sequence_handler)(int fd,
+                             uint64_t sequence,
+                             uint64_t ns,
+                             uint64_t user_data);
+} my_drmEventContext_t;
+typedef struct my_drmEventContext_32_s
+{
+    int version;
+    ptr_t vblank_handler;
+    ptr_t page_flip_handler;
+    ptr_t page_flip_handler2;
+    ptr_t sequence_handler;
+} my_drmEventContext_32_t;
+
 EXPORT void* my32_drmGetVersion(x64emu_t* emu, int fd)
 {
     return inplace_drmVersion_shrink(my->drmGetVersion(fd));
@@ -104,4 +383,42 @@ EXPORT void my32_drmFreeVersion(x64emu_t* emu, void* v)
     my->drmFreeVersion(inplace_drmVersion_enlarge(v));
 }
 
+EXPORT void* my32_drmModeGetConnector(x64emu_t* emu, int fd, uint32_t id)
+{
+    return inplace_drmModeConnector_shrink(my->drmModeGetConnector(fd, id));
+}
+
+EXPORT void* my32_drmModeGetConnectorCurrent(x64emu_t* emu, int fd, uint32_t id)
+{
+    return inplace_drmModeConnector_shrink(my->drmModeGetConnectorCurrent(fd, id));
+}
+
+EXPORT void my32_drmModeFreeConnector(void* v)
+{
+    my->drmModeFreeConnector(inplace_drmModeConnector_enlarge(v));
+}
+
+EXPORT void my32_drmModeFreeResources(void* v)
+{
+    my->drmModeFreeResources(inplace_drmModeRes_enlarge(v));
+}
+
+EXPORT void* my32_drmModeGetResources(int fd)
+{
+    return inplace_drmModeRes_shrink(my->drmModeGetResources(fd));
+}
+
+EXPORT int my32_drmHandleEvent(x64emu_t* emu, int fd, my_drmEventContext_32_t* event)
+{
+    my_drmEventContext_t ctx = {0};
+    if(event) {
+        ctx.version = event->version;
+        ctx.vblank_handler = find_vblank_handler_Fct(from_ptrv(event->vblank_handler));
+        ctx.page_flip_handler = find_page_flip_handler_Fct(from_ptrv(event->page_flip_handler));
+        ctx.page_flip_handler2 = find_page_flip_handler2_Fct(from_ptrv(event->page_flip_handler2));
+        ctx.sequence_handler = find_sequence_handler_Fct(from_ptrv(event->sequence_handler));
+    }
+    return my->drmHandleEvent(fd, event?(&ctx):NULL);
+}
+
 #include "wrappedlib_init32.h"
diff --git a/src/wrapped32/wrappedlibdrm_private.h b/src/wrapped32/wrappedlibdrm_private.h
index c56e0c4c..17caa003 100644
--- a/src/wrapped32/wrappedlibdrm_private.h
+++ b/src/wrapped32/wrappedlibdrm_private.h
@@ -78,7 +78,7 @@ GO(drmGetRenderDeviceNameFromFd, pFi)
 GO(drmGetReservedContextList, pFip)
 //GO(drmGetStats, 
 GOM(drmGetVersion, pFEi)
-//GOM(drmHandleEvent, iFEibipppp_)
+GOM(drmHandleEvent, iFEip)
 GO(drmHashCreate, pFv)
 GO(drmHashDelete, iFpL)
 GO(drmHashDestroy, iFp)
@@ -112,7 +112,7 @@ GO(drmModeCrtcSetGamma, iFiuuppp)
 GO(drmModeDestroyPropertyBlob, iFiu)
 GO(drmModeDetachMode, iFiup)
 GO(drmModeDirtyFB, iFiupu)
-//GO(drmModeFreeConnector, vFbuuuuuuuuipippip_)
+GOM(drmModeFreeConnector, vFEp)
 GO(drmModeFreeCrtc, vFp)
 GO(drmModeFreeEncoder, vFp)
 GO(drmModeFreeFB, vFp)
@@ -122,9 +122,9 @@ GO(drmModeFreeModeInfo, vFp)
 //GO(drmModeFreePlaneResources, vFbup_)
 //GO(drmModeFreeProperty, vFbuuccccccccccccccccccccccccccccccccipipip_)
 //GO(drmModeFreePropertyBlob, vFbuup_)
-//GO(drmModeFreeResources, vFbipipipipuuuu_)
-//GOM(drmModeGetConnector, pFEiu)
-//GOM(drmModeGetConnectorCurrent, pFEiu)
+GOM(drmModeFreeResources, vFEp)
+GOM(drmModeGetConnector, pFEiu)
+GOM(drmModeGetConnectorCurrent, pFEiu)
 GO(drmModeGetCrtc, pFiu)
 GO(drmModeGetEncoder, pFiu)
 GO(drmModeGetFB, pFiu)
@@ -133,7 +133,7 @@ GO(drmModeGetFB, pFiu)
 //GOM(drmModeGetPlaneResources, pFEi)
 //GOM(drmModeGetProperty, pFEiu)
 //GOM(drmModeGetPropertyBlob, pFEiu)
-//GOM(drmModeGetResources, pFEi)
+GOM(drmModeGetResources, pFEi)
 //GO(drmModeListLessees, 
 GO(drmModeMoveCursor, iFiuii)
 //GOM(drmModeObjectGetProperties, pFEiuu)