diff --git a/ThunkLibs/libEGL/libEGL_interface.cpp b/ThunkLibs/libEGL/libEGL_interface.cpp index 7d681948e..c9bb2d1cc 100644 --- a/ThunkLibs/libEGL/libEGL_interface.cpp +++ b/ThunkLibs/libEGL/libEGL_interface.cpp @@ -7,6 +7,10 @@ struct fex_gen_config { unsigned version = 1; }; +// Function, parameter index, parameter type [optional] +template +struct fex_gen_param {}; + template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -23,4 +27,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; + +// EGLNativeDisplayType is a pointer to opaque data (wl_display/(X)Display/...) template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; diff --git a/ThunkLibs/libGL/libGL_interface.cpp b/ThunkLibs/libGL/libGL_interface.cpp index e292b2e05..d05c0cbab 100644 --- a/ThunkLibs/libGL/libGL_interface.cpp +++ b/ThunkLibs/libGL/libGL_interface.cpp @@ -11,6 +11,8 @@ #undef GL_ARB_viewport_array #include "glcorearb.h" +#include + template struct fex_gen_config { unsigned version = 1; @@ -18,6 +20,25 @@ struct fex_gen_config { template<> struct fex_gen_config : fexgen::custom_guest_entrypoint, fexgen::returns_guest_pointer {}; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type> : fexgen::opaque_type {}; +template<> struct fex_gen_type> : fexgen::opaque_type {}; +template<> struct fex_gen_type> : fexgen::opaque_type {}; + +// NOTE: These should be opaque, but actually aren't because the respective libraries aren't thunked +template<> struct fex_gen_type<_cl_context> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_cl_event> : fexgen::opaque_type {}; + +// Opaque for the purpose of libGL +template<> struct fex_gen_type<_XDisplay> : fexgen::opaque_type {}; + +#ifndef IS_32BIT_THUNK +// TODO: These are largely compatible, *but* contain function pointer members that need adjustment! +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#endif + // Symbols queryable through glXGetProcAddr namespace internal { template diff --git a/ThunkLibs/libX11/libX11_Guest.cpp b/ThunkLibs/libX11/libX11_Guest.cpp index b32ad9228..3a2547a76 100644 --- a/ThunkLibs/libX11/libX11_Guest.cpp +++ b/ThunkLibs/libX11/libX11_Guest.cpp @@ -14,6 +14,8 @@ extern "C" { #include #include +#include + // Include Xlibint.h and undefine some of its macros that clash with the standard library #include #undef min diff --git a/ThunkLibs/libX11/libX11_Host.cpp b/ThunkLibs/libX11/libX11_Host.cpp index c73d7a6ea..568543a70 100644 --- a/ThunkLibs/libX11/libX11_Host.cpp +++ b/ThunkLibs/libX11/libX11_Host.cpp @@ -20,12 +20,20 @@ extern "C" { #undef min #undef max +#define XTRANS_SEND_FDS 1 +#include + #include +#include #include #include +#include #include +#include + +#include } #include "common/Host.h" diff --git a/ThunkLibs/libX11/libX11_interface.cpp b/ThunkLibs/libX11/libX11_interface.cpp index 188826056..15675e4fc 100644 --- a/ThunkLibs/libX11/libX11_interface.cpp +++ b/ThunkLibs/libX11/libX11_interface.cpp @@ -10,11 +10,15 @@ extern "C" { #include +#include #include +#include #include #include +#include + #include } @@ -28,6 +32,10 @@ struct fex_gen_config { template struct fex_gen_type {}; +// Function, parameter index, parameter type [optional] +template +struct fex_gen_param {}; + template<> struct fex_gen_type {}; // XDisplay::resource_alloc // NOTE: only indirect calls to this are allowed @@ -54,6 +62,61 @@ template<> struct fex_gen_type {}; // XIm template<> struct fex_gen_type {}; // XImage::f.put_pixel template<> struct fex_gen_type {}; // XImage::f.add_pixel +template<> struct fex_gen_type> : fexgen::opaque_type {}; +template<> struct fex_gen_type> : fexgen::opaque_type {}; +template<> struct fex_gen_type> : fexgen::opaque_type {}; +template<> struct fex_gen_type> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XrmHashBucketRec> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XkbInfoRec> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XContextDB> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XDisplayAtoms> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XLockInfo> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XIMFilter> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XErrorThreadInfo> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XKeytrans> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_X11XCBPrivate> : fexgen::opaque_type {}; + + +#ifndef IS_32BIT_THUNK +// This has a public definition but is used as an opaque type in most APIs +template<> struct fex_gen_type> : fexgen::assume_compatible_data_layout {}; + +// Union types +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + +// Union type of all sorts of different X objects... Further, XEHeadOfExtensionList casts this to XExtData**. +// This is likely highly unsafe to assume compatible. +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + +// Linked-list types +template<> struct fex_gen_type<_XtransConnFd> : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XkbDeviceLedChanges> : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XQEvent> : fexgen::assume_compatible_data_layout {}; + +// Contains nontrivial circular pointer relationships +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + +// TODO: These are largely compatible, *but* contain function pointer members that need adjustment! +template<> struct fex_gen_type<_XConnWatchInfo> : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XLockPtrs> : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XFreeFuncRec> : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XExtension> : fexgen::assume_compatible_data_layout {}; // Also contains linked-list pointers +template<> struct fex_gen_type<_XConnectionInfo> : fexgen::assume_compatible_data_layout {}; // Also contains linked-list pointers +template<> struct fex_gen_type<_XInternalAsync> : fexgen::assume_compatible_data_layout {}; // Also contains linked-list pointers +template<> struct fex_gen_type<_XDisplay> : fexgen::assume_compatible_data_layout {}; + +// TODO: This contains a nested struct type of function pointer members +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#endif + +// Union type (each member is defined in terms of char members) +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + // Xlibint template<> struct fex_gen_config<_XGetRequest> {}; template<> struct fex_gen_config<_XFlushGCCache> {}; diff --git a/ThunkLibs/libXext/libXext_Guest.cpp b/ThunkLibs/libXext/libXext_Guest.cpp index 0db7e4dab..e8684b83f 100644 --- a/ThunkLibs/libXext/libXext_Guest.cpp +++ b/ThunkLibs/libXext/libXext_Guest.cpp @@ -35,6 +35,8 @@ extern "C" { #include #include //#include +#undef min +#undef max #include "common/Guest.h" diff --git a/ThunkLibs/libXext/libXext_Host.cpp b/ThunkLibs/libXext/libXext_Host.cpp index 94caa6be0..076087b80 100644 --- a/ThunkLibs/libXext/libXext_Host.cpp +++ b/ThunkLibs/libXext/libXext_Host.cpp @@ -8,6 +8,7 @@ $end_info$ #include #include +#include #include #include #include @@ -38,6 +39,12 @@ extern "C" { #include //#include +#define XTRANS_SEND_FDS 1 +#include + +#undef min +#undef max + #include "common/Host.h" #include diff --git a/ThunkLibs/libXext/libXext_interface.cpp b/ThunkLibs/libXext/libXext_interface.cpp index 87b0666bb..18f6ccf1e 100644 --- a/ThunkLibs/libXext/libXext_interface.cpp +++ b/ThunkLibs/libXext/libXext_interface.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -16,12 +17,52 @@ extern "C" { #include } +#include template struct fex_gen_config { unsigned version = 6; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type<_X11XCBPrivate> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XContextDB> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XDisplayAtoms> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XErrorThreadInfo> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XIMFilter> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XkbInfoRec> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XKeytrans> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XLockInfo> : fexgen::opaque_type {}; +template<> struct fex_gen_type<_XrmHashBucketRec> : fexgen::opaque_type {}; + +#ifndef IS_32BIT_THUNK +// Union types +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + +// Linked-list types +template<> struct fex_gen_type<_XtransConnFd> : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XQEvent> : fexgen::assume_compatible_data_layout {}; + +// TODO: These are largely compatible, *but* contain function pointer members that need adjustment! +template<> struct fex_gen_type<_XConnectionInfo> : fexgen::assume_compatible_data_layout {}; // Also contains linked-list pointers +template<> struct fex_gen_type<_XConnWatchInfo> : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XDisplay> : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XExtension> : fexgen::assume_compatible_data_layout {}; // Also contains linked-list pointers +template<> struct fex_gen_type<_XInternalAsync> : fexgen::assume_compatible_data_layout {}; // Also contains linked-list pointers + +// Contains nontrivial circular pointer relationships +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + +// TODO: This contains a nested struct type of function pointer members +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#endif + template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; diff --git a/ThunkLibs/libXfixes/libXfixes_Host.cpp b/ThunkLibs/libXfixes/libXfixes_Host.cpp index b6a0a5ca9..0712fb90a 100644 --- a/ThunkLibs/libXfixes/libXfixes_Host.cpp +++ b/ThunkLibs/libXfixes/libXfixes_Host.cpp @@ -6,9 +6,14 @@ $end_info$ #include +extern "C" { #include +#include #include #include +} +#undef min +#undef max #include "common/Host.h" #include diff --git a/ThunkLibs/libXfixes/libXfixes_interface.cpp b/ThunkLibs/libXfixes/libXfixes_interface.cpp index 1bd6df682..24c2227a4 100644 --- a/ThunkLibs/libXfixes/libXfixes_interface.cpp +++ b/ThunkLibs/libXfixes/libXfixes_interface.cpp @@ -1,12 +1,24 @@ #include +extern "C" { #include +#include +} template struct fex_gen_config { unsigned version = 3; }; +template +struct fex_gen_type {}; + +#ifndef IS_32BIT_THUNK +// TODO: These are largely compatible, *but* contain function pointer members that need adjustment! +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XDisplay> : fexgen::assume_compatible_data_layout {}; +#endif + template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; diff --git a/ThunkLibs/libXrender/libXrender_Host.cpp b/ThunkLibs/libXrender/libXrender_Host.cpp index 49d01d88c..04dbb4a77 100644 --- a/ThunkLibs/libXrender/libXrender_Host.cpp +++ b/ThunkLibs/libXrender/libXrender_Host.cpp @@ -6,9 +6,15 @@ $end_info$ #include +extern "C" { #include +#include +#include #include #include +} +#undef min +#undef max #include "common/Host.h" #include diff --git a/ThunkLibs/libXrender/libXrender_interface.cpp b/ThunkLibs/libXrender/libXrender_interface.cpp index e884c286e..12424de42 100644 --- a/ThunkLibs/libXrender/libXrender_interface.cpp +++ b/ThunkLibs/libXrender/libXrender_interface.cpp @@ -2,11 +2,28 @@ #include +#include + template struct fex_gen_config { unsigned version = 1; }; +template +struct fex_gen_type {}; + +// Struct with multi-dimensional array member. Compatible data layout across all architectures +template<> struct fex_gen_type<_XTransform> : fexgen::assume_compatible_data_layout {}; + +#ifndef IS_32BIT_THUNK +// This has a public definition but is used as an opaque type in most APIs +template<> struct fex_gen_type> : fexgen::assume_compatible_data_layout {}; + +// TODO: These are largely compatible, *but* contain function pointer members that need adjustment! +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type<_XDisplay> : fexgen::assume_compatible_data_layout {}; +#endif + template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; diff --git a/ThunkLibs/libasound/libasound_interface.cpp b/ThunkLibs/libasound/libasound_interface.cpp index 7e34d5ce4..e7f101e3f 100644 --- a/ThunkLibs/libasound/libasound_interface.cpp +++ b/ThunkLibs/libasound/libasound_interface.cpp @@ -3,11 +3,99 @@ #include #include +#include + template struct fex_gen_config { unsigned version = 2; }; +// Function, parameter index, parameter type [optional] +template +struct fex_gen_param {}; + +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type> : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + +// Union types with compatible data layout +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +// Has anonymous union member +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + +#ifndef IS_32BIT_THUNK +// TODO: Convert vtable +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#endif + template<> struct fex_gen_config {}; #if SND_LIB_VERSION < ((1 << 16) | (2 << 8) | (6)) // Exists on 1.2.6 diff --git a/ThunkLibs/libdrm/libdrm_interface.cpp b/ThunkLibs/libdrm/libdrm_interface.cpp index a8075531e..f64cc2204 100644 --- a/ThunkLibs/libdrm/libdrm_interface.cpp +++ b/ThunkLibs/libdrm/libdrm_interface.cpp @@ -7,6 +7,21 @@ struct fex_gen_config { unsigned version = 2; }; +template +struct fex_gen_type {}; + +#ifndef IS_32BIT_THUNK +// Union types with compatible data layout +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + +// Anonymous sub-structs +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + +// TODO: Convert vtable +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#endif + size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libvulkan/Guest.cpp b/ThunkLibs/libvulkan/Guest.cpp index 066e1a6b4..cbad026a1 100644 --- a/ThunkLibs/libvulkan/Guest.cpp +++ b/ThunkLibs/libvulkan/Guest.cpp @@ -4,6 +4,8 @@ tags: thunklibs|Vulkan $end_info$ */ +#define VK_USE_64_BIT_PTR_DEFINES 0 + #define VK_USE_PLATFORM_XLIB_XRANDR_EXT #define VK_USE_PLATFORM_XLIB_KHR #define VK_USE_PLATFORM_XCB_KHR diff --git a/ThunkLibs/libvulkan/Host.cpp b/ThunkLibs/libvulkan/Host.cpp index 8e5b333dc..b3f11a7ab 100644 --- a/ThunkLibs/libvulkan/Host.cpp +++ b/ThunkLibs/libvulkan/Host.cpp @@ -4,6 +4,8 @@ tags: thunklibs|Vulkan $end_info$ */ +#define VK_USE_64_BIT_PTR_DEFINES 0 + #define VK_USE_PLATFORM_XLIB_XRANDR_EXT #define VK_USE_PLATFORM_XLIB_KHR #define VK_USE_PLATFORM_XCB_KHR @@ -91,8 +93,8 @@ static void FEXFN_IMPL(vkFreeMemory)(VkDevice a_0, VkDeviceMemory a_1, const VkA LDR_PTR(vkFreeMemory)(a_0, a_1, nullptr); } -static VkResult FEXFN_IMPL(vkCreateDebugReportCallbackEXT)(VkInstance a_0, const VkDebugReportCallbackCreateInfoEXT* a_1, const VkAllocationCallbacks* a_2, VkDebugReportCallbackEXT* a_3) { - VkDebugReportCallbackCreateInfoEXT overridden_callback = *a_1; +static VkResult FEXFN_IMPL(vkCreateDebugReportCallbackEXT)(VkInstance a_0, guest_layout a_1, const VkAllocationCallbacks* a_2, VkDebugReportCallbackEXT* a_3) { + VkDebugReportCallbackCreateInfoEXT overridden_callback = *a_1.data; overridden_callback.pfnCallback = DummyVkDebugReportCallback; (void*&)LDR_PTR(vkCreateDebugReportCallbackEXT) = (void*)LDR_PTR(vkGetInstanceProcAddr)(a_0, "vkCreateDebugReportCallbackEXT"); return LDR_PTR(vkCreateDebugReportCallbackEXT)(a_0, &overridden_callback, nullptr, a_3); @@ -103,6 +105,21 @@ static void FEXFN_IMPL(vkDestroyDebugReportCallbackEXT)(VkInstance a_0, VkDebugR LDR_PTR(vkDestroyDebugReportCallbackEXT)(a_0, a_1, nullptr); } +extern "C" VkBool32 DummyVkDebugUtilsMessengerCallback( + VkDebugUtilsMessageSeverityFlagBitsEXT, VkDebugUtilsMessageTypeFlagsEXT, + const VkDebugUtilsMessengerCallbackDataEXT*, void*) { + return VK_FALSE; +} + +static VkResult FEXFN_IMPL(vkCreateDebugUtilsMessengerEXT)( + VkInstance_T* a_0, guest_layout a_1, + const VkAllocationCallbacks* a_2, VkDebugUtilsMessengerEXT* a_3) { + VkDebugUtilsMessengerCreateInfoEXT overridden_callback = *a_1.data; + overridden_callback.pfnUserCallback = DummyVkDebugUtilsMessengerCallback; + (void*&)LDR_PTR(vkCreateDebugUtilsMessengerEXT) = (void*)LDR_PTR(vkGetInstanceProcAddr)(a_0, "vkCreateDebugUtilsMessengerEXT"); + return LDR_PTR(vkCreateDebugUtilsMessengerEXT)(a_0, &overridden_callback, nullptr, a_3); +} + static PFN_vkVoidFunction FEXFN_IMPL(vkGetDeviceProcAddr)(VkDevice a_0, const char* a_1) { // Just return the host facing function pointer // The guest will handle mapping if this exists diff --git a/ThunkLibs/libvulkan/libvulkan_interface.cpp b/ThunkLibs/libvulkan/libvulkan_interface.cpp index abc8d8b86..ba50a1842 100644 --- a/ThunkLibs/libvulkan/libvulkan_interface.cpp +++ b/ThunkLibs/libvulkan/libvulkan_interface.cpp @@ -1,10 +1,19 @@ #include +#include + template struct fex_gen_config { unsigned version = 1; }; +// Some of Vulkan's handle types are so-called "non-dispatchable handles". +// On 64-bit, these are defined as dedicated types by default, which makes +// annotating these handle types unnecessarily complicated. Instead, setting +// the following define will make the Vulkan headers alias all handle types +// to uint64_t. +#define VK_USE_64_BIT_PTR_DEFINES 0 + #define VK_USE_PLATFORM_XLIB_XRANDR_EXT #define VK_USE_PLATFORM_XLIB_KHR #define VK_USE_PLATFORM_XCB_KHR @@ -14,6 +23,52 @@ struct fex_gen_config { template<> struct fex_gen_config : fexgen::custom_host_impl, fexgen::custom_guest_entrypoint, fexgen::returns_guest_pointer {}; template<> struct fex_gen_config : fexgen::custom_host_impl, fexgen::custom_guest_entrypoint, fexgen::returns_guest_pointer {}; +template +struct fex_gen_type {}; + +// So-called "dispatchable" handles are represented as opaque pointers. +// In addition to marking them as such, API functions that create these objects +// need special care since they wrap these handles in another pointer, which +// the thunk generator can't automatically handle. +// +// So-called "non-dispatchable" handles don't need this extra treatment, since +// they are uint64_t IDs on both 32-bit and 64-bit systems. +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; + +// Mark union types with compatible layout as such +// TODO: These may still have different alignment requirements! +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#ifndef IS_32BIT_THUNK +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#endif + +#ifndef IS_32BIT_THUNK +// The pNext member of this is a pointer to another VkBaseOutStructure, so data layout compatibility can't be inferred automatically +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#endif + + +// TODO: Should not be opaque, but it's usually NULL anyway. Supporting the contained function pointers will need more work. +template<> struct fex_gen_type : fexgen::opaque_type {}; + +// X11 interop +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; + +// Wayland interop +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; + namespace internal { // Function, parameter index, parameter type [optional] @@ -31,6 +86,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +// TODO: Output parameter must repack on exit! template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -74,6 +130,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -185,6 +242,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -296,9 +354,11 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -370,6 +430,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config : fexgen::custom_host_impl {}; +template<> struct fex_gen_param : fexgen::ptr_passthrough {}; template<> struct fex_gen_config : fexgen::custom_host_impl {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -393,6 +454,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -417,7 +479,8 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; -template<> struct fex_gen_config {}; +template<> struct fex_gen_config : fexgen::custom_host_impl {}; +template<> struct fex_gen_param : fexgen::ptr_passthrough {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -427,6 +490,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -439,11 +503,15 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -453,6 +521,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -537,6 +606,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -609,6 +679,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -619,6 +690,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; diff --git a/ThunkLibs/libwayland-client/Host.cpp b/ThunkLibs/libwayland-client/Host.cpp index 8cfcb4693..00a29ef5c 100644 --- a/ThunkLibs/libwayland-client/Host.cpp +++ b/ThunkLibs/libwayland-client/Host.cpp @@ -46,7 +46,7 @@ static void WaylandFinalizeHostTrampolineForGuestListener(void (*callback)()) { } extern "C" int fexfn_impl_libwayland_client_wl_proxy_add_listener(struct wl_proxy *proxy, - guest_layout callback_raw, guest_layout data) { + guest_layout callback_raw, void* data) { auto guest_interface = ((wl_proxy_private*)proxy)->interface; for (int i = 0; i < guest_interface->event_count; ++i) { @@ -162,7 +162,7 @@ extern "C" int fexfn_impl_libwayland_client_wl_proxy_add_listener(struct wl_prox } // Pass the original function pointer table to the host wayland library. This ensures the table is valid until the listener is unregistered. - return fexldr_ptr_libwayland_client_wl_proxy_add_listener(proxy, callback_raw.data, data.data); + return fexldr_ptr_libwayland_client_wl_proxy_add_listener(proxy, callback_raw.data, data); } wl_interface* fexfn_impl_libwayland_client_fex_wl_exchange_interface_pointer(wl_interface* guest_interface, char const* name) { diff --git a/ThunkLibs/libwayland-client/libwayland-client_interface.cpp b/ThunkLibs/libwayland-client/libwayland-client_interface.cpp index 32fe6ba37..077e52c93 100644 --- a/ThunkLibs/libwayland-client/libwayland-client_interface.cpp +++ b/ThunkLibs/libwayland-client/libwayland-client_interface.cpp @@ -14,6 +14,15 @@ struct fex_gen_type {}; template struct fex_gen_param {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + +// Passed over Wayland's wire protocol for some functions +template<> struct fex_gen_type {}; + template<> struct fex_gen_config : fexgen::custom_guest_entrypoint {}; @@ -36,8 +45,10 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config : fexgen::custom_host_impl, fexgen::custom_guest_entrypoint {}; +// Callback table template<> struct fex_gen_param : fexgen::ptr_passthrough {}; -template<> struct fex_gen_param : fexgen::ptr_passthrough {}; +// User-provided data pointer (not used in caller-provided callback) +template<> struct fex_gen_param : fexgen::assume_compatible_data_layout {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; @@ -45,6 +56,7 @@ template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; +// TODO: This has a void* parameter. Why does 32-bit accept this without annotations? template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; diff --git a/ThunkLibs/libxcb-dri2/libxcb-dri2_interface.cpp b/ThunkLibs/libxcb-dri2/libxcb-dri2_interface.cpp index 07f93f48d..5a3349c55 100644 --- a/ThunkLibs/libxcb-dri2/libxcb-dri2_interface.cpp +++ b/ThunkLibs/libxcb-dri2/libxcb-dri2_interface.cpp @@ -1,12 +1,18 @@ #include #include +#include template struct fex_gen_config { unsigned version = 0; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + void FEX_xcb_dri2_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxcb-dri3/libxcb-dri3_interface.cpp b/ThunkLibs/libxcb-dri3/libxcb-dri3_interface.cpp index 0708baf23..07d20da64 100644 --- a/ThunkLibs/libxcb-dri3/libxcb-dri3_interface.cpp +++ b/ThunkLibs/libxcb-dri3/libxcb-dri3_interface.cpp @@ -1,12 +1,18 @@ #include #include +#include template struct fex_gen_config { unsigned version = 0; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + void FEX_xcb_dri3_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxcb-glx/libxcb-glx_interface.cpp b/ThunkLibs/libxcb-glx/libxcb-glx_interface.cpp index 28f76fcce..64160def5 100644 --- a/ThunkLibs/libxcb-glx/libxcb-glx_interface.cpp +++ b/ThunkLibs/libxcb-glx/libxcb-glx_interface.cpp @@ -1,12 +1,18 @@ #include #include +#include template struct fex_gen_config { unsigned version = 0; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + void FEX_xcb_glx_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxcb-present/libxcb-present_interface.cpp b/ThunkLibs/libxcb-present/libxcb-present_interface.cpp index b1e32b755..69481998b 100644 --- a/ThunkLibs/libxcb-present/libxcb-present_interface.cpp +++ b/ThunkLibs/libxcb-present/libxcb-present_interface.cpp @@ -1,12 +1,18 @@ #include #include +#include template struct fex_gen_config { unsigned version = 0; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + void FEX_xcb_present_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxcb-randr/libxcb-randr_interface.cpp b/ThunkLibs/libxcb-randr/libxcb-randr_interface.cpp index 4f00b4713..f8eb585ce 100644 --- a/ThunkLibs/libxcb-randr/libxcb-randr_interface.cpp +++ b/ThunkLibs/libxcb-randr/libxcb-randr_interface.cpp @@ -1,12 +1,23 @@ #include #include +#include template struct fex_gen_config { unsigned version = 0; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + +// Union type (includes pointers, so only compatible across 64-bit architectures) +#ifndef IS_32BIT_THUNK +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; +#endif + void FEX_xcb_randr_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxcb-shm/libxcb-shm_interface.cpp b/ThunkLibs/libxcb-shm/libxcb-shm_interface.cpp index 246c0abee..9b61d0570 100644 --- a/ThunkLibs/libxcb-shm/libxcb-shm_interface.cpp +++ b/ThunkLibs/libxcb-shm/libxcb-shm_interface.cpp @@ -1,12 +1,18 @@ #include #include +#include template struct fex_gen_config { unsigned version = 0; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + void FEX_xcb_shm_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxcb-sync/libxcb-sync_interface.cpp b/ThunkLibs/libxcb-sync/libxcb-sync_interface.cpp index e810ec019..5fe072f76 100644 --- a/ThunkLibs/libxcb-sync/libxcb-sync_interface.cpp +++ b/ThunkLibs/libxcb-sync/libxcb-sync_interface.cpp @@ -1,12 +1,18 @@ #include #include +#include template struct fex_gen_config { unsigned version = 1; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + void FEX_xcb_sync_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxcb-xfixes/libxcb-xfixes_interface.cpp b/ThunkLibs/libxcb-xfixes/libxcb-xfixes_interface.cpp index 3f5c9c1fc..947da6c19 100644 --- a/ThunkLibs/libxcb-xfixes/libxcb-xfixes_interface.cpp +++ b/ThunkLibs/libxcb-xfixes/libxcb-xfixes_interface.cpp @@ -1,12 +1,18 @@ #include #include +#include template struct fex_gen_config { unsigned version = 0; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + void FEX_xcb_xfixes_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxcb/libxcb_interface.cpp b/ThunkLibs/libxcb/libxcb_interface.cpp index feeff4940..ede74e44b 100644 --- a/ThunkLibs/libxcb/libxcb_interface.cpp +++ b/ThunkLibs/libxcb/libxcb_interface.cpp @@ -11,6 +11,15 @@ struct fex_gen_config { unsigned version = 1; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; +template<> struct fex_gen_type : fexgen::opaque_type {}; + +// Union type with consistent data layout across host/x86/x86-64 +template<> struct fex_gen_type : fexgen::assume_compatible_data_layout {}; + void FEX_xcb_init_extension(xcb_connection_t*, xcb_extension_t*); size_t FEX_usable_size(void*); void FEX_free_on_host(void*); diff --git a/ThunkLibs/libxshmfence/libxshmfence_interface.cpp b/ThunkLibs/libxshmfence/libxshmfence_interface.cpp index cf396ef6d..5b2433da4 100644 --- a/ThunkLibs/libxshmfence/libxshmfence_interface.cpp +++ b/ThunkLibs/libxshmfence/libxshmfence_interface.cpp @@ -9,6 +9,11 @@ struct fex_gen_config { unsigned version = 1; }; +template +struct fex_gen_type {}; + +template<> struct fex_gen_type : fexgen::opaque_type {}; + template<> struct fex_gen_config {}; template<> struct fex_gen_config {}; template<> struct fex_gen_config {};