winecrt0: Call __wine_unix_call through an explicit pointer in the helper macro.

This commit is contained in:
Alexandre Julliard 2022-11-25 10:23:38 +01:00
parent 12a129586b
commit 7c0b3a408c
3 changed files with 21 additions and 34 deletions

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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 */