Revert "ntdll: Add a Wine-specific class in NtQueryVirtualMemory to retrieve the init functions of a module."

This reverts commits e5339ecbc6 and
18408b18f3.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51596
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-09-10 20:09:38 +02:00
parent ed5c882975
commit e9cfc97d46
7 changed files with 23 additions and 63 deletions

View File

@ -1338,31 +1338,6 @@ static void call_tls_callbacks( HMODULE module, UINT reason )
}
}
/*************************************************************************
* init_builtin_dll
*/
static void init_builtin_dll( HMODULE module )
{
void *buffer[16];
void (**funcs)(int, char **, char **) = (void *)buffer;
SIZE_T i, size;
NTSTATUS status;
status = NtQueryVirtualMemory( GetCurrentProcess(), module, MemoryWineImageInitFuncs,
buffer, sizeof(buffer), &size );
if (status == STATUS_BUFFER_TOO_SMALL)
{
if (!(funcs = RtlAllocateHeap( GetProcessHeap(), 0, size ))) return;
status = NtQueryVirtualMemory( GetCurrentProcess(), module, MemoryWineImageInitFuncs,
funcs, size, &size );
}
if (!status) for (i = 0; i < size / sizeof(*funcs); i++) funcs[i]( 0, NULL, NULL );
if ((void *)funcs != (void *)buffer) RtlFreeHeap( GetProcessHeap(), 0, funcs );
}
/*************************************************************************
* MODULE_InitDLL
*/
@ -1379,7 +1354,7 @@ static NTSTATUS MODULE_InitDLL( WINE_MODREF *wm, UINT reason, LPVOID lpReserved
if (wm->ldr.Flags & LDR_DONT_RESOLVE_REFS) return STATUS_SUCCESS;
if (wm->ldr.TlsIndex != -1) call_tls_callbacks( wm->ldr.DllBase, reason );
if (wm->ldr.Flags & LDR_WINE_INTERNAL && reason == DLL_PROCESS_ATTACH)
init_builtin_dll( wm->ldr.DllBase );
unix_funcs->init_builtin_dll( wm->ldr.DllBase );
if (!entry) return STATUS_SUCCESS;
if (TRACE_ON(relay))
@ -3917,7 +3892,7 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR
}
release_address_space();
if (wm->ldr.TlsIndex != -1) call_tls_callbacks( wm->ldr.DllBase, DLL_PROCESS_ATTACH );
if (wm->ldr.Flags & LDR_WINE_INTERNAL) init_builtin_dll( wm->ldr.DllBase );
if (wm->ldr.Flags & LDR_WINE_INTERNAL) unix_funcs->init_builtin_dll( wm->ldr.DllBase );
if (wm->ldr.ActivationContext) RtlDeactivateActivationContext( 0, cookie );
process_breakpoint();
}

View File

@ -1975,21 +1975,26 @@ static BOOL get_relocbase(caddr_t mapbase, caddr_t *relocbase)
#endif
/*************************************************************************
* get_builtin_init_funcs
* init_builtin_dll
*/
NTSTATUS get_builtin_init_funcs( void *handle, void **funcs, SIZE_T len, SIZE_T *retlen )
static void CDECL init_builtin_dll( void *module )
{
#ifdef HAVE_DLINFO
void *handle = NULL;
struct link_map *map;
void *init_func = NULL, **init_array = NULL;
ULONG_PTR i, count, init_arraysz = 0;
void (*init_func)(int, char **, char **) = NULL;
void (**init_array)(int, char **, char **) = NULL;
ULONG_PTR i, init_arraysz = 0;
#ifdef _WIN64
const Elf64_Dyn *dyn;
#else
const Elf32_Dyn *dyn;
#endif
if (dlinfo( handle, RTLD_DI_LINKMAP, &map )) return STATUS_INVALID_IMAGE_FORMAT;
if (!(handle = get_builtin_so_handle( module ))) return;
if (dlinfo( handle, RTLD_DI_LINKMAP, &map )) map = NULL;
release_builtin_module( module );
if (!map) return;
for (dyn = map->l_ld; dyn->d_tag; dyn++)
{
@ -2009,18 +2014,13 @@ NTSTATUS get_builtin_init_funcs( void *handle, void **funcs, SIZE_T len, SIZE_T
}
}
TRACE( "%p: got init_func %p init_array %p %lu\n", handle, init_func, init_array, init_arraysz );
TRACE( "%p: got init_func %p init_array %p %lu\n", module, init_func, init_array, init_arraysz );
count = init_arraysz / sizeof(*init_array);
if (init_func) count++;
if (retlen) *retlen = count * sizeof(*funcs);
if (init_func) init_func( main_argc, main_argv, main_envp );
if (count > len / sizeof(*funcs)) return STATUS_BUFFER_TOO_SMALL;
if (init_func) *funcs++ = init_func;
for (i = 0; i < init_arraysz / sizeof(*init_array); i++) funcs[i] = init_array[i];
return STATUS_SUCCESS;
#else
return STATUS_NOT_SUPPORTED;
if (init_array)
for (i = 0; i < init_arraysz / sizeof(*init_array); i++)
init_array[i]( main_argc, main_argv, main_envp );
#endif
}
@ -2172,6 +2172,7 @@ static struct unix_funcs unix_funcs =
ntdll_sqrt,
ntdll_tan,
load_so_dll,
init_builtin_dll,
init_unix_lib,
unwind_builtin_dll,
};

View File

@ -164,7 +164,6 @@ extern BOOL is_builtin_path( const UNICODE_STRING *path, WORD *machine ) DECLSPE
extern NTSTATUS load_main_exe( const WCHAR *name, const char *unix_name, const WCHAR *curdir, WCHAR **image,
void **module ) DECLSPEC_HIDDEN;
extern NTSTATUS load_start_exe( WCHAR **image, void **module ) DECLSPEC_HIDDEN;
extern NTSTATUS get_builtin_init_funcs( void *handle, void **funcs, SIZE_T len, SIZE_T *retlen ) DECLSPEC_HIDDEN;
extern void start_server( BOOL debug ) DECLSPEC_HIDDEN;
extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;
@ -232,6 +231,7 @@ extern void virtual_set_force_exec( BOOL enable ) DECLSPEC_HIDDEN;
extern void virtual_set_large_address_space(void) DECLSPEC_HIDDEN;
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;

View File

@ -615,7 +615,7 @@ static void add_builtin_module( void *module, void *handle )
/***********************************************************************
* release_builtin_module
*/
static void release_builtin_module( void *module )
void release_builtin_module( void *module )
{
struct builtin_module *builtin;
@ -4329,21 +4329,6 @@ NTSTATUS WINAPI NtQueryVirtualMemory( HANDLE process, LPCVOID addr,
case MemoryMappedFilenameInformation:
return get_memory_section_name( process, addr, buffer, len, res_len );
case MemoryWineImageInitFuncs:
if (process == GetCurrentProcess())
{
void *module = (void *)addr;
void *handle = get_builtin_so_handle( module );
if (handle)
{
status = get_builtin_init_funcs( handle, buffer, len, res_len );
release_builtin_module( module );
return status;
}
}
return STATUS_INVALID_HANDLE;
case MemoryWineUnixFuncs:
case MemoryWineUnixWow64Funcs:
if (len != sizeof(unixlib_handle_t)) return STATUS_INFO_LENGTH_MISMATCH;

View File

@ -26,7 +26,7 @@
struct _DISPATCHER_CONTEXT;
/* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 125
#define NTDLL_UNIXLIB_VERSION 126
struct unix_funcs
{
@ -71,6 +71,7 @@ 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 );

View File

@ -369,7 +369,6 @@ NTSTATUS WINAPI wow64_NtQueryVirtualMemory( UINT *args )
break;
}
case MemoryWineImageInitFuncs:
case MemoryWineUnixWow64Funcs:
return STATUS_INVALID_INFO_CLASS;

View File

@ -1919,8 +1919,7 @@ typedef enum _MEMORY_INFORMATION_CLASS {
MemoryBasicInformationCapped,
MemoryPhysicalContiguityInformation,
#ifdef __WINESRC__
MemoryWineImageInitFuncs = 1000,
MemoryWineUnixFuncs,
MemoryWineUnixFuncs = 1000,
MemoryWineUnixWow64Funcs,
#endif
} MEMORY_INFORMATION_CLASS;