Thunks/X11: Thunk function pointers set up in XOpenDisplay

This commit is contained in:
Tony Wasserka 2022-07-29 18:21:02 +02:00
parent 4f8ae81562
commit 3ac1650001
2 changed files with 53 additions and 2 deletions

View File

@ -130,9 +130,45 @@ extern "C" {
}
}
Display* XOpenDisplay(const char* name) {
auto ret = fexfn_pack_XOpenDisplay(name);
for (auto& funcptr : ret->event_vec) {
if (!funcptr) {
continue;
}
auto caller = (uintptr_t)GetCallerForHostFunction(funcptr);
LinkAddressToFunction((uintptr_t)funcptr, (uintptr_t)caller);
}
for (auto& funcptr : ret->wire_vec) {
if (!funcptr) {
continue;
}
auto caller = (uintptr_t)GetCallerForHostFunction(funcptr);
LinkAddressToFunction((uintptr_t)funcptr, (uintptr_t)caller);
}
{
auto caller = (uintptr_t)GetCallerForHostFunction(ret->resource_alloc);
LinkAddressToFunction((uintptr_t)ret->resource_alloc, (uintptr_t)caller);
}
{
auto caller = (uintptr_t)GetCallerForHostFunction(ret->idlist_alloc);
LinkAddressToFunction((uintptr_t)ret->idlist_alloc, (uintptr_t)caller);
}
{
auto caller = (uintptr_t)GetCallerForHostFunction(ret->exit_handler);
LinkAddressToFunction((uintptr_t)ret->exit_handler, (uintptr_t)caller);
}
return ret;
}
void (*_XLockMutex_fn)(LockInfoPtr) = LockMutexFunction;
void (*_XUnlockMutex_fn)(LockInfoPtr) = UnlockMutexFunction;
typedef struct _LockInfoRec *LockInfoPtr;
LockInfoPtr _Xglobal_lock = (LockInfoPtr)0x4142434445464748ULL;
}

View File

@ -9,11 +9,16 @@
#include <X11/Xlibint.h>
#include <X11/XKBlib.h>
#include <type_traits>
template<auto>
struct fex_gen_config {
unsigned version = 6;
};
template<typename>
struct fex_gen_type {};
template<> struct fex_gen_config<XFetchBytes> {};
template<> struct fex_gen_config<XLocaleOfIM> {};
template<> struct fex_gen_config<XLocaleOfOM> {};
@ -453,7 +458,17 @@ template<> struct fex_gen_config<XListExtensions> {};
template<> struct fex_gen_config<XSetLocaleModifiers> {};
template<> struct fex_gen_config<XCreateColormap> {};
template<> struct fex_gen_config<XCreatePixmapCursor> {};
template<> struct fex_gen_config<XOpenDisplay> {};
template<> struct fex_gen_type<XID(Display*)> {}; // XDisplay::resource_alloc
// NOTE: only indirect calls to this are allowed
// NOTE: The char* and int arguments are only present in some configurations, but always enabling them interfers with our internal ABI...
template<> struct fex_gen_type<void(Display*/*, char*, int*/)> {}; // XDisplay::lock_fns->lock_display
template<> struct fex_gen_type<void(_XDisplay*, XID*, int)> {}; // XDisplay::idlist_alloc
template<> struct fex_gen_type<std::remove_pointer_t<XIOErrorExitHandler>> {}; // XDisplay::exit_handler
template<> struct fex_gen_config<XOpenDisplay> : fexgen::custom_guest_entrypoint {};
template<> struct fex_gen_config<XChangeProperty> {};
template<> struct fex_gen_config<XCloseDisplay> {};
template<> struct fex_gen_config<XCloseIM> {};