Alexandre Julliard : Revert "ntdll: Add a Wine-specific class in NtQueryVirtualMemory to retrieve the init functions of a module."
Alexandre Julliard
julliard at winehq.org
Fri Sep 10 15:29:45 CDT 2021
Module: wine
Branch: master
Commit: e9cfc97d46aaf39bc9c2a41b319d3b3b358c0f04
URL: https://source.winehq.org/git/wine.git/?a=commit;h=e9cfc97d46aaf39bc9c2a41b319d3b3b358c0f04
Author: Alexandre Julliard <julliard at winehq.org>
Date: Fri Sep 10 20:09:38 2021 +0200
Revert "ntdll: Add a Wine-specific class in NtQueryVirtualMemory to retrieve the init functions of a module."
This reverts commits e5339ecbc66f20193a0a6b1dfdce98d42d2ad926 and
18408b18f3ebd9630a02f0bd16864f5e5118b71a.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51596
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/loader.c | 29 ++---------------------------
dlls/ntdll/unix/loader.c | 31 ++++++++++++++++---------------
dlls/ntdll/unix/unix_private.h | 2 +-
dlls/ntdll/unix/virtual.c | 17 +----------------
dlls/ntdll/unixlib.h | 3 ++-
dlls/wow64/virtual.c | 1 -
include/winternl.h | 3 +--
7 files changed, 23 insertions(+), 63 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 48e826fe888..819cf51b9fc 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -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();
}
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
index b15824346b7..defa61909a1 100644
--- a/dlls/ntdll/unix/loader.c
+++ b/dlls/ntdll/unix/loader.c
@@ -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,
};
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index b2bcd423d4b..fb1a4a397e9 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -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;
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 8a1e35b6387..984af2d4a21 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -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;
diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h
index f22e0c12d22..4b7c8b45be7 100644
--- a/dlls/ntdll/unixlib.h
+++ b/dlls/ntdll/unixlib.h
@@ -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 );
diff --git a/dlls/wow64/virtual.c b/dlls/wow64/virtual.c
index e5759609974..f4cd50d0ea2 100644
--- a/dlls/wow64/virtual.c
+++ b/dlls/wow64/virtual.c
@@ -369,7 +369,6 @@ NTSTATUS WINAPI wow64_NtQueryVirtualMemory( UINT *args )
break;
}
- case MemoryWineImageInitFuncs:
case MemoryWineUnixWow64Funcs:
return STATUS_INVALID_INFO_CLASS;
diff --git a/include/winternl.h b/include/winternl.h
index fea9e9df117..798127aee90 100644
--- a/include/winternl.h
+++ b/include/winternl.h
@@ -1919,8 +1919,7 @@ typedef enum _MEMORY_INFORMATION_CLASS {
MemoryBasicInformationCapped,
MemoryPhysicalContiguityInformation,
#ifdef __WINESRC__
- MemoryWineImageInitFuncs = 1000,
- MemoryWineUnixFuncs,
+ MemoryWineUnixFuncs = 1000,
MemoryWineUnixWow64Funcs,
#endif
} MEMORY_INFORMATION_CLASS;
More information about the wine-cvs
mailing list