|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +#include <string.h> |
| 4 | +#define _GNU_SOURCE /* See feature_test_macros(7) */ |
| 5 | +#include <dlfcn.h> |
| 6 | + |
| 7 | +#include "wrappedlibs.h" |
| 8 | + |
| 9 | +#include "debug.h" |
| 10 | +#include "wrapper.h" |
| 11 | +#include "bridge.h" |
| 12 | +#include "librarian/library_private.h" |
| 13 | +#include "x64emu.h" |
| 14 | +#include "emu/x64emu_private.h" |
| 15 | +#include "box64context.h" |
| 16 | +#include "librarian.h" |
| 17 | +#include "callback.h" |
| 18 | +#include "gltools.h" |
| 19 | + |
| 20 | +const char* libglxnvidiaName = "libGLX_nvidia.so.0"; |
| 21 | +#define ALTNAME "libGLX_nvidia.so" |
| 22 | +#define LIBNAME libglxnvidia |
| 23 | + |
| 24 | +#include "generated/wrappedlibglxnvidiatypes.h" |
| 25 | + |
| 26 | +#include "wrappercallback.h" |
| 27 | + |
| 28 | +// FIXME: old wrapped* type of file, cannot use generated/wrappedlibgltypes.h |
| 29 | + |
| 30 | +EXPORT void* mynv_glXGetProcAddress(x64emu_t* emu, void* name) |
| 31 | +{ |
| 32 | + pFp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 33 | + if(!fnc) fnc=my->glXGetProcAddress; |
| 34 | + khint_t k; |
| 35 | + const char* rname = (const char*)name; |
| 36 | + return getGLProcAddress(emu, (void*)fnc, rname); |
| 37 | +} |
| 38 | +EXPORT void* mynv_glXGetProcAddressARB(x64emu_t* emu, void* name) __attribute__((alias("mynv_glXGetProcAddress"))); |
| 39 | + |
| 40 | +typedef int (*iFi_t)(int); |
| 41 | +typedef void (*vFpp_t)(void*, void*); |
| 42 | +typedef void (*vFppp_t)(void*, void*, void*); |
| 43 | +typedef void (*vFppi_t)(void*, void*, int); |
| 44 | +typedef void*(*pFp_t)(void*); |
| 45 | +typedef void (*debugProc_t)(int32_t, int32_t, uint32_t, int32_t, int32_t, void*, void*); |
| 46 | + |
| 47 | +typedef struct gl_wrappers_s { |
| 48 | + glprocaddress_t procaddress; |
| 49 | + kh_symbolmap_t *glwrappers; // the map of wrapper for glProcs (for GLX or SDL1/2) |
| 50 | + kh_symbolmap_t *glmymap; // link to the mysymbolmap of libGL |
| 51 | +} gl_wrappers_t; |
| 52 | + |
| 53 | +KHASH_MAP_INIT_INT64(gl_wrappers, gl_wrappers_t*) |
| 54 | + |
| 55 | +static kh_gl_wrappers_t *gl_wrappers = NULL; |
| 56 | + |
| 57 | +#define SUPER() \ |
| 58 | +GO(0) \ |
| 59 | +GO(1) \ |
| 60 | +GO(2) \ |
| 61 | +GO(3) \ |
| 62 | +GO(4) |
| 63 | + |
| 64 | +// debug_callback ... |
| 65 | +#define GO(A) \ |
| 66 | +static uintptr_t my_debug_callback_fct_##A = 0; \ |
| 67 | +static void my_debug_callback_##A(int32_t a, int32_t b, uint32_t c, int32_t d, int32_t e, const char* f, const void* g) \ |
| 68 | +{ \ |
| 69 | + RunFunctionFmt(my_debug_callback_fct_##A, "iiuiipp", a, b, c, d, e, f, g); \ |
| 70 | +} |
| 71 | +SUPER() |
| 72 | +#undef GO |
| 73 | +static void* find_debug_callback_Fct(void* fct) |
| 74 | +{ |
| 75 | + if(!fct) return fct; |
| 76 | + if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct); |
| 77 | + #define GO(A) if(my_debug_callback_fct_##A == (uintptr_t)fct) return my_debug_callback_##A; |
| 78 | + SUPER() |
| 79 | + #undef GO |
| 80 | + #define GO(A) if(my_debug_callback_fct_##A == 0) {my_debug_callback_fct_##A = (uintptr_t)fct; return my_debug_callback_##A; } |
| 81 | + SUPER() |
| 82 | + #undef GO |
| 83 | + printf_log(LOG_NONE, "Warning, no more slot for libGL debug_callback callback\n"); |
| 84 | + return NULL; |
| 85 | +} |
| 86 | +// egl_debug_callback ... |
| 87 | +#define GO(A) \ |
| 88 | +static uintptr_t my_egl_debug_callback_fct_##A = 0; \ |
| 89 | + static void my_egl_debug_callback_##A(int a, void* b, int c, void* d, void* e, const char* f) \ |
| 90 | +{ \ |
| 91 | + RunFunctionFmt(my_egl_debug_callback_fct_##A, "ipippp", a, b, c, d, e, f); \ |
| 92 | +} |
| 93 | +SUPER() |
| 94 | +#undef GO |
| 95 | +static void* find_egl_debug_callback_Fct(void* fct) |
| 96 | +{ |
| 97 | + if(!fct) return fct; |
| 98 | + if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct); |
| 99 | + #define GO(A) if(my_egl_debug_callback_fct_##A == (uintptr_t)fct) return my_egl_debug_callback_##A; |
| 100 | + SUPER() |
| 101 | + #undef GO |
| 102 | + #define GO(A) if(my_egl_debug_callback_fct_##A == 0) {my_egl_debug_callback_fct_##A = (uintptr_t)fct; return my_egl_debug_callback_##A; } |
| 103 | + SUPER() |
| 104 | + #undef GO |
| 105 | + printf_log(LOG_NONE, "Warning, no more slot for libGL egl_debug_callback callback\n"); |
| 106 | + return NULL; |
| 107 | +} |
| 108 | +// program_callback ... |
| 109 | +#define GO(A) \ |
| 110 | +static uintptr_t my_program_callback_fct_##A = 0; \ |
| 111 | +static void my_program_callback_##A(int32_t a, void* b) \ |
| 112 | +{ \ |
| 113 | + RunFunctionFmt(my_program_callback_fct_##A, "ip", a, b); \ |
| 114 | +} |
| 115 | +SUPER() |
| 116 | +#undef GO |
| 117 | +static void* find_program_callback_Fct(void* fct) |
| 118 | +{ |
| 119 | + if(!fct) return fct; |
| 120 | + if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct); |
| 121 | + #define GO(A) if(my_program_callback_fct_##A == (uintptr_t)fct) return my_program_callback_##A; |
| 122 | + SUPER() |
| 123 | + #undef GO |
| 124 | + #define GO(A) if(my_program_callback_fct_##A == 0) {my_program_callback_fct_##A = (uintptr_t)fct; return my_program_callback_##A; } |
| 125 | + SUPER() |
| 126 | + #undef GO |
| 127 | + printf_log(LOG_NONE, "Warning, no more slot for libGL program_callback callback\n"); |
| 128 | + return NULL; |
| 129 | +} |
| 130 | +// set_blob_func ... |
| 131 | +#define GO(A) \ |
| 132 | +static uintptr_t my_set_blob_func_fct_##A = 0; \ |
| 133 | +static void my_set_blob_func_##A(void* a, ssize_t b, void* c, ssize_t d) \ |
| 134 | +{ \ |
| 135 | + RunFunctionFmt(my_set_blob_func_fct_##A, "plpl", a, b, c, d); \ |
| 136 | +} |
| 137 | +SUPER() |
| 138 | +#undef GO |
| 139 | +static void* find_set_blob_func_Fct(void* fct) |
| 140 | +{ |
| 141 | + if(!fct) return fct; |
| 142 | + if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct); |
| 143 | + #define GO(A) if(my_set_blob_func_fct_##A == (uintptr_t)fct) return my_set_blob_func_##A; |
| 144 | + SUPER() |
| 145 | + #undef GO |
| 146 | + #define GO(A) if(my_set_blob_func_fct_##A == 0) {my_set_blob_func_fct_##A = (uintptr_t)fct; return my_set_blob_func_##A; } |
| 147 | + SUPER() |
| 148 | + #undef GO |
| 149 | + printf_log(LOG_NONE, "Warning, no more slot for libGL set_blob_func callback\n"); |
| 150 | + return NULL; |
| 151 | +} |
| 152 | +// get_blob_func ... |
| 153 | +#define GO(A) \ |
| 154 | +static uintptr_t my_get_blob_func_fct_##A = 0; \ |
| 155 | +static ssize_t my_get_blob_func_##A(void* a, ssize_t b, void* c, ssize_t d) \ |
| 156 | +{ \ |
| 157 | + return (ssize_t)RunFunctionFmt(my_get_blob_func_fct_##A, "plpl", a, b, c, d); \ |
| 158 | +} |
| 159 | +SUPER() |
| 160 | +#undef GO |
| 161 | +static void* find_get_blob_func_Fct(void* fct) |
| 162 | +{ |
| 163 | + if(!fct) return fct; |
| 164 | + if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct); |
| 165 | + #define GO(A) if(my_get_blob_func_fct_##A == (uintptr_t)fct) return my_get_blob_func_##A; |
| 166 | + SUPER() |
| 167 | + #undef GO |
| 168 | + #define GO(A) if(my_get_blob_func_fct_##A == 0) {my_get_blob_func_fct_##A = (uintptr_t)fct; return my_get_blob_func_##A; } |
| 169 | + SUPER() |
| 170 | + #undef GO |
| 171 | + printf_log(LOG_NONE, "Warning, no more slot for libGL get_blob_func callback\n"); |
| 172 | + return NULL; |
| 173 | +} |
| 174 | +#undef SUPER |
| 175 | +#define ALTMY mynv |
| 176 | +#include "wrappedlib_init.h" |
| 177 | + |
| 178 | +// glDebugMessageCallback |
| 179 | +static void mynv_glDebugMessageCallback(x64emu_t* emu, void* prod, void* param) |
| 180 | +{ |
| 181 | + vFpp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 182 | + if(!fnc) fnc=my->glDebugMessageCallback; |
| 183 | + fnc(find_debug_callback_Fct(prod), param); |
| 184 | +} |
| 185 | +// glDebugMessageCallbackARB |
| 186 | +static void mynv_glDebugMessageCallbackARB(x64emu_t* emu, void* prod, void* param) |
| 187 | +{ |
| 188 | + vFpp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 189 | + if(!fnc) fnc=my->glDebugMessageCallbackARB; |
| 190 | + fnc(find_debug_callback_Fct(prod), param); |
| 191 | +} |
| 192 | +// glDebugMessageCallbackAMD |
| 193 | +static void mynv_glDebugMessageCallbackAMD(x64emu_t* emu, void* prod, void* param) |
| 194 | +{ |
| 195 | + vFpp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 196 | + if(!fnc) fnc=my->glDebugMessageCallbackAMD; |
| 197 | + fnc(find_debug_callback_Fct(prod), param); |
| 198 | +} |
| 199 | +// glDebugMessageCallbackKHR |
| 200 | +static void mynv_glDebugMessageCallbackKHR(x64emu_t* emu, void* prod, void* param) |
| 201 | +{ |
| 202 | + vFpp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 203 | + if(!fnc) fnc=my->glDebugMessageCallbackKHR; |
| 204 | + fnc(find_debug_callback_Fct(prod), param); |
| 205 | +} |
| 206 | +// eglDebugMessageControlKHR |
| 207 | +static int mynv_eglDebugMessageControlKHR(x64emu_t* emu, void* prod, void* param) |
| 208 | +{ |
| 209 | + iFpp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 210 | + if(!fnc) fnc=my->eglDebugMessageControlKHR; |
| 211 | + return fnc(find_debug_callback_Fct(prod), param); |
| 212 | +} |
| 213 | +// eglSetBlobCacheFuncsANDROID ... |
| 214 | +static void mynv_eglSetBlobCacheFuncsANDROID(x64emu_t* emu, void* dpy, void* set, void* get) \ |
| 215 | +{ \ |
| 216 | + vFppp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 217 | + if(!fnc) fnc=my->eglSetBlobCacheFuncsANDROID; |
| 218 | + fnc(dpy, find_set_blob_func_Fct(set), find_get_blob_func_Fct(get)); |
| 219 | +} |
| 220 | +// glXSwapIntervalMESA ... |
| 221 | +static int mynv_dummy_glXSwapIntervalMESA(int interval) |
| 222 | +{ |
| 223 | + return 5; // GLX_BAD_CONTEXT |
| 224 | +} |
| 225 | +static int mynv_glXSwapIntervalMESA(x64emu_t* emu, int interval) |
| 226 | +{ |
| 227 | + iFi_t fnc = getBridgeFnc2((void*)R_RIP); |
| 228 | + if(!fnc) fnc=my->glXSwapIntervalMESA; |
| 229 | + if(!fnc) fnc=mynv_dummy_glXSwapIntervalMESA; |
| 230 | + return fnc(interval); |
| 231 | +} |
| 232 | +// glXSwapIntervalEXT ... |
| 233 | +static void mynv_dummy_glXSwapIntervalEXT(void* dpy, void* drawable, int interval) {} |
| 234 | +static void mynv_glXSwapIntervalEXT(x64emu_t* emu, void* dpy, void* drawable, int interval) |
| 235 | +{ |
| 236 | + vFppi_t fnc = getBridgeFnc2((void*)R_RIP); |
| 237 | + if(!fnc) fnc=my->glXSwapIntervalEXT; |
| 238 | + if(!fnc) fnc=mynv_dummy_glXSwapIntervalEXT; |
| 239 | + fnc(dpy, drawable, interval); |
| 240 | +} |
| 241 | +// glProgramCallbackMESA ... |
| 242 | +static void mynv_glProgramCallbackMESA(x64emu_t* emu, int t, void* f, void* data) |
| 243 | +{ |
| 244 | + vFipp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 245 | + if(!fnc) fnc=my->glProgramCallbackMESA; |
| 246 | + fnc(t, find_program_callback_Fct(f), data); |
| 247 | +} |
| 248 | +void* my_GetVkProcAddr(x64emu_t* emu, void* name, void*(*getaddr)(void*)); // defined in wrappedvulkan.c |
| 249 | +// glGetVkProcAddrNV ... |
| 250 | +static void* mynv_glGetVkProcAddrNV(x64emu_t* emu, void* name) |
| 251 | +{ |
| 252 | + pFp_t fnc = getBridgeFnc2((void*)R_RIP); |
| 253 | + if(!fnc) fnc=my->glGetVkProcAddrNV; |
| 254 | + return my_GetVkProcAddr(emu, name, fnc); |
| 255 | +} |
0 commit comments