winecrt0: Add a helper function and macro to simplify Unix library usage.

This commit is contained in:
Alexandre Julliard 2022-11-24 10:25:52 +01:00
parent ed510dd900
commit 1d036c0493
2 changed files with 30 additions and 3 deletions

View file

@ -18,8 +18,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifdef __WINE_PE_BUILD
#include <stdarg.h>
#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 );
}

View file

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