Module: wine Branch: master Commit: 7c0b3a408c75e6760f2e4e9b76e8ba007e95986d URL: https://gitlab.winehq.org/wine/wine/-/commit/7c0b3a408c75e6760f2e4e9b76e8ba0...
Author: Alexandre Julliard julliard@winehq.org Date: Fri Nov 25 10:23:38 2022 +0100
winecrt0: Call __wine_unix_call through an explicit pointer in the helper macro.
---
dlls/winecrt0/unix_lib.c | 45 +++++++++++++++------------------------------ dlls/winevulkan/loader.c | 7 ++++--- include/wine/unixlib.h | 3 ++- 3 files changed, 21 insertions(+), 34 deletions(-)
diff --git a/dlls/winecrt0/unix_lib.c b/dlls/winecrt0/unix_lib.c index 10be32899ba..1c8e2117dd0 100644 --- a/dlls/winecrt0/unix_lib.c +++ b/dlls/winecrt0/unix_lib.c @@ -27,34 +27,6 @@ #include "winternl.h" #include "wine/unixlib.h"
-#ifdef __WINE_PE_BUILD - -static NTSTATUS (WINAPI *p__wine_unix_call)( unixlib_handle_t, unsigned int, void * ); - -static void load_func( void **func, const char *name, void *def ) -{ - if (!*func) - { - HMODULE module = GetModuleHandleW( L"ntdll.dll" ); - void *proc = GetProcAddress( module, name ); - InterlockedExchangePointer( func, proc ? proc : def ); - } -} -#define LOAD_FUNC(name) load_func( (void **)&p ## name, #name, fallback ## name ) - -static NTSTATUS __cdecl fallback__wine_unix_call( unixlib_handle_t handle, unsigned int code, void *args ) -{ - return STATUS_DLL_NOT_FOUND; -} - -NTSTATUS WINAPI __wine_unix_call( unixlib_handle_t handle, unsigned int code, void *args ) -{ - LOAD_FUNC( __wine_unix_call ); - return p__wine_unix_call( handle, code, args ); -} - -#endif /* __WINE_PE_BUILD */ - static inline void *image_base(void) { #ifdef __WINE_PE_BUILD @@ -66,10 +38,23 @@ static inline void *image_base(void) #endif }
+static NTSTATUS WINAPI unix_call_fallback( unixlib_handle_t handle, unsigned int code, void *args ) +{ + return STATUS_DLL_NOT_FOUND; +} + unixlib_handle_t __wine_unixlib_handle = 0; +NTSTATUS (WINAPI *__wine_unix_call_ptr)( unixlib_handle_t, unsigned int, void * ) = unix_call_fallback;
NTSTATUS WINAPI __wine_init_unix_call(void) { - return NtQueryVirtualMemory( GetCurrentProcess(), image_base(), MemoryWineUnixFuncs, - &__wine_unixlib_handle, sizeof(__wine_unixlib_handle), NULL ); + NTSTATUS status; + HMODULE module = GetModuleHandleW( L"ntdll.dll" ); + void *proc = GetProcAddress( module, "__wine_unix_call" ); + + if (!proc) return STATUS_DLL_NOT_FOUND; + status = NtQueryVirtualMemory( GetCurrentProcess(), image_base(), MemoryWineUnixFuncs, + &__wine_unixlib_handle, sizeof(__wine_unixlib_handle), NULL ); + if (!status) __wine_unix_call_ptr = proc; + return status; } diff --git a/dlls/winevulkan/loader.c b/dlls/winevulkan/loader.c index 6714502e428..f168e824ae8 100644 --- a/dlls/winevulkan/loader.c +++ b/dlls/winevulkan/loader.c @@ -35,7 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(vulkan); DEFINE_DEVPROPKEY(DEVPROPKEY_GPU_LUID, 0x60b193cb, 0x5276, 0x4d0f, 0x96, 0xfc, 0xf1, 0x73, 0xab, 0xad, 0x3e, 0xc6, 2); DEFINE_DEVPROPKEY(WINE_DEVPROPKEY_GPU_VULKAN_UUID, 0x233a9ef3, 0xafc4, 0x4abd, 0xb5, 0x64, 0xc3, 0x2f, 0x21, 0xf1, 0x53, 0x5c, 2);
-NTSTATUS (WINAPI *p_vk_direct_unix_call)(unixlib_handle_t handle, unsigned int code, void *args) = __wine_unix_call; +NTSTATUS (WINAPI *p_vk_direct_unix_call)(unixlib_handle_t handle, unsigned int code, void *args) = NULL;
static HINSTANCE hinstance;
@@ -234,9 +234,10 @@ VkResult WINAPI vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *supported_ver
static BOOL WINAPI wine_vk_init(INIT_ONCE *once, void *param, void **context) { - if (__wine_init_unix_call()) - return FALSE; + NTSTATUS status = __wine_init_unix_call();
+ p_vk_direct_unix_call = __wine_unix_call_ptr; + if (status) return FALSE; return !vk_unix_call(unix_init, &p_vk_direct_unix_call); }
diff --git a/include/wine/unixlib.h b/include/wine/unixlib.h index fcb25422524..977dabc77f3 100644 --- a/include/wine/unixlib.h +++ b/include/wine/unixlib.h @@ -268,9 +268,10 @@ static inline ULONG ntdll_wcstoul( const WCHAR *s, WCHAR **end, int base ) #else /* WINE_UNIX_LIB */
extern unixlib_handle_t __wine_unixlib_handle DECLSPEC_HIDDEN; +extern NTSTATUS (WINAPI *__wine_unix_call_ptr)( unixlib_handle_t, unsigned int, void * ) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI __wine_init_unix_call(void) DECLSPEC_HIDDEN;
-#define WINE_UNIX_CALL(code,args) __wine_unix_call( __wine_unixlib_handle, (code), (args) ) +#define WINE_UNIX_CALL(code,args) __wine_unix_call_ptr( __wine_unixlib_handle, (code), (args) )
#endif /* WINE_UNIX_LIB */