Skip to content

Commit

Permalink
[WRAPPER] Reworked wrapped libwayland-client with new wrapperhelper
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Sep 23, 2024
1 parent 4c0a213 commit dbdb3d6
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/wrapped/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,7 @@
#() pFpuuuuu
#() pFpuuupu
#() pFpupuui
#() pFpupuup
#() pFpuppip
#() pFpupppp
#() pFplpppp
Expand Down Expand Up @@ -5872,6 +5873,8 @@ wrappedvulkan:
- vFpuuuupupup:
- vkCmdPipelineBarrier
wrappedwaylandclient:
- vFp:
- wl_log_set_handler_client
- iFppp:
- wl_proxy_add_listener
wrappedwaylandcursor:
Expand Down
2 changes: 2 additions & 0 deletions src/wrapped/generated/wrappedwaylandclienttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
#define ADDED_FUNCTIONS()
#endif

typedef void (*vFp_t)(void*);
typedef int32_t (*iFppp_t)(void*, void*, void*);

#define SUPER() ADDED_FUNCTIONS() \
GO(wl_log_set_handler_client, vFp_t) \
GO(wl_proxy_add_listener, iFppp_t)

#endif // __wrappedwaylandclientTYPES_H_
3 changes: 3 additions & 0 deletions src/wrapped/generated/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,7 @@ typedef void* (*pFpuiiip_t)(void*, uint32_t, int32_t, int32_t, int32_t, void*);
typedef void* (*pFpuuuuu_t)(void*, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
typedef void* (*pFpuuupu_t)(void*, uint32_t, uint32_t, uint32_t, void*, uint32_t);
typedef void* (*pFpupuui_t)(void*, uint32_t, void*, uint32_t, uint32_t, int32_t);
typedef void* (*pFpupuup_t)(void*, uint32_t, void*, uint32_t, uint32_t, void*);
typedef void* (*pFpuppip_t)(void*, uint32_t, void*, void*, int32_t, void*);
typedef void* (*pFpupppp_t)(void*, uint32_t, void*, void*, void*, void*);
typedef void* (*pFplpppp_t)(void*, intptr_t, void*, void*, void*, void*);
Expand Down Expand Up @@ -5523,6 +5524,7 @@ void pFpuiiip(x64emu_t *emu, uintptr_t fcn) { pFpuiiip_t fn = (pFpuiiip_t)fcn; R
void pFpuuuuu(x64emu_t *emu, uintptr_t fcn) { pFpuuuuu_t fn = (pFpuuuuu_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI, (uint32_t)R_RSI, (uint32_t)R_RDX, (uint32_t)R_RCX, (uint32_t)R_R8, (uint32_t)R_R9); }
void pFpuuupu(x64emu_t *emu, uintptr_t fcn) { pFpuuupu_t fn = (pFpuuupu_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI, (uint32_t)R_RSI, (uint32_t)R_RDX, (uint32_t)R_RCX, (void*)R_R8, (uint32_t)R_R9); }
void pFpupuui(x64emu_t *emu, uintptr_t fcn) { pFpupuui_t fn = (pFpupuui_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI, (uint32_t)R_RSI, (void*)R_RDX, (uint32_t)R_RCX, (uint32_t)R_R8, (int32_t)R_R9); }
void pFpupuup(x64emu_t *emu, uintptr_t fcn) { pFpupuup_t fn = (pFpupuup_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI, (uint32_t)R_RSI, (void*)R_RDX, (uint32_t)R_RCX, (uint32_t)R_R8, (void*)R_R9); }
void pFpuppip(x64emu_t *emu, uintptr_t fcn) { pFpuppip_t fn = (pFpuppip_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI, (uint32_t)R_RSI, (void*)R_RDX, (void*)R_RCX, (int32_t)R_R8, (void*)R_R9); }
void pFpupppp(x64emu_t *emu, uintptr_t fcn) { pFpupppp_t fn = (pFpupppp_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI, (uint32_t)R_RSI, (void*)R_RDX, (void*)R_RCX, (void*)R_R8, (void*)R_R9); }
void pFplpppp(x64emu_t *emu, uintptr_t fcn) { pFplpppp_t fn = (pFplpppp_t)fcn; R_RAX=(uintptr_t)fn((void*)R_RDI, (intptr_t)R_RSI, (void*)R_RDX, (void*)R_RCX, (void*)R_R8, (void*)R_R9); }
Expand Down Expand Up @@ -8329,6 +8331,7 @@ int isSimpleWrapper(wrapper_t fun) {
if (fun == &pFpuuuuu) return 1;
if (fun == &pFpuuupu) return 1;
if (fun == &pFpupuui) return 1;
if (fun == &pFpupuup) return 1;
if (fun == &pFpuppip) return 1;
if (fun == &pFpupppp) return 1;
if (fun == &pFplpppp) return 1;
Expand Down
1 change: 1 addition & 0 deletions src/wrapped/generated/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,7 @@ void pFpuiiip(x64emu_t *emu, uintptr_t fnc);
void pFpuuuuu(x64emu_t *emu, uintptr_t fnc);
void pFpuuupu(x64emu_t *emu, uintptr_t fnc);
void pFpupuui(x64emu_t *emu, uintptr_t fnc);
void pFpupuup(x64emu_t *emu, uintptr_t fnc);
void pFpuppip(x64emu_t *emu, uintptr_t fnc);
void pFpupppp(x64emu_t *emu, uintptr_t fnc);
void pFplpppp(x64emu_t *emu, uintptr_t fnc);
Expand Down
40 changes: 40 additions & 0 deletions src/wrapped/wrappedwaylandclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <dlfcn.h>
#include <stdarg.h>

#include "wrappedlibs.h"

Expand Down Expand Up @@ -34,6 +35,40 @@ GO(2) \
GO(3) \
GO(4)

//wl_log_func_t
#ifdef CONVERT_VALIST
#define GO(A) \
static uintptr_t my_wl_log_func_t_fct_##A = 0; \
static void my_wl_log_func_t_##A(void* fmt, x64_va_list_t args) \
{ \
CONVERT_VALIST(args) \
RunFunction(my_wl_log_func_t_fct_##A, 2, fmt, VARARGS); \
}
#else
#define GO(A) \
static uintptr_t my_wl_log_func_t_fct_##A = 0; \
static void my_wl_log_func_t_##A(void* fmt, x64_va_list_t args) \
{ \
CREATE_VALIST_FROM_VALIST(args, thread_get_emu()->scratch); \
RunFunction(my_wl_log_func_t_fct_##A, 2, fmt, VARARGS); \
}
#endif
SUPER()
#undef GO
static void* find_wl_log_func_t_Fct(void* fct)
{
if(!fct) return fct;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_wl_log_func_t_fct_##A == (uintptr_t)fct) return my_wl_log_func_t_##A;
SUPER()
#undef GO
#define GO(A) if(my_wl_log_func_t_fct_##A == 0) {my_wl_log_func_t_fct_##A = (uintptr_t)fct; return my_wl_log_func_t_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for wayland-client wl_log_func_t callback\n");
return NULL;
}

// wl_registry_listener ...
typedef struct my_wl_registry_listener_s {
uintptr_t global; //vFppupu
Expand Down Expand Up @@ -561,4 +596,9 @@ EXPORT int my_wl_proxy_add_listener(x64emu_t* emu, void* proxy, void** l, void*
return my->wl_proxy_add_listener(proxy, l, data);
}

EXPORT void my_wl_log_set_handler_client(x64emu_t* emu, void* f)
{
my->wl_log_set_handler_client(find_wl_log_func_t_Fct(f));
}

#include "wrappedlib_init.h"
34 changes: 17 additions & 17 deletions src/wrapped/wrappedwaylandclient_private.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA))
#error meh!
#error Meh...
#endif

GO(wl_array_add, pFpL)
//GO(wl_array_copy,
GO(wl_array_copy, iFpp)
GO(wl_array_init, vFp)
GO(wl_array_release, vFp)
DATA(wl_buffer_interface, 40)
//DATA(wl_callback_interface,
//DATA(wl_callback_interface, 0)
DATA(wl_compositor_interface, 40)
//DATA(wl_data_device_interface,
//DATA(wl_data_device_manager_interface,
//DATA(wl_data_offer_interface,
//DATA(wl_data_source_interface,
//DATA(wl_data_device_interface, 0)
//DATA(wl_data_device_manager_interface, 0)
//DATA(wl_data_offer_interface, 0)
//DATA(wl_data_source_interface, 0)
GO(wl_display_cancel_read, vFp)
GO(wl_display_connect, pFp)
GO(wl_display_connect_to_fd, pFi)
Expand All @@ -25,7 +25,7 @@ GO(wl_display_dispatch_queue_pending, iFpp)
GO(wl_display_flush, iFp)
GO(wl_display_get_error, iFp)
GO(wl_display_get_fd, iFp)
//GO(wl_display_get_protocol_error,
GO(wl_display_get_protocol_error, uFppp)
DATA(wl_display_interface, 40)
GO(wl_display_prepare_read, iFp)
GO(wl_display_prepare_read_queue, iFpp)
Expand All @@ -34,36 +34,36 @@ GO(wl_display_roundtrip, iFp)
GO(wl_display_roundtrip_queue, iFpp)
GO(wl_event_queue_destroy, vFp)
DATA(wl_keyboard_interface, 40)
//GO(wl_list_empty,
GO(wl_list_empty, iFp)
GO(wl_list_init, vFp)
GO(wl_list_insert, vFpp)
//GO(wl_list_insert_list,
//GO(wl_list_length,
GO(wl_list_insert_list, vFpp)
GO(wl_list_length, iFp)
GO(wl_list_remove, vFp)
//GO(wl_log_set_handler_client,
GOM(wl_log_set_handler_client, vFEp)
DATA(wl_output_interface, 40)
DATA(wl_pointer_interface, 40)
//GO(wl_proxy_add_dispatcher,
//GOM(wl_proxy_add_dispatcher, iFEpppp)
GOM(wl_proxy_add_listener, iFEppp)
GO(wl_proxy_create, pFpp)
GO(wl_proxy_create_wrapper, pFp)
GO(wl_proxy_destroy, vFp)
//GO(wl_proxy_get_class,
GO(wl_proxy_get_class, pFp)
GO(wl_proxy_get_id, uFp)
GO(wl_proxy_get_listener, pFp)
//GO(wl_proxy_get_tag,
GO(wl_proxy_get_tag, pFp)
GO(wl_proxy_get_user_data, pFp)
GO(wl_proxy_get_version, uFp)
GO(wl_proxy_marshal, vFpupppppppppp) //VAARGS
GO(wl_proxy_marshal_array, vFpup)
GO(wl_proxy_marshal_array_constructor, pFpupp)
GO(wl_proxy_marshal_array_constructor_versioned, pFpuppu)
//GO(wl_proxy_marshal_array_flags,
GO(wl_proxy_marshal_array_flags, pFpupuup)
GO(wl_proxy_marshal_constructor, pFpupppppppppppppppp) //VAARGS
GO(wl_proxy_marshal_constructor_versioned, pFpupupppppppppppppppp) //VAARGS
GO(wl_proxy_marshal_flags, pFpupuupppppppppppppppppppp) //VAARGS
GO(wl_proxy_set_queue, vFpp)
//GO(wl_proxy_set_tag,
GO(wl_proxy_set_tag, vFpp)
GO(wl_proxy_set_user_data, vFpp)
GO(wl_proxy_wrapper_destroy, vFp)
DATA(wl_region_interface, 40)
Expand Down

0 comments on commit dbdb3d6

Please sign in to comment.