ntdll: Remove __wine_init_unix_lib() and the old Unix library interface.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-12-09 10:43:56 +01:00
parent 2aa9c52196
commit 4f58d8144c
8 changed files with 9 additions and 197 deletions

View File

@ -3041,24 +3041,6 @@ done:
}
/***********************************************************************
* __wine_init_unix_lib
*/
NTSTATUS __cdecl __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
{
WINE_MODREF *wm;
NTSTATUS ret;
RtlEnterCriticalSection( &loader_section );
if ((wm = get_modref( module ))) ret = unix_funcs->init_unix_lib( module, reason, ptr_in, ptr_out );
else ret = STATUS_INVALID_HANDLE;
RtlLeaveCriticalSection( &loader_section );
return ret;
}
/***********************************************************************
* __wine_ctrl_routine
*/
@ -4450,11 +4432,6 @@ static void CDECL init_builtin_dll_fallback( void *module )
{
}
static NTSTATUS CDECL init_unix_lib_fallback( void *module, DWORD reason, const void *ptr_in, void *ptr_out )
{
return STATUS_DLL_NOT_FOUND;
}
static NTSTATUS CDECL unwind_builtin_dll_fallback( ULONG type, struct _DISPATCHER_CONTEXT *dispatch,
CONTEXT *context )
{
@ -4472,7 +4449,6 @@ static const struct unix_funcs unix_fallbacks =
{
load_so_dll_fallback,
init_builtin_dll_fallback,
init_unix_lib_fallback,
unwind_builtin_dll_fallback,
RtlGetSystemTimePrecise_fallback,
};

View File

@ -1633,7 +1633,6 @@
@ stdcall -syscall __wine_unix_call(int64 long ptr)
@ stdcall -syscall __wine_unix_spawnvp(long ptr)
@ cdecl __wine_set_unix_funcs(long ptr)
@ cdecl __wine_init_unix_lib(long long ptr ptr)
@ stdcall __wine_ctrl_routine(ptr)
@ extern __wine_syscall_dispatcher
@ extern -arch=i386 __wine_ldt_copy

View File

@ -1019,21 +1019,6 @@ static ULONG_PTR find_named_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY
return 0;
}
static ULONG_PTR find_pe_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
const IMAGE_IMPORT_BY_NAME *name )
{
const WORD *ordinals = (const WORD *)((BYTE *)module + exports->AddressOfNameOrdinals);
const DWORD *names = (const DWORD *)((BYTE *)module + exports->AddressOfNames);
if (name->Hint < exports->NumberOfNames)
{
char *ename = (char *)module + names[name->Hint];
if (!strcmp( ename, (char *)name->Name ))
return find_ordinal_export( module, exports, ordinals[name->Hint] );
}
return find_named_export( module, exports, (char *)name->Name );
}
static inline void *get_rva( void *module, ULONG_PTR addr )
{
return (BYTE *)module + addr;
@ -1055,49 +1040,6 @@ static const void *get_module_data_dir( HMODULE module, ULONG dir, ULONG *size )
return get_rva( module, data->VirtualAddress );
}
static NTSTATUS fixup_ntdll_imports( const char *name, HMODULE module )
{
const IMAGE_IMPORT_DESCRIPTOR *descr;
const IMAGE_THUNK_DATA *import_list;
IMAGE_THUNK_DATA *thunk_list;
if (!(descr = get_module_data_dir( module, IMAGE_FILE_IMPORT_DIRECTORY, NULL ))) return STATUS_SUCCESS;
for (; descr->Name && descr->FirstThunk; descr++)
{
thunk_list = get_rva( module, descr->FirstThunk );
/* ntdll must be the only import */
if (strcmp( get_rva( module, descr->Name ), "ntdll.dll" ))
{
ERR( "module %s is importing %s\n", debugstr_a(name), (char *)get_rva( module, descr->Name ));
return STATUS_PROCEDURE_NOT_FOUND;
}
if (descr->u.OriginalFirstThunk)
import_list = get_rva( module, descr->u.OriginalFirstThunk );
else
import_list = thunk_list;
while (import_list->u1.Ordinal)
{
if (IMAGE_SNAP_BY_ORDINAL( import_list->u1.Ordinal ))
{
int ordinal = IMAGE_ORDINAL( import_list->u1.Ordinal ) - ntdll_exports->Base;
thunk_list->u1.Function = find_ordinal_export( ntdll_module, ntdll_exports, ordinal );
if (!thunk_list->u1.Function) ERR( "%s: ntdll.%u not found\n", debugstr_a(name), ordinal );
}
else /* import by name */
{
IMAGE_IMPORT_BY_NAME *pe_name = get_rva( module, import_list->u1.AddressOfData );
thunk_list->u1.Function = find_pe_export( ntdll_module, ntdll_exports, pe_name );
if (!thunk_list->u1.Function) ERR( "%s: ntdll.%s not found\n", debugstr_a(name), pe_name->Name );
}
import_list++;
thunk_list++;
}
}
return STATUS_SUCCESS;
}
static void load_ntdll_functions( HMODULE module )
{
ntdll_exports = get_module_data_dir( module, IMAGE_FILE_EXPORT_DIRECTORY, NULL );
@ -1384,38 +1326,6 @@ already_loaded:
}
/***********************************************************************
* init_unix_lib
*/
static NTSTATUS CDECL init_unix_lib( void *module, DWORD reason, const void *ptr_in, void *ptr_out )
{
NTSTATUS (CDECL *init_func)( HMODULE, DWORD, const void *, void * );
const IMAGE_NT_HEADERS *nt;
const char *name;
void *handle, *entry, *unix_module;
NTSTATUS status;
if ((status = get_builtin_unix_info( module, &name, &handle, &entry ))) return status;
if (!entry)
{
if (!name || !handle) return STATUS_DLL_NOT_FOUND;
if (!(nt = dlsym( handle, "__wine_spec_nt_header" )) ||
!(entry = dlsym( handle, "__wine_init_unix_lib" )))
return STATUS_INVALID_IMAGE_FORMAT;
TRACE( "loaded %s for %p\n", debugstr_a(name), module );
unix_module = (void *)((nt->OptionalHeader.ImageBase + 0xffff) & ~0xffff);
map_so_dll( nt, unix_module );
fixup_ntdll_imports( name, unix_module );
set_builtin_unix_entry( module, entry );
}
init_func = entry;
return init_func( module, reason, ptr_in, ptr_out );
}
/***********************************************************************
* ntdll_init_syscalls
*/
@ -1716,13 +1626,8 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T
done:
if (status >= 0 && ext)
{
void *handle;
strcpy( ext, ".so" );
if ((handle = dlopen( ptr, RTLD_NOW )))
{
if (set_builtin_unix_handle( *module, ptr, handle )) dlclose( handle );
}
load_builtin_unixlib( *module, ptr );
}
free( file );
return status;
@ -2158,7 +2063,6 @@ static struct unix_funcs unix_funcs =
{
load_so_dll,
init_builtin_dll,
init_unix_lib,
unwind_builtin_dll,
RtlGetSystemTimePrecise,
#ifdef __aarch64__

View File

@ -220,9 +220,7 @@ extern void virtual_fill_image_information( const pe_image_info_t *pe_info,
SECTION_IMAGE_INFORMATION *info ) DECLSPEC_HIDDEN;
extern void release_builtin_module( void *module ) DECLSPEC_HIDDEN;
extern void *get_builtin_so_handle( void *module ) DECLSPEC_HIDDEN;
extern NTSTATUS get_builtin_unix_info( void *module, const char **name, void **handle, void **entry ) DECLSPEC_HIDDEN;
extern NTSTATUS set_builtin_unix_handle( void *module, const char *name, void *handle ) DECLSPEC_HIDDEN;
extern NTSTATUS set_builtin_unix_entry( void *module, void *entry ) DECLSPEC_HIDDEN;
extern NTSTATUS load_builtin_unixlib( void *module, const char *name ) DECLSPEC_HIDDEN;
extern NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len ) DECLSPEC_HIDDEN;
extern void *get_native_context( CONTEXT *context ) DECLSPEC_HIDDEN;

View File

@ -102,9 +102,7 @@ struct builtin_module
unsigned int refcount;
void *handle;
void *module;
char *unix_name;
void *unix_handle;
void *unix_entry;
};
static struct list builtin_modules = LIST_INIT( builtin_modules );
@ -589,9 +587,7 @@ static void add_builtin_module( void *module, void *handle )
builtin->handle = handle;
builtin->module = module;
builtin->refcount = 1;
builtin->unix_name = NULL;
builtin->unix_handle = NULL;
builtin->unix_entry = NULL;
list_add_tail( &builtin_modules, &builtin->entry );
}
@ -611,7 +607,6 @@ void release_builtin_module( void *module )
list_remove( &builtin->entry );
if (builtin->handle) dlclose( builtin->handle );
if (builtin->unix_handle) dlclose( builtin->unix_handle );
free( builtin->unix_name );
free( builtin );
}
break;
@ -668,45 +663,22 @@ static NTSTATUS get_builtin_unix_funcs( void *module, BOOL wow, void **funcs )
/***********************************************************************
* get_builtin_unix_info
* load_builtin_unixlib
*/
NTSTATUS get_builtin_unix_info( void *module, const char **name, void **handle, void **entry )
{
sigset_t sigset;
NTSTATUS status = STATUS_DLL_NOT_FOUND;
struct builtin_module *builtin;
server_enter_uninterrupted_section( &virtual_mutex, &sigset );
LIST_FOR_EACH_ENTRY( builtin, &builtin_modules, struct builtin_module, entry )
{
if (builtin->module != module) continue;
*name = builtin->unix_name;
*handle = builtin->unix_handle;
*entry = builtin->unix_entry;
status = STATUS_SUCCESS;
break;
}
server_leave_uninterrupted_section( &virtual_mutex, &sigset );
return status;
}
/***********************************************************************
* set_builtin_unix_handle
*/
NTSTATUS set_builtin_unix_handle( void *module, const char *name, void *handle )
NTSTATUS load_builtin_unixlib( void *module, const char *name )
{
void *handle;
sigset_t sigset;
NTSTATUS status = STATUS_DLL_NOT_FOUND;
struct builtin_module *builtin;
if (!(handle = dlopen( name, RTLD_NOW ))) return status;
server_enter_uninterrupted_section( &virtual_mutex, &sigset );
LIST_FOR_EACH_ENTRY( builtin, &builtin_modules, struct builtin_module, entry )
{
if (builtin->module != module) continue;
if (!builtin->unix_handle)
{
builtin->unix_name = strdup( name );
builtin->unix_handle = handle;
status = STATUS_SUCCESS;
}
@ -714,31 +686,7 @@ NTSTATUS set_builtin_unix_handle( void *module, const char *name, void *handle )
break;
}
server_leave_uninterrupted_section( &virtual_mutex, &sigset );
return status;
}
/***********************************************************************
* set_builtin_unix_entry
*/
NTSTATUS set_builtin_unix_entry( void *module, void *entry )
{
sigset_t sigset;
NTSTATUS status = STATUS_DLL_NOT_FOUND;
struct builtin_module *builtin;
server_enter_uninterrupted_section( &virtual_mutex, &sigset );
LIST_FOR_EACH_ENTRY( builtin, &builtin_modules, struct builtin_module, entry )
{
if (builtin->module != module) continue;
if (builtin->unix_handle)
{
builtin->unix_entry = entry;
status = STATUS_SUCCESS;
}
break;
}
server_leave_uninterrupted_section( &virtual_mutex, &sigset );
if (status) dlclose( handle );
return status;
}

View File

@ -26,14 +26,13 @@
struct _DISPATCHER_CONTEXT;
/* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 133
#define NTDLL_UNIXLIB_VERSION 134
struct unix_funcs
{
/* loader functions */
NTSTATUS (CDECL *load_so_dll)( UNICODE_STRING *nt_name, void **module );
void (CDECL *init_builtin_dll)( void *module );
NTSTATUS (CDECL *init_unix_lib)( void *module, DWORD reason, const void *ptr_in, void *ptr_out );
NTSTATUS (CDECL *unwind_builtin_dll)( ULONG type, struct _DISPATCHER_CONTEXT *dispatch,
CONTEXT *context );
/* other Win32 API functions */

View File

@ -29,7 +29,6 @@
#include "winternl.h"
#include "wine/unixlib.h"
static NTSTATUS (__cdecl *p__wine_init_unix_lib)( HMODULE, DWORD, const void *, void * );
static NTSTATUS (WINAPI *p__wine_unix_call)( unixlib_handle_t, unsigned int, void * );
static void load_func( void **func, const char *name, void *def )
@ -43,22 +42,11 @@ static void load_func( void **func, const char *name, void *def )
}
#define LOAD_FUNC(name) load_func( (void **)&p ## name, #name, fallback ## name )
static NTSTATUS __cdecl fallback__wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
{
return STATUS_DLL_NOT_FOUND;
}
static NTSTATUS __cdecl fallback__wine_unix_call( unixlib_handle_t handle, unsigned int code, void *args )
{
return STATUS_DLL_NOT_FOUND;
}
NTSTATUS __cdecl __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
{
LOAD_FUNC( __wine_init_unix_lib );
return p__wine_init_unix_lib( module, reason, ptr_in, ptr_out );
}
NTSTATUS WINAPI __wine_unix_call( unixlib_handle_t handle, unsigned int code, void *args )
{
LOAD_FUNC( __wine_unix_call );

View File

@ -4680,7 +4680,7 @@ static inline PLIST_ENTRY RemoveTailList(PLIST_ENTRY le)
#ifdef __WINESRC__
/* Wine internal functions */
extern NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out );
extern NTSTATUS WINAPI __wine_unix_spawnvp( char * const argv[], int wait );
/* The thread information for 16-bit threads */