From 1d036c04930e449cfc374e52e9663ab8ecad0465 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 24 Nov 2022 10:25:52 +0100 Subject: [PATCH] winecrt0: Add a helper function and macro to simplify Unix library usage. --- dlls/winecrt0/unix_lib.c | 23 +++++++++++++++++++++-- include/wine/unixlib.h | 10 +++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dlls/winecrt0/unix_lib.c b/dlls/winecrt0/unix_lib.c index c86897b9905..10be32899ba 100644 --- a/dlls/winecrt0/unix_lib.c +++ b/dlls/winecrt0/unix_lib.c @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifdef __WINE_PE_BUILD - #include #include "ntstatus.h" @@ -29,6 +27,8 @@ #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 ) @@ -54,3 +54,22 @@ NTSTATUS WINAPI __wine_unix_call( unixlib_handle_t handle, unsigned int code, vo } #endif /* __WINE_PE_BUILD */ + +static inline void *image_base(void) +{ +#ifdef __WINE_PE_BUILD + extern IMAGE_DOS_HEADER __ImageBase; + return (void *)&__ImageBase; +#else + extern IMAGE_NT_HEADERS __wine_spec_nt_header; + return (void *)((__wine_spec_nt_header.OptionalHeader.ImageBase + 0xffff) & ~0xffff); +#endif +} + +unixlib_handle_t __wine_unixlib_handle = 0; + +NTSTATUS WINAPI __wine_init_unix_call(void) +{ + return NtQueryVirtualMemory( GetCurrentProcess(), image_base(), MemoryWineUnixFuncs, + &__wine_unixlib_handle, sizeof(__wine_unixlib_handle), NULL ); +} diff --git a/include/wine/unixlib.h b/include/wine/unixlib.h index ef60b32184c..fcb25422524 100644 --- a/include/wine/unixlib.h +++ b/include/wine/unixlib.h @@ -21,13 +21,14 @@ #ifndef __WINE_WINE_UNIXLIB_H #define __WINE_WINE_UNIXLIB_H -typedef NTSTATUS (*unixlib_entry_t)( void *args ); typedef UINT64 unixlib_handle_t; extern NTSTATUS WINAPI __wine_unix_call( unixlib_handle_t handle, unsigned int code, void *args ); #ifdef WINE_UNIX_LIB +typedef NTSTATUS (*unixlib_entry_t)( void *args ); + /* some useful helpers from ntdll */ extern const char *ntdll_get_build_dir(void); extern const char *ntdll_get_data_dir(void); @@ -264,6 +265,13 @@ static inline ULONG ntdll_wcstoul( const WCHAR *s, WCHAR **end, int base ) #define wcstol(str,e,b) ntdll_wcstol(str,e,b) #define wcstoul(str,e,b) ntdll_wcstoul(str,e,b) +#else /* WINE_UNIX_LIB */ + +extern unixlib_handle_t __wine_unixlib_handle 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) ) + #endif /* WINE_UNIX_LIB */ #endif /* __WINE_WINE_UNIXLIB_H */