2002-03-10 00:29:33 +01:00
|
|
|
/*
|
2003-03-20 05:55:59 +01:00
|
|
|
* Loader functions
|
|
|
|
*
|
2003-04-05 07:16:11 +02:00
|
|
|
* Copyright 1995, 2003 Alexandre Julliard
|
2003-09-08 21:38:45 +02:00
|
|
|
* Copyright 2002 Dmitry Timoshkov for CodeWeavers
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
|
|
|
|
2003-11-27 01:59:36 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-03-18 19:29:13 +01:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2020-04-16 12:22:24 +02:00
|
|
|
#ifdef HAVE_LINK_H
|
|
|
|
# include <link.h>
|
|
|
|
#endif
|
2008-03-26 17:08:38 +01:00
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
# include <sys/mman.h>
|
|
|
|
#endif
|
2003-03-18 19:29:13 +01:00
|
|
|
|
2020-04-17 13:53:20 +02:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
# include <mach-o/getsect.h>
|
|
|
|
#endif
|
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2015-03-14 03:38:17 +01:00
|
|
|
#define NONAMELESSUNION
|
2020-04-16 10:26:13 +02:00
|
|
|
#define NONAMELESSSTRUCT
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-01-29 19:30:16 +01:00
|
|
|
#include "winnt.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2013-11-11 23:20:41 +01:00
|
|
|
#include "delayloadhandler.h"
|
2002-06-10 04:28:00 +02:00
|
|
|
|
2002-08-16 00:09:53 +02:00
|
|
|
#include "wine/exception.h"
|
2005-05-18 20:27:54 +02:00
|
|
|
#include "wine/library.h"
|
2002-06-10 04:28:00 +02:00
|
|
|
#include "wine/debug.h"
|
2018-06-22 03:54:56 +02:00
|
|
|
#include "wine/list.h"
|
2003-03-14 05:00:52 +01:00
|
|
|
#include "wine/server.h"
|
|
|
|
#include "ntdll_misc.h"
|
2007-05-18 18:09:03 +02:00
|
|
|
#include "ddk/wdm.h"
|
2002-06-10 04:28:00 +02:00
|
|
|
|
2003-04-04 21:50:17 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(module);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
2003-04-05 07:16:11 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(snoop);
|
2003-03-14 05:00:52 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(loaddll);
|
2005-05-18 11:51:46 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(imports);
|
2003-03-14 05:00:52 +01:00
|
|
|
|
2015-08-10 18:31:56 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
#define DEFAULT_SECURITY_COOKIE_64 (((ULONGLONG)0x00002b99 << 32) | 0x2ddfa232)
|
|
|
|
#endif
|
|
|
|
#define DEFAULT_SECURITY_COOKIE_32 0xbb40e64e
|
|
|
|
#define DEFAULT_SECURITY_COOKIE_16 (DEFAULT_SECURITY_COOKIE_32 >> 16)
|
|
|
|
|
2007-07-25 16:50:32 +02:00
|
|
|
/* we don't want to include winuser.h */
|
|
|
|
#define RT_MANIFEST ((ULONG_PTR)24)
|
|
|
|
#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID ((ULONG_PTR)2)
|
|
|
|
|
2003-04-04 21:50:17 +02:00
|
|
|
typedef DWORD (CALLBACK *DLLENTRYPROC)(HMODULE,DWORD,LPVOID);
|
2017-04-28 17:59:41 +02:00
|
|
|
typedef void (CALLBACK *LDRENUMPROC)(LDR_MODULE *, void *, BOOLEAN *);
|
2003-04-04 21:50:17 +02:00
|
|
|
|
2018-02-19 19:38:29 +01:00
|
|
|
/* system directory with trailing backslash */
|
|
|
|
const WCHAR system_dir[] = {'C',':','\\','w','i','n','d','o','w','s','\\',
|
|
|
|
's','y','s','t','e','m','3','2','\\',0};
|
2019-10-22 10:15:28 +02:00
|
|
|
const WCHAR syswow64_dir[] = {'C',':','\\','w','i','n','d','o','w','s','\\',
|
|
|
|
's','y','s','w','o','w','6','4','\\',0};
|
2018-02-19 19:38:29 +01:00
|
|
|
|
2019-10-01 09:33:52 +02:00
|
|
|
/* system search path */
|
|
|
|
static const WCHAR system_path[] =
|
|
|
|
{'C',':','\\','w','i','n','d','o','w','s','\\','s','y','s','t','e','m','3','2',';',
|
|
|
|
'C',':','\\','w','i','n','d','o','w','s','\\','s','y','s','t','e','m',';',
|
2019-10-03 14:14:36 +02:00
|
|
|
'C',':','\\','w','i','n','d','o','w','s',0};
|
|
|
|
|
|
|
|
static const WCHAR dotW[] = {'.',0};
|
2019-10-01 09:33:52 +02:00
|
|
|
|
2017-11-20 17:09:29 +01:00
|
|
|
static BOOL imports_fixup_done = FALSE; /* set once the imports have been fixed up, before attaching them */
|
2013-11-02 14:34:13 +01:00
|
|
|
static BOOL process_detaching = FALSE; /* set on process detach to avoid deadlocks with thread detach */
|
2003-03-18 19:29:13 +01:00
|
|
|
static int free_lib_count; /* recursion depth of LdrUnloadDll calls */
|
2019-10-01 09:32:46 +02:00
|
|
|
static ULONG path_safe_mode; /* path mode set by RtlSetSearchPathMode */
|
2019-10-03 14:14:36 +02:00
|
|
|
static ULONG dll_safe_mode = 1; /* dll search mode */
|
2019-10-01 13:59:51 +02:00
|
|
|
static UNICODE_STRING dll_directory; /* extra path for LdrSetDllDirectory */
|
2019-10-03 14:14:36 +02:00
|
|
|
static DWORD default_search_flags; /* default flags set by LdrSetDefaultDllDirectories */
|
|
|
|
|
|
|
|
struct dll_dir_entry
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
WCHAR dir[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct list dll_dir_list = LIST_INIT( dll_dir_list ); /* extra dirs from LdrAddDllDirectory */
|
2002-01-29 19:30:16 +01:00
|
|
|
|
2018-06-22 03:54:56 +02:00
|
|
|
struct ldr_notification
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
PLDR_DLL_NOTIFICATION_FUNCTION callback;
|
|
|
|
void *context;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct list ldr_notifications = LIST_INIT( ldr_notifications );
|
|
|
|
|
2003-05-08 06:13:26 +02:00
|
|
|
static const char * const reason_names[] =
|
|
|
|
{
|
|
|
|
"PROCESS_DETACH",
|
|
|
|
"PROCESS_ATTACH",
|
|
|
|
"THREAD_ATTACH",
|
2006-03-21 15:10:22 +01:00
|
|
|
"THREAD_DETACH",
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
"WINE_PREATTACH"
|
2003-05-08 06:13:26 +02:00
|
|
|
};
|
|
|
|
|
2003-09-26 01:55:35 +02:00
|
|
|
static const WCHAR dllW[] = {'.','d','l','l',0};
|
|
|
|
|
|
|
|
/* internal representation of 32bit modules. per process. */
|
2003-10-06 23:18:51 +02:00
|
|
|
typedef struct _wine_modref
|
2003-09-26 01:55:35 +02:00
|
|
|
{
|
|
|
|
LDR_MODULE ldr;
|
2018-02-28 10:11:55 +01:00
|
|
|
dev_t dev;
|
|
|
|
ino_t ino;
|
2020-04-16 12:00:43 +02:00
|
|
|
void *so_handle;
|
2018-03-14 14:47:25 +01:00
|
|
|
int alloc_deps;
|
2003-09-26 01:55:35 +02:00
|
|
|
int nDeps;
|
|
|
|
struct _wine_modref **deps;
|
2003-10-06 23:18:51 +02:00
|
|
|
} WINE_MODREF;
|
2003-09-26 01:55:35 +02:00
|
|
|
|
2003-10-08 00:56:34 +02:00
|
|
|
/* info about the current builtin dll load */
|
|
|
|
/* used to keep track of things across the register_dll constructor call */
|
|
|
|
struct builtin_load_info
|
|
|
|
{
|
2019-02-08 12:49:47 +01:00
|
|
|
const WCHAR *load_path;
|
|
|
|
const UNICODE_STRING *filename;
|
|
|
|
NTSTATUS status;
|
|
|
|
WINE_MODREF *wm;
|
2003-10-08 00:56:34 +02:00
|
|
|
};
|
|
|
|
|
2003-10-10 02:12:17 +02:00
|
|
|
static struct builtin_load_info default_load_info;
|
|
|
|
static struct builtin_load_info *builtin_load_info = &default_load_info;
|
2003-10-08 00:56:34 +02:00
|
|
|
|
2003-05-14 21:51:14 +02:00
|
|
|
static UINT tls_module_count; /* number of modules with TLS directory */
|
2015-07-14 10:36:12 +02:00
|
|
|
static IMAGE_TLS_DIRECTORY *tls_dirs; /* array of TLS directories */
|
2013-12-23 18:16:51 +01:00
|
|
|
LIST_ENTRY tls_links = { &tls_links, &tls_links };
|
2003-05-14 21:51:14 +02:00
|
|
|
|
2005-06-25 20:00:57 +02:00
|
|
|
static RTL_CRITICAL_SECTION loader_section;
|
|
|
|
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
|
2003-08-13 01:50:54 +02:00
|
|
|
{
|
|
|
|
0, 0, &loader_section,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": loader_section") }
|
2003-08-13 01:50:54 +02:00
|
|
|
};
|
2005-06-25 20:00:57 +02:00
|
|
|
static RTL_CRITICAL_SECTION loader_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2003-08-13 01:50:54 +02:00
|
|
|
|
2019-10-01 13:59:51 +02:00
|
|
|
static CRITICAL_SECTION dlldir_section;
|
|
|
|
static CRITICAL_SECTION_DEBUG dlldir_critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &dlldir_section,
|
|
|
|
{ &dlldir_critsect_debug.ProcessLocksList, &dlldir_critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": dlldir_section") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION dlldir_section = { &dlldir_critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2003-04-05 07:16:11 +02:00
|
|
|
static WINE_MODREF *cached_modref;
|
2003-04-08 01:27:54 +02:00
|
|
|
static WINE_MODREF *current_modref;
|
2005-01-11 17:01:31 +01:00
|
|
|
static WINE_MODREF *last_failed_modref;
|
2003-04-05 07:16:11 +02:00
|
|
|
|
2019-11-07 18:54:21 +01:00
|
|
|
static NTSTATUS load_dll( const WCHAR *load_path, const WCHAR *libname, const WCHAR *default_ext,
|
|
|
|
DWORD flags, WINE_MODREF** pwm );
|
2007-12-06 21:40:37 +01:00
|
|
|
static NTSTATUS process_attach( WINE_MODREF *wm, LPVOID lpReserved );
|
2009-09-25 13:12:02 +02:00
|
|
|
static FARPROC find_ordinal_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
|
|
|
|
DWORD exp_size, DWORD ordinal, LPCWSTR load_path );
|
2004-06-15 02:47:00 +02:00
|
|
|
static FARPROC find_named_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
|
2007-12-06 21:40:37 +01:00
|
|
|
DWORD exp_size, const char *name, int hint, LPCWSTR load_path );
|
2003-04-05 07:16:11 +02:00
|
|
|
|
|
|
|
/* convert PE image VirtualAddress to Real Address */
|
2007-03-17 11:28:32 +01:00
|
|
|
static inline void *get_rva( HMODULE module, DWORD va )
|
2003-04-05 07:16:11 +02:00
|
|
|
{
|
|
|
|
return (void *)((char *)module + va);
|
|
|
|
}
|
2003-03-18 19:29:13 +01:00
|
|
|
|
2003-09-29 22:42:24 +02:00
|
|
|
/* check whether the file name contains a path */
|
2013-11-02 14:34:13 +01:00
|
|
|
static inline BOOL contains_path( LPCWSTR name )
|
2003-09-29 22:42:24 +02:00
|
|
|
{
|
2020-03-31 11:43:50 +02:00
|
|
|
return ((*name && (name[1] == ':')) || wcschr(name, '/') || wcschr(name, '\\'));
|
2003-09-29 22:42:24 +02:00
|
|
|
}
|
|
|
|
|
2019-04-23 07:47:30 +02:00
|
|
|
#define RTL_UNLOAD_EVENT_TRACE_NUMBER 64
|
|
|
|
|
|
|
|
typedef struct _RTL_UNLOAD_EVENT_TRACE
|
|
|
|
{
|
|
|
|
void *BaseAddress;
|
|
|
|
SIZE_T SizeOfImage;
|
|
|
|
ULONG Sequence;
|
|
|
|
ULONG TimeDateStamp;
|
|
|
|
ULONG CheckSum;
|
|
|
|
WCHAR ImageName[32];
|
|
|
|
} RTL_UNLOAD_EVENT_TRACE, *PRTL_UNLOAD_EVENT_TRACE;
|
|
|
|
|
|
|
|
static RTL_UNLOAD_EVENT_TRACE unload_traces[RTL_UNLOAD_EVENT_TRACE_NUMBER];
|
2020-04-02 10:40:45 +02:00
|
|
|
static RTL_UNLOAD_EVENT_TRACE *unload_trace_ptr;
|
2019-04-23 07:47:30 +02:00
|
|
|
static unsigned int unload_trace_seq;
|
|
|
|
|
|
|
|
static void module_push_unload_trace( const LDR_MODULE *ldr )
|
|
|
|
{
|
|
|
|
RTL_UNLOAD_EVENT_TRACE *ptr = &unload_traces[unload_trace_seq];
|
2019-04-30 11:26:26 +02:00
|
|
|
unsigned int len = min(sizeof(ptr->ImageName) - sizeof(WCHAR), ldr->BaseDllName.Length);
|
2019-04-23 07:47:30 +02:00
|
|
|
|
|
|
|
ptr->BaseAddress = ldr->BaseAddress;
|
|
|
|
ptr->SizeOfImage = ldr->SizeOfImage;
|
|
|
|
ptr->Sequence = unload_trace_seq;
|
|
|
|
ptr->TimeDateStamp = ldr->TimeDateStamp;
|
|
|
|
ptr->CheckSum = ldr->CheckSum;
|
|
|
|
memcpy(ptr->ImageName, ldr->BaseDllName.Buffer, len);
|
|
|
|
ptr->ImageName[len / sizeof(*ptr->ImageName)] = 0;
|
|
|
|
|
|
|
|
unload_trace_seq = (unload_trace_seq + 1) % ARRAY_SIZE(unload_traces);
|
2020-04-02 10:40:45 +02:00
|
|
|
unload_trace_ptr = unload_traces;
|
2019-04-23 07:47:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* RtlGetUnloadEventTrace [NTDLL.@]
|
|
|
|
*/
|
|
|
|
RTL_UNLOAD_EVENT_TRACE * WINAPI RtlGetUnloadEventTrace(void)
|
|
|
|
{
|
|
|
|
return unload_traces;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* RtlGetUnloadEventTraceEx [NTDLL.@]
|
|
|
|
*/
|
|
|
|
void WINAPI RtlGetUnloadEventTraceEx(ULONG **size, ULONG **count, void **trace)
|
|
|
|
{
|
|
|
|
static unsigned int element_size = sizeof(*unload_traces);
|
|
|
|
static unsigned int element_count = ARRAY_SIZE(unload_traces);
|
|
|
|
|
|
|
|
*size = &element_size;
|
|
|
|
*count = &element_count;
|
2020-04-02 10:40:45 +02:00
|
|
|
*trace = &unload_trace_ptr;
|
2019-04-23 07:47:30 +02:00
|
|
|
}
|
2004-03-19 03:07:16 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* call_dll_entry_point
|
|
|
|
*
|
|
|
|
* Some brain-damaged dlls (ir32_32.dll for instance) modify ebx in
|
2014-09-07 01:46:26 +02:00
|
|
|
* their entry point, so we need a small asm wrapper. Testing indicates
|
|
|
|
* that only modifying esi leads to a crash, so use this one to backup
|
|
|
|
* ebp while running the dll entry proc.
|
2004-03-19 03:07:16 +01:00
|
|
|
*/
|
|
|
|
#ifdef __i386__
|
|
|
|
extern BOOL call_dll_entry_point( DLLENTRYPROC proc, void *module, UINT reason, void *reserved );
|
|
|
|
__ASM_GLOBAL_FUNC(call_dll_entry_point,
|
|
|
|
"pushl %ebp\n\t"
|
2009-06-25 12:02:53 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
2004-03-19 03:07:16 +01:00
|
|
|
"movl %esp,%ebp\n\t"
|
2009-06-25 12:02:53 +02:00
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
2004-03-19 03:07:16 +01:00
|
|
|
"pushl %ebx\n\t"
|
2009-06-25 12:02:53 +02:00
|
|
|
__ASM_CFI(".cfi_rel_offset %ebx,-4\n\t")
|
2014-09-07 01:46:26 +02:00
|
|
|
"pushl %esi\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
|
|
|
|
"pushl %edi\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %edi,-12\n\t")
|
|
|
|
"movl %ebp,%esi\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %esi\n\t")
|
2004-03-19 03:07:16 +01:00
|
|
|
"pushl 20(%ebp)\n\t"
|
|
|
|
"pushl 16(%ebp)\n\t"
|
|
|
|
"pushl 12(%ebp)\n\t"
|
|
|
|
"movl 8(%ebp),%eax\n\t"
|
|
|
|
"call *%eax\n\t"
|
2014-09-07 01:46:26 +02:00
|
|
|
"movl %esi,%ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
|
|
|
"leal -12(%ebp),%esp\n\t"
|
|
|
|
"popl %edi\n\t"
|
|
|
|
__ASM_CFI(".cfi_same_value %edi\n\t")
|
|
|
|
"popl %esi\n\t"
|
|
|
|
__ASM_CFI(".cfi_same_value %esi\n\t")
|
2004-03-19 03:07:16 +01:00
|
|
|
"popl %ebx\n\t"
|
2009-06-25 12:02:53 +02:00
|
|
|
__ASM_CFI(".cfi_same_value %ebx\n\t")
|
2004-03-19 03:07:16 +01:00
|
|
|
"popl %ebp\n\t"
|
2009-06-25 12:02:53 +02:00
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
2007-01-13 00:38:07 +01:00
|
|
|
"ret" )
|
2004-03-19 03:07:16 +01:00
|
|
|
#else /* __i386__ */
|
|
|
|
static inline BOOL call_dll_entry_point( DLLENTRYPROC proc, void *module,
|
|
|
|
UINT reason, void *reserved )
|
|
|
|
{
|
|
|
|
return proc( module, reason, reserved );
|
|
|
|
}
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
|
|
|
|
2017-08-01 10:52:42 +02:00
|
|
|
#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
|
2004-12-14 21:03:23 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* stub_entry_point
|
|
|
|
*
|
|
|
|
* Entry point for stub functions.
|
|
|
|
*/
|
2008-12-16 12:25:07 +01:00
|
|
|
static void stub_entry_point( const char *dll, const char *name, void *ret_addr )
|
2004-12-14 21:03:23 +01:00
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec;
|
|
|
|
|
|
|
|
rec.ExceptionCode = EXCEPTION_WINE_STUB;
|
|
|
|
rec.ExceptionFlags = EH_NONCONTINUABLE;
|
|
|
|
rec.ExceptionRecord = NULL;
|
2008-12-16 12:25:07 +01:00
|
|
|
rec.ExceptionAddress = ret_addr;
|
2004-12-14 21:03:23 +01:00
|
|
|
rec.NumberParameters = 2;
|
2005-02-24 14:15:36 +01:00
|
|
|
rec.ExceptionInformation[0] = (ULONG_PTR)dll;
|
|
|
|
rec.ExceptionInformation[1] = (ULONG_PTR)name;
|
2004-12-14 21:03:23 +01:00
|
|
|
for (;;) RtlRaiseException( &rec );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-21 11:52:26 +01:00
|
|
|
#include "pshpack1.h"
|
2008-12-16 12:25:07 +01:00
|
|
|
#ifdef __i386__
|
2004-12-14 21:03:23 +01:00
|
|
|
struct stub
|
|
|
|
{
|
|
|
|
BYTE pushl1; /* pushl $name */
|
|
|
|
const char *name;
|
|
|
|
BYTE pushl2; /* pushl $dll */
|
|
|
|
const char *dll;
|
2008-12-16 12:25:07 +01:00
|
|
|
BYTE call; /* call stub_entry_point */
|
2004-12-14 21:03:23 +01:00
|
|
|
DWORD entry;
|
|
|
|
};
|
2012-03-08 22:12:30 +01:00
|
|
|
#elif defined(__arm__)
|
|
|
|
struct stub
|
|
|
|
{
|
2018-01-18 19:20:10 +01:00
|
|
|
DWORD ldr_r0; /* ldr r0, $dll */
|
|
|
|
DWORD ldr_r1; /* ldr r1, $name */
|
|
|
|
DWORD mov_r2_lr; /* mov r2, lr */
|
|
|
|
DWORD ldr_pc_pc; /* ldr pc, [pc, #4] */
|
2017-08-01 10:52:43 +02:00
|
|
|
const char *dll;
|
|
|
|
const char *name;
|
2012-03-08 22:12:30 +01:00
|
|
|
const void* entry;
|
|
|
|
};
|
2017-08-01 10:52:42 +02:00
|
|
|
#elif defined(__aarch64__)
|
|
|
|
struct stub
|
|
|
|
{
|
2018-01-18 19:20:10 +01:00
|
|
|
DWORD ldr_x0; /* ldr x0, $dll */
|
|
|
|
DWORD ldr_x1; /* ldr x1, $name */
|
|
|
|
DWORD mov_x2_lr; /* mov x2, lr */
|
|
|
|
DWORD ldr_x16; /* ldr x16, $entry */
|
|
|
|
DWORD br_x16; /* br x16 */
|
2017-08-01 10:52:42 +02:00
|
|
|
const char *dll;
|
|
|
|
const char *name;
|
|
|
|
const void *entry;
|
|
|
|
};
|
2008-12-16 12:25:07 +01:00
|
|
|
#else
|
|
|
|
struct stub
|
|
|
|
{
|
|
|
|
BYTE movq_rdi[2]; /* movq $dll,%rdi */
|
|
|
|
const char *dll;
|
|
|
|
BYTE movq_rsi[2]; /* movq $name,%rsi */
|
|
|
|
const char *name;
|
|
|
|
BYTE movq_rsp_rdx[4]; /* movq (%rsp),%rdx */
|
|
|
|
BYTE movq_rax[2]; /* movq $entry, %rax */
|
|
|
|
const void* entry;
|
|
|
|
BYTE jmpq_rax[2]; /* jmp %rax */
|
|
|
|
};
|
|
|
|
#endif
|
2005-03-21 11:52:26 +01:00
|
|
|
#include "poppack.h"
|
2004-12-14 21:03:23 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* allocate_stub
|
|
|
|
*
|
|
|
|
* Allocate a stub entry point.
|
|
|
|
*/
|
2005-07-19 13:44:32 +02:00
|
|
|
static ULONG_PTR allocate_stub( const char *dll, const char *name )
|
2004-12-14 21:03:23 +01:00
|
|
|
{
|
|
|
|
#define MAX_SIZE 65536
|
|
|
|
static struct stub *stubs;
|
|
|
|
static unsigned int nb_stubs;
|
|
|
|
struct stub *stub;
|
|
|
|
|
2005-07-19 13:44:32 +02:00
|
|
|
if (nb_stubs >= MAX_SIZE / sizeof(*stub)) return 0xdeadbeef;
|
2004-12-14 21:03:23 +01:00
|
|
|
|
|
|
|
if (!stubs)
|
|
|
|
{
|
2006-10-16 13:49:06 +02:00
|
|
|
SIZE_T size = MAX_SIZE;
|
2005-02-22 20:33:50 +01:00
|
|
|
if (NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&stubs, 0, &size,
|
2011-11-08 10:09:17 +01:00
|
|
|
MEM_COMMIT, PAGE_EXECUTE_READWRITE ) != STATUS_SUCCESS)
|
2005-07-19 13:44:32 +02:00
|
|
|
return 0xdeadbeef;
|
2004-12-14 21:03:23 +01:00
|
|
|
}
|
|
|
|
stub = &stubs[nb_stubs++];
|
2008-12-16 12:25:07 +01:00
|
|
|
#ifdef __i386__
|
2004-12-14 21:03:23 +01:00
|
|
|
stub->pushl1 = 0x68; /* pushl $name */
|
|
|
|
stub->name = name;
|
|
|
|
stub->pushl2 = 0x68; /* pushl $dll */
|
|
|
|
stub->dll = dll;
|
2008-12-16 12:25:07 +01:00
|
|
|
stub->call = 0xe8; /* call stub_entry_point */
|
2004-12-14 21:03:23 +01:00
|
|
|
stub->entry = (BYTE *)stub_entry_point - (BYTE *)(&stub->entry + 1);
|
2012-03-08 22:12:30 +01:00
|
|
|
#elif defined(__arm__)
|
2018-01-18 19:20:10 +01:00
|
|
|
stub->ldr_r0 = 0xe59f0008; /* ldr r0, [pc, #8] ($dll) */
|
|
|
|
stub->ldr_r1 = 0xe59f1008; /* ldr r1, [pc, #8] ($name) */
|
|
|
|
stub->mov_r2_lr = 0xe1a0200e; /* mov r2, lr */
|
|
|
|
stub->ldr_pc_pc = 0xe59ff004; /* ldr pc, [pc, #4] */
|
|
|
|
stub->dll = dll;
|
|
|
|
stub->name = name;
|
|
|
|
stub->entry = stub_entry_point;
|
2017-08-01 10:52:42 +02:00
|
|
|
#elif defined(__aarch64__)
|
2018-01-18 19:20:10 +01:00
|
|
|
stub->ldr_x0 = 0x580000a0; /* ldr x0, #20 ($dll) */
|
|
|
|
stub->ldr_x1 = 0x580000c1; /* ldr x1, #24 ($name) */
|
|
|
|
stub->mov_x2_lr = 0xaa1e03e2; /* mov x2, lr */
|
|
|
|
stub->ldr_x16 = 0x580000d0; /* ldr x16, #24 ($entry) */
|
|
|
|
stub->br_x16 = 0xd61f0200; /* br x16 */
|
|
|
|
stub->dll = dll;
|
|
|
|
stub->name = name;
|
|
|
|
stub->entry = stub_entry_point;
|
2008-12-16 12:25:07 +01:00
|
|
|
#else
|
|
|
|
stub->movq_rdi[0] = 0x48; /* movq $dll,%rdi */
|
|
|
|
stub->movq_rdi[1] = 0xbf;
|
|
|
|
stub->dll = dll;
|
|
|
|
stub->movq_rsi[0] = 0x48; /* movq $name,%rsi */
|
|
|
|
stub->movq_rsi[1] = 0xbe;
|
|
|
|
stub->name = name;
|
|
|
|
stub->movq_rsp_rdx[0] = 0x48; /* movq (%rsp),%rdx */
|
|
|
|
stub->movq_rsp_rdx[1] = 0x8b;
|
|
|
|
stub->movq_rsp_rdx[2] = 0x14;
|
|
|
|
stub->movq_rsp_rdx[3] = 0x24;
|
|
|
|
stub->movq_rax[0] = 0x48; /* movq $entry, %rax */
|
|
|
|
stub->movq_rax[1] = 0xb8;
|
|
|
|
stub->entry = stub_entry_point;
|
|
|
|
stub->jmpq_rax[0] = 0xff; /* jmp %rax */
|
|
|
|
stub->jmpq_rax[1] = 0xe0;
|
|
|
|
#endif
|
2005-07-19 13:44:32 +02:00
|
|
|
return (ULONG_PTR)stub;
|
2004-12-14 21:03:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* __i386__ */
|
2005-07-19 13:44:32 +02:00
|
|
|
static inline ULONG_PTR allocate_stub( const char *dll, const char *name ) { return 0xdeadbeef; }
|
2004-12-14 21:03:23 +01:00
|
|
|
#endif /* __i386__ */
|
|
|
|
|
2018-06-22 03:54:56 +02:00
|
|
|
/* call ldr notifications */
|
|
|
|
static void call_ldr_notifications( ULONG reason, LDR_MODULE *module )
|
|
|
|
{
|
|
|
|
struct ldr_notification *notify, *notify_next;
|
|
|
|
LDR_DLL_NOTIFICATION_DATA data;
|
|
|
|
|
|
|
|
data.Loaded.Flags = 0;
|
|
|
|
data.Loaded.FullDllName = &module->FullDllName;
|
|
|
|
data.Loaded.BaseDllName = &module->BaseDllName;
|
|
|
|
data.Loaded.DllBase = module->BaseAddress;
|
|
|
|
data.Loaded.SizeOfImage = module->SizeOfImage;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( notify, notify_next, &ldr_notifications, struct ldr_notification, entry )
|
|
|
|
{
|
|
|
|
TRACE_(relay)("\1Call LDR notification callback (proc=%p,reason=%u,data=%p,context=%p)\n",
|
|
|
|
notify->callback, reason, &data, notify->context );
|
|
|
|
|
|
|
|
notify->callback(reason, &data, notify->context);
|
|
|
|
|
|
|
|
TRACE_(relay)("\1Ret LDR notification callback (proc=%p,reason=%u,data=%p,context=%p)\n",
|
|
|
|
notify->callback, reason, &data, notify->context );
|
|
|
|
}
|
|
|
|
}
|
2004-12-14 21:03:23 +01:00
|
|
|
|
2003-03-18 19:29:13 +01:00
|
|
|
/*************************************************************************
|
2003-04-05 07:16:11 +02:00
|
|
|
* get_modref
|
|
|
|
*
|
|
|
|
* Looks for the referenced HMODULE in the current process
|
|
|
|
* The loader_section must be locked while calling this function.
|
2003-03-18 19:29:13 +01:00
|
|
|
*/
|
2003-04-05 07:16:11 +02:00
|
|
|
static WINE_MODREF *get_modref( HMODULE hmod )
|
2003-03-18 19:29:13 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
PLIST_ENTRY mark, entry;
|
|
|
|
PLDR_MODULE mod;
|
2003-03-18 19:29:13 +01:00
|
|
|
|
2003-04-05 07:16:11 +02:00
|
|
|
if (cached_modref && cached_modref->ldr.BaseAddress == hmod) return cached_modref;
|
2003-03-18 19:29:13 +01:00
|
|
|
|
2003-07-01 05:38:56 +02:00
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
2003-04-05 07:16:11 +02:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
mod = CONTAINING_RECORD(entry, LDR_MODULE, InMemoryOrderModuleList);
|
|
|
|
if (mod->BaseAddress == hmod)
|
|
|
|
return cached_modref = CONTAINING_RECORD(mod, WINE_MODREF, ldr);
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
2003-07-01 05:38:56 +02:00
|
|
|
return NULL;
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-19 06:04:57 +02:00
|
|
|
/**********************************************************************
|
2003-10-08 00:56:34 +02:00
|
|
|
* find_basename_module
|
2003-09-19 06:04:57 +02:00
|
|
|
*
|
2003-10-08 00:56:34 +02:00
|
|
|
* Find a module from its base name.
|
2003-09-19 06:04:57 +02:00
|
|
|
* The loader_section must be locked while calling this function
|
|
|
|
*/
|
2003-10-08 00:56:34 +02:00
|
|
|
static WINE_MODREF *find_basename_module( LPCWSTR name )
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
|
|
|
PLIST_ENTRY mark, entry;
|
2020-03-27 13:39:20 +01:00
|
|
|
UNICODE_STRING name_str;
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2020-03-27 13:39:20 +01:00
|
|
|
RtlInitUnicodeString( &name_str, name );
|
|
|
|
|
|
|
|
if (cached_modref && RtlEqualUnicodeString( &name_str, &cached_modref->ldr.BaseDllName, TRUE ))
|
2003-10-08 00:56:34 +02:00
|
|
|
return cached_modref;
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2003-10-08 00:56:34 +02:00
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2003-10-08 00:56:34 +02:00
|
|
|
LDR_MODULE *mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
|
2020-03-27 13:39:20 +01:00
|
|
|
if (RtlEqualUnicodeString( &name_str, &mod->BaseDllName, TRUE ))
|
2003-10-08 00:56:34 +02:00
|
|
|
{
|
|
|
|
cached_modref = CONTAINING_RECORD(mod, WINE_MODREF, ldr);
|
|
|
|
return cached_modref;
|
|
|
|
}
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
2003-10-08 00:56:34 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* find_fullname_module
|
|
|
|
*
|
|
|
|
* Find a module from its full path name.
|
|
|
|
* The loader_section must be locked while calling this function
|
|
|
|
*/
|
2019-02-08 12:46:22 +01:00
|
|
|
static WINE_MODREF *find_fullname_module( const UNICODE_STRING *nt_name )
|
2003-10-08 00:56:34 +02:00
|
|
|
{
|
|
|
|
PLIST_ENTRY mark, entry;
|
2019-02-08 12:46:22 +01:00
|
|
|
UNICODE_STRING name = *nt_name;
|
2003-10-08 00:56:34 +02:00
|
|
|
|
2019-02-08 12:46:22 +01:00
|
|
|
if (name.Length <= 4 * sizeof(WCHAR)) return NULL;
|
|
|
|
name.Length -= 4 * sizeof(WCHAR); /* for \??\ prefix */
|
|
|
|
name.Buffer += 4;
|
|
|
|
|
|
|
|
if (cached_modref && RtlEqualUnicodeString( &name, &cached_modref->ldr.FullDllName, TRUE ))
|
2003-10-08 00:56:34 +02:00
|
|
|
return cached_modref;
|
2003-09-19 06:04:57 +02:00
|
|
|
|
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
|
|
|
{
|
2003-10-08 00:56:34 +02:00
|
|
|
LDR_MODULE *mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
|
2019-02-08 12:46:22 +01:00
|
|
|
if (RtlEqualUnicodeString( &name, &mod->FullDllName, TRUE ))
|
2003-10-08 00:56:34 +02:00
|
|
|
{
|
|
|
|
cached_modref = CONTAINING_RECORD(mod, WINE_MODREF, ldr);
|
|
|
|
return cached_modref;
|
|
|
|
}
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
2003-10-08 00:56:34 +02:00
|
|
|
return NULL;
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 10:11:55 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* find_fileid_module
|
|
|
|
*
|
|
|
|
* Find a module from its file id.
|
|
|
|
* The loader_section must be locked while calling this function
|
|
|
|
*/
|
2019-02-08 23:00:27 +01:00
|
|
|
static WINE_MODREF *find_fileid_module( struct stat *st )
|
2018-02-28 10:11:55 +01:00
|
|
|
{
|
|
|
|
LIST_ENTRY *mark, *entry;
|
|
|
|
|
|
|
|
if (cached_modref && cached_modref->dev == st->st_dev && cached_modref->ino == st->st_ino)
|
|
|
|
return cached_modref;
|
|
|
|
|
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
|
|
|
{
|
|
|
|
LDR_MODULE *mod = CONTAINING_RECORD( entry, LDR_MODULE, InLoadOrderModuleList );
|
|
|
|
WINE_MODREF *wm = CONTAINING_RECORD( mod, WINE_MODREF, ldr );
|
|
|
|
|
|
|
|
if (wm->dev == st->st_dev && wm->ino == st->st_ino)
|
|
|
|
{
|
|
|
|
cached_modref = wm;
|
|
|
|
return wm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-05 17:26:35 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* find_so_module
|
|
|
|
*
|
|
|
|
* Find a module from its so file handle.
|
|
|
|
* The loader_section must be locked while calling this function
|
|
|
|
*/
|
|
|
|
static WINE_MODREF *find_so_module( void *handle )
|
|
|
|
{
|
|
|
|
LIST_ENTRY *mark, *entry;
|
|
|
|
|
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
|
|
|
{
|
|
|
|
LDR_MODULE *mod = CONTAINING_RECORD( entry, LDR_MODULE, InLoadOrderModuleList );
|
|
|
|
WINE_MODREF *wm = CONTAINING_RECORD( mod, WINE_MODREF, ldr );
|
|
|
|
|
2020-04-16 12:00:43 +02:00
|
|
|
if (wm->so_handle == handle) return wm;
|
2019-06-05 17:26:35 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-05 07:16:11 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* find_forwarded_export
|
|
|
|
*
|
|
|
|
* Find the final function pointer for a forwarded function.
|
|
|
|
* The loader_section must be locked while calling this function.
|
|
|
|
*/
|
2007-12-06 21:40:37 +01:00
|
|
|
static FARPROC find_forwarded_export( HMODULE module, const char *forward, LPCWSTR load_path )
|
2003-04-05 07:16:11 +02:00
|
|
|
{
|
2004-06-15 02:47:00 +02:00
|
|
|
const IMAGE_EXPORT_DIRECTORY *exports;
|
2003-04-05 07:16:11 +02:00
|
|
|
DWORD exp_size;
|
|
|
|
WINE_MODREF *wm;
|
2003-10-08 00:56:34 +02:00
|
|
|
WCHAR mod_name[32];
|
2006-12-04 13:37:32 +01:00
|
|
|
const char *end = strrchr(forward, '.');
|
2003-04-05 07:16:11 +02:00
|
|
|
FARPROC proc = NULL;
|
|
|
|
|
|
|
|
if (!end) return NULL;
|
2006-12-04 13:37:32 +01:00
|
|
|
if ((end - forward) * sizeof(WCHAR) >= sizeof(mod_name)) return NULL;
|
2003-09-29 22:42:24 +02:00
|
|
|
ascii_to_unicode( mod_name, forward, end - forward );
|
2006-12-04 13:37:32 +01:00
|
|
|
mod_name[end - forward] = 0;
|
2020-03-31 11:43:50 +02:00
|
|
|
if (!wcschr( mod_name, '.' ))
|
2006-12-04 13:37:32 +01:00
|
|
|
{
|
|
|
|
if ((end - forward) * sizeof(WCHAR) >= sizeof(mod_name) - sizeof(dllW)) return NULL;
|
|
|
|
memcpy( mod_name + (end - forward), dllW, sizeof(dllW) );
|
|
|
|
}
|
2003-04-05 07:16:11 +02:00
|
|
|
|
2003-10-08 00:56:34 +02:00
|
|
|
if (!(wm = find_basename_module( mod_name )))
|
2003-04-05 07:16:11 +02:00
|
|
|
{
|
2007-12-06 21:40:37 +01:00
|
|
|
TRACE( "delay loading %s for '%s'\n", debugstr_w(mod_name), forward );
|
2019-11-07 18:54:21 +01:00
|
|
|
if (load_dll( load_path, mod_name, dllW, 0, &wm ) == STATUS_SUCCESS &&
|
2007-12-06 21:40:37 +01:00
|
|
|
!(wm->ldr.Flags & LDR_DONT_RESOLVE_REFS))
|
|
|
|
{
|
2017-11-21 13:13:35 +01:00
|
|
|
if (!imports_fixup_done && current_modref)
|
|
|
|
{
|
|
|
|
WINE_MODREF **deps;
|
2018-03-14 14:47:25 +01:00
|
|
|
if (current_modref->alloc_deps)
|
2017-11-21 13:13:35 +01:00
|
|
|
deps = RtlReAllocateHeap( GetProcessHeap(), 0, current_modref->deps,
|
2018-03-14 14:47:25 +01:00
|
|
|
(current_modref->alloc_deps + 1) * sizeof(*deps) );
|
2017-11-21 13:13:35 +01:00
|
|
|
else
|
|
|
|
deps = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*deps) );
|
|
|
|
if (deps)
|
|
|
|
{
|
|
|
|
deps[current_modref->nDeps++] = wm;
|
|
|
|
current_modref->deps = deps;
|
2018-03-14 14:47:25 +01:00
|
|
|
current_modref->alloc_deps++;
|
2017-11-21 13:13:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (process_attach( wm, NULL ) != STATUS_SUCCESS)
|
2007-12-06 21:40:37 +01:00
|
|
|
{
|
|
|
|
LdrUnloadDll( wm->ldr.BaseAddress );
|
|
|
|
wm = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wm)
|
|
|
|
{
|
|
|
|
ERR( "module not found for forward '%s' used by %s\n",
|
|
|
|
forward, debugstr_w(get_modref(module)->ldr.FullDllName.Buffer) );
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
if ((exports = RtlImageDirectoryEntryToData( wm->ldr.BaseAddress, TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
|
2009-09-25 13:12:02 +02:00
|
|
|
{
|
|
|
|
const char *name = end + 1;
|
|
|
|
if (*name == '#') /* ordinal */
|
|
|
|
proc = find_ordinal_export( wm->ldr.BaseAddress, exports, exp_size, atoi(name+1), load_path );
|
|
|
|
else
|
|
|
|
proc = find_named_export( wm->ldr.BaseAddress, exports, exp_size, name, -1, load_path );
|
|
|
|
}
|
2003-04-05 07:16:11 +02:00
|
|
|
|
|
|
|
if (!proc)
|
|
|
|
{
|
2003-09-29 22:42:24 +02:00
|
|
|
ERR("function not found for forward '%s' used by %s."
|
|
|
|
" If you are using builtin %s, try using the native one instead.\n",
|
|
|
|
forward, debugstr_w(get_modref(module)->ldr.FullDllName.Buffer),
|
|
|
|
debugstr_w(get_modref(module)->ldr.BaseDllName.Buffer) );
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* find_ordinal_export
|
|
|
|
*
|
|
|
|
* Find an exported function by ordinal.
|
|
|
|
* The exports base must have been subtracted from the ordinal already.
|
|
|
|
* The loader_section must be locked while calling this function.
|
|
|
|
*/
|
2004-06-15 02:47:00 +02:00
|
|
|
static FARPROC find_ordinal_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
|
2007-12-06 21:40:37 +01:00
|
|
|
DWORD exp_size, DWORD ordinal, LPCWSTR load_path )
|
2003-04-05 07:16:11 +02:00
|
|
|
{
|
|
|
|
FARPROC proc;
|
2004-06-15 02:47:00 +02:00
|
|
|
const DWORD *functions = get_rva( module, exports->AddressOfFunctions );
|
2003-04-05 07:16:11 +02:00
|
|
|
|
|
|
|
if (ordinal >= exports->NumberOfFunctions)
|
|
|
|
{
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE(" ordinal %d out of range!\n", ordinal + exports->Base );
|
2003-04-05 07:16:11 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!functions[ordinal]) return NULL;
|
|
|
|
|
|
|
|
proc = get_rva( module, functions[ordinal] );
|
|
|
|
|
|
|
|
/* if the address falls into the export dir, it's a forward */
|
2004-06-15 02:47:00 +02:00
|
|
|
if (((const char *)proc >= (const char *)exports) &&
|
|
|
|
((const char *)proc < (const char *)exports + exp_size))
|
2007-12-06 21:40:37 +01:00
|
|
|
return find_forwarded_export( module, (const char *)proc, load_path );
|
2003-04-05 07:16:11 +02:00
|
|
|
|
2004-08-03 00:25:01 +02:00
|
|
|
if (TRACE_ON(snoop))
|
2003-04-05 07:16:11 +02:00
|
|
|
{
|
2004-08-03 00:25:01 +02:00
|
|
|
const WCHAR *user = current_modref ? current_modref->ldr.BaseDllName.Buffer : NULL;
|
|
|
|
proc = SNOOP_GetProcAddress( module, exports, exp_size, proc, ordinal, user );
|
2003-04-08 01:27:54 +02:00
|
|
|
}
|
2004-08-03 00:25:01 +02:00
|
|
|
if (TRACE_ON(relay))
|
2003-04-08 01:27:54 +02:00
|
|
|
{
|
2004-08-03 00:25:01 +02:00
|
|
|
const WCHAR *user = current_modref ? current_modref->ldr.BaseDllName.Buffer : NULL;
|
2005-12-18 10:45:01 +01:00
|
|
|
proc = RELAY_GetProcAddress( module, exports, exp_size, proc, ordinal, user );
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* find_named_export
|
|
|
|
*
|
|
|
|
* Find an exported function by name.
|
|
|
|
* The loader_section must be locked while calling this function.
|
|
|
|
*/
|
2004-06-15 02:47:00 +02:00
|
|
|
static FARPROC find_named_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
|
2007-12-06 21:40:37 +01:00
|
|
|
DWORD exp_size, const char *name, int hint, LPCWSTR load_path )
|
2003-04-05 07:16:11 +02:00
|
|
|
{
|
2004-06-15 02:47:00 +02:00
|
|
|
const WORD *ordinals = get_rva( module, exports->AddressOfNameOrdinals );
|
|
|
|
const DWORD *names = get_rva( module, exports->AddressOfNames );
|
2003-04-05 07:16:11 +02:00
|
|
|
int min = 0, max = exports->NumberOfNames - 1;
|
|
|
|
|
|
|
|
/* first check the hint */
|
|
|
|
if (hint >= 0 && hint <= max)
|
|
|
|
{
|
|
|
|
char *ename = get_rva( module, names[hint] );
|
|
|
|
if (!strcmp( ename, name ))
|
2007-12-06 21:40:37 +01:00
|
|
|
return find_ordinal_export( module, exports, exp_size, ordinals[hint], load_path );
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* then do a binary search */
|
|
|
|
while (min <= max)
|
|
|
|
{
|
|
|
|
int res, pos = (min + max) / 2;
|
|
|
|
char *ename = get_rva( module, names[pos] );
|
|
|
|
if (!(res = strcmp( ename, name )))
|
2007-12-06 21:40:37 +01:00
|
|
|
return find_ordinal_export( module, exports, exp_size, ordinals[pos], load_path );
|
2003-04-05 07:16:11 +02:00
|
|
|
if (res > 0) max = pos - 1;
|
|
|
|
else min = pos + 1;
|
|
|
|
}
|
2003-03-18 19:29:13 +01:00
|
|
|
return NULL;
|
2003-04-05 07:16:11 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* import_dll
|
|
|
|
*
|
|
|
|
* Import the dll specified by the given import descriptor.
|
|
|
|
* The loader_section must be locked while calling this function.
|
|
|
|
*/
|
2016-02-10 17:38:28 +01:00
|
|
|
static BOOL import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *descr, LPCWSTR load_path, WINE_MODREF **pwm )
|
2003-04-05 07:16:11 +02:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
WINE_MODREF *wmImp;
|
|
|
|
HMODULE imp_mod;
|
2004-06-15 02:47:00 +02:00
|
|
|
const IMAGE_EXPORT_DIRECTORY *exports;
|
2003-04-05 07:16:11 +02:00
|
|
|
DWORD exp_size;
|
2004-06-15 02:47:00 +02:00
|
|
|
const IMAGE_THUNK_DATA *import_list;
|
|
|
|
IMAGE_THUNK_DATA *thunk_list;
|
2003-09-29 22:42:24 +02:00
|
|
|
WCHAR buffer[32];
|
2004-06-15 02:47:00 +02:00
|
|
|
const char *name = get_rva( module, descr->Name );
|
2006-02-20 14:08:26 +01:00
|
|
|
DWORD len = strlen(name);
|
2004-06-22 04:07:47 +02:00
|
|
|
PVOID protect_base;
|
2005-09-12 12:36:06 +02:00
|
|
|
SIZE_T protect_size = 0;
|
2004-06-22 04:07:47 +02:00
|
|
|
DWORD protect_old;
|
2003-09-29 22:42:24 +02:00
|
|
|
|
2003-10-11 01:28:51 +02:00
|
|
|
thunk_list = get_rva( module, (DWORD)descr->FirstThunk );
|
|
|
|
if (descr->u.OriginalFirstThunk)
|
|
|
|
import_list = get_rva( module, (DWORD)descr->u.OriginalFirstThunk );
|
|
|
|
else
|
|
|
|
import_list = thunk_list;
|
|
|
|
|
2016-02-10 17:38:28 +01:00
|
|
|
if (!import_list->u1.Ordinal)
|
|
|
|
{
|
|
|
|
WARN( "Skipping unused import %s\n", name );
|
|
|
|
*pwm = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-02-20 14:08:26 +01:00
|
|
|
while (len && name[len-1] == ' ') len--; /* remove trailing spaces */
|
|
|
|
|
|
|
|
if (len * sizeof(WCHAR) < sizeof(buffer))
|
2003-09-29 22:42:24 +02:00
|
|
|
{
|
|
|
|
ascii_to_unicode( buffer, name, len );
|
2006-02-20 14:08:26 +01:00
|
|
|
buffer[len] = 0;
|
2019-11-07 18:54:21 +01:00
|
|
|
status = load_dll( load_path, buffer, dllW, 0, &wmImp );
|
2003-09-29 22:42:24 +02:00
|
|
|
}
|
|
|
|
else /* need to allocate a larger buffer */
|
|
|
|
{
|
2006-02-20 14:08:26 +01:00
|
|
|
WCHAR *ptr = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
|
2016-02-10 17:38:28 +01:00
|
|
|
if (!ptr) return FALSE;
|
2003-09-29 22:42:24 +02:00
|
|
|
ascii_to_unicode( ptr, name, len );
|
2006-02-20 14:08:26 +01:00
|
|
|
ptr[len] = 0;
|
2019-11-07 18:54:21 +01:00
|
|
|
status = load_dll( load_path, ptr, dllW, 0, &wmImp );
|
2003-09-29 22:42:24 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, ptr );
|
|
|
|
}
|
2003-04-05 07:16:11 +02:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
2003-09-29 22:42:24 +02:00
|
|
|
if (status == STATUS_DLL_NOT_FOUND)
|
2004-02-24 02:25:03 +01:00
|
|
|
ERR("Library %s (which is needed by %s) not found\n",
|
2003-09-29 22:42:24 +02:00
|
|
|
name, debugstr_w(current_modref->ldr.FullDllName.Buffer));
|
2003-04-05 07:16:11 +02:00
|
|
|
else
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR("Loading library %s (which is needed by %s) failed (error %x).\n",
|
2003-09-29 22:42:24 +02:00
|
|
|
name, debugstr_w(current_modref->ldr.FullDllName.Buffer), status);
|
2016-02-10 17:38:28 +01:00
|
|
|
return FALSE;
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
|
2004-06-22 04:07:47 +02:00
|
|
|
/* unprotect the import address table since it can be located in
|
|
|
|
* readonly section */
|
|
|
|
while (import_list[protect_size].u1.Ordinal) protect_size++;
|
|
|
|
protect_base = thunk_list;
|
|
|
|
protect_size *= sizeof(*thunk_list);
|
2005-02-22 20:33:50 +01:00
|
|
|
NtProtectVirtualMemory( NtCurrentProcess(), &protect_base,
|
2011-10-31 06:48:37 +01:00
|
|
|
&protect_size, PAGE_READWRITE, &protect_old );
|
2004-06-22 04:07:47 +02:00
|
|
|
|
2004-02-24 02:25:03 +01:00
|
|
|
imp_mod = wmImp->ldr.BaseAddress;
|
|
|
|
exports = RtlImageDirectoryEntryToData( imp_mod, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size );
|
|
|
|
|
2003-10-11 01:28:51 +02:00
|
|
|
if (!exports)
|
|
|
|
{
|
|
|
|
/* set all imported function to deadbeef */
|
|
|
|
while (import_list->u1.Ordinal)
|
|
|
|
{
|
|
|
|
if (IMAGE_SNAP_BY_ORDINAL(import_list->u1.Ordinal))
|
|
|
|
{
|
2004-12-14 21:03:23 +01:00
|
|
|
int ordinal = IMAGE_ORDINAL(import_list->u1.Ordinal);
|
|
|
|
WARN("No implementation for %s.%d", name, ordinal );
|
2007-05-23 09:36:29 +02:00
|
|
|
thunk_list->u1.Function = allocate_stub( name, IntToPtr(ordinal) );
|
2003-10-11 01:28:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IMAGE_IMPORT_BY_NAME *pe_name = get_rva( module, (DWORD)import_list->u1.AddressOfData );
|
2004-12-14 21:03:23 +01:00
|
|
|
WARN("No implementation for %s.%s", name, pe_name->Name );
|
2005-09-02 16:47:36 +02:00
|
|
|
thunk_list->u1.Function = allocate_stub( name, (const char*)pe_name->Name );
|
2003-10-11 01:28:51 +02:00
|
|
|
}
|
2004-12-14 21:03:23 +01:00
|
|
|
WARN(" imported from %s, allocating stub %p\n",
|
2005-07-19 13:44:32 +02:00
|
|
|
debugstr_w(current_modref->ldr.FullDllName.Buffer),
|
|
|
|
(void *)thunk_list->u1.Function );
|
2003-10-11 01:28:51 +02:00
|
|
|
import_list++;
|
|
|
|
thunk_list++;
|
|
|
|
}
|
2004-06-22 04:07:47 +02:00
|
|
|
goto done;
|
2003-10-11 01:28:51 +02:00
|
|
|
}
|
2003-04-05 07:16:11 +02:00
|
|
|
|
|
|
|
while (import_list->u1.Ordinal)
|
|
|
|
{
|
|
|
|
if (IMAGE_SNAP_BY_ORDINAL(import_list->u1.Ordinal))
|
|
|
|
{
|
|
|
|
int ordinal = IMAGE_ORDINAL(import_list->u1.Ordinal);
|
|
|
|
|
2005-07-19 13:44:32 +02:00
|
|
|
thunk_list->u1.Function = (ULONG_PTR)find_ordinal_export( imp_mod, exports, exp_size,
|
2007-12-06 21:40:37 +01:00
|
|
|
ordinal - exports->Base, load_path );
|
2003-04-05 07:16:11 +02:00
|
|
|
if (!thunk_list->u1.Function)
|
|
|
|
{
|
2007-05-23 09:36:29 +02:00
|
|
|
thunk_list->u1.Function = allocate_stub( name, IntToPtr(ordinal) );
|
2004-12-14 21:03:23 +01:00
|
|
|
WARN("No implementation for %s.%d imported from %s, setting to %p\n",
|
2005-07-19 13:44:32 +02:00
|
|
|
name, ordinal, debugstr_w(current_modref->ldr.FullDllName.Buffer),
|
|
|
|
(void *)thunk_list->u1.Function );
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
2005-07-19 13:44:32 +02:00
|
|
|
TRACE_(imports)("--- Ordinal %s.%d = %p\n", name, ordinal, (void *)thunk_list->u1.Function );
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
else /* import by name */
|
|
|
|
{
|
|
|
|
IMAGE_IMPORT_BY_NAME *pe_name;
|
|
|
|
pe_name = get_rva( module, (DWORD)import_list->u1.AddressOfData );
|
2005-07-19 13:44:32 +02:00
|
|
|
thunk_list->u1.Function = (ULONG_PTR)find_named_export( imp_mod, exports, exp_size,
|
2007-12-06 21:40:37 +01:00
|
|
|
(const char*)pe_name->Name,
|
|
|
|
pe_name->Hint, load_path );
|
2003-04-05 07:16:11 +02:00
|
|
|
if (!thunk_list->u1.Function)
|
|
|
|
{
|
2005-09-02 16:47:36 +02:00
|
|
|
thunk_list->u1.Function = allocate_stub( name, (const char*)pe_name->Name );
|
2004-12-14 21:03:23 +01:00
|
|
|
WARN("No implementation for %s.%s imported from %s, setting to %p\n",
|
2005-07-19 13:44:32 +02:00
|
|
|
name, pe_name->Name, debugstr_w(current_modref->ldr.FullDllName.Buffer),
|
|
|
|
(void *)thunk_list->u1.Function );
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
2005-07-19 13:44:32 +02:00
|
|
|
TRACE_(imports)("--- %s %s.%d = %p\n",
|
|
|
|
pe_name->Name, name, pe_name->Hint, (void *)thunk_list->u1.Function);
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
import_list++;
|
|
|
|
thunk_list++;
|
|
|
|
}
|
2004-06-22 04:07:47 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
/* restore old protection of the import address table */
|
2015-05-02 18:43:24 +02:00
|
|
|
NtProtectVirtualMemory( NtCurrentProcess(), &protect_base, &protect_size, protect_old, &protect_old );
|
2016-02-10 17:38:28 +01:00
|
|
|
*pwm = wmImp;
|
|
|
|
return TRUE;
|
2003-04-05 07:16:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-25 16:50:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* create_module_activation_context
|
|
|
|
*/
|
|
|
|
static NTSTATUS create_module_activation_context( LDR_MODULE *module )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
LDR_RESOURCE_INFO info;
|
|
|
|
const IMAGE_RESOURCE_DATA_ENTRY *entry;
|
|
|
|
|
|
|
|
info.Type = RT_MANIFEST;
|
|
|
|
info.Name = ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
|
|
|
|
info.Language = 0;
|
|
|
|
if (!(status = LdrFindResource_U( module->BaseAddress, &info, 3, &entry )))
|
|
|
|
{
|
|
|
|
ACTCTXW ctx;
|
|
|
|
ctx.cbSize = sizeof(ctx);
|
|
|
|
ctx.lpSource = NULL;
|
|
|
|
ctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
|
|
|
|
ctx.hModule = module->BaseAddress;
|
|
|
|
ctx.lpResourceName = (LPCWSTR)ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
|
|
|
|
status = RtlCreateActivationContext( &module->ActivationContext, &ctx );
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-11 12:18:35 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* is_dll_native_subsystem
|
|
|
|
*
|
|
|
|
* Check if dll is a proper native driver.
|
|
|
|
* Some dlls (corpol.dll from IE6 for instance) are incorrectly marked as native
|
|
|
|
* while being perfectly normal DLLs. This heuristic should catch such breakages.
|
|
|
|
*/
|
2019-06-11 15:32:39 +02:00
|
|
|
static BOOL is_dll_native_subsystem( LDR_MODULE *mod, const IMAGE_NT_HEADERS *nt, LPCWSTR filename )
|
2008-12-11 12:18:35 +01:00
|
|
|
{
|
|
|
|
static const WCHAR ntdllW[] = {'n','t','d','l','l','.','d','l','l',0};
|
|
|
|
static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
|
|
|
|
const IMAGE_IMPORT_DESCRIPTOR *imports;
|
|
|
|
DWORD i, size;
|
|
|
|
WCHAR buffer[16];
|
|
|
|
|
|
|
|
if (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_NATIVE) return FALSE;
|
2013-01-08 14:00:06 +01:00
|
|
|
if (nt->OptionalHeader.SectionAlignment < page_size) return TRUE;
|
2019-06-11 15:32:39 +02:00
|
|
|
if (mod->Flags & LDR_WINE_INTERNAL) return TRUE;
|
2008-12-11 12:18:35 +01:00
|
|
|
|
2019-06-11 15:32:39 +02:00
|
|
|
if ((imports = RtlImageDirectoryEntryToData( mod->BaseAddress, TRUE,
|
2008-12-11 12:18:35 +01:00
|
|
|
IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
|
|
|
|
{
|
|
|
|
for (i = 0; imports[i].Name; i++)
|
|
|
|
{
|
2019-06-11 15:32:39 +02:00
|
|
|
const char *name = get_rva( mod->BaseAddress, imports[i].Name );
|
2008-12-11 12:18:35 +01:00
|
|
|
DWORD len = strlen(name);
|
|
|
|
if (len * sizeof(WCHAR) >= sizeof(buffer)) continue;
|
|
|
|
ascii_to_unicode( buffer, name, len + 1 );
|
2020-03-27 13:38:09 +01:00
|
|
|
if (!wcsicmp( buffer, ntdllW ) || !wcsicmp( buffer, kernel32W ))
|
2008-12-11 12:18:35 +01:00
|
|
|
{
|
|
|
|
TRACE( "%s imports %s, assuming not native\n", debugstr_w(filename), debugstr_w(buffer) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-23 12:54:26 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* alloc_tls_slot
|
|
|
|
*
|
|
|
|
* Allocate a TLS slot for a newly-loaded module.
|
|
|
|
* The loader_section must be locked while calling this function.
|
|
|
|
*/
|
|
|
|
static SHORT alloc_tls_slot( LDR_MODULE *mod )
|
|
|
|
{
|
|
|
|
const IMAGE_TLS_DIRECTORY *dir;
|
|
|
|
ULONG i, size;
|
|
|
|
void *new_ptr;
|
2013-12-23 18:16:51 +01:00
|
|
|
LIST_ENTRY *entry;
|
2013-12-23 12:54:26 +01:00
|
|
|
|
|
|
|
if (!(dir = RtlImageDirectoryEntryToData( mod->BaseAddress, TRUE, IMAGE_DIRECTORY_ENTRY_TLS, &size )))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
size = dir->EndAddressOfRawData - dir->StartAddressOfRawData;
|
|
|
|
if (!size && !dir->SizeOfZeroFill && !dir->AddressOfCallBacks) return -1;
|
|
|
|
|
2015-07-14 10:36:12 +02:00
|
|
|
for (i = 0; i < tls_module_count; i++)
|
|
|
|
{
|
|
|
|
if (!tls_dirs[i].StartAddressOfRawData && !tls_dirs[i].EndAddressOfRawData &&
|
|
|
|
!tls_dirs[i].SizeOfZeroFill && !tls_dirs[i].AddressOfCallBacks)
|
|
|
|
break;
|
|
|
|
}
|
2013-12-23 12:54:26 +01:00
|
|
|
|
|
|
|
TRACE( "module %p data %p-%p zerofill %u index %p callback %p flags %x -> slot %u\n", mod->BaseAddress,
|
|
|
|
(void *)dir->StartAddressOfRawData, (void *)dir->EndAddressOfRawData, dir->SizeOfZeroFill,
|
|
|
|
(void *)dir->AddressOfIndex, (void *)dir->AddressOfCallBacks, dir->Characteristics, i );
|
|
|
|
|
|
|
|
if (i == tls_module_count)
|
|
|
|
{
|
|
|
|
UINT new_count = max( 32, tls_module_count * 2 );
|
|
|
|
|
|
|
|
if (!tls_dirs)
|
|
|
|
new_ptr = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, new_count * sizeof(*tls_dirs) );
|
|
|
|
else
|
|
|
|
new_ptr = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, tls_dirs,
|
|
|
|
new_count * sizeof(*tls_dirs) );
|
|
|
|
if (!new_ptr) return -1;
|
2013-12-23 18:16:51 +01:00
|
|
|
|
|
|
|
/* resize the pointer block in all running threads */
|
|
|
|
for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
|
|
|
|
{
|
|
|
|
TEB *teb = CONTAINING_RECORD( entry, TEB, TlsLinks );
|
|
|
|
void **old = teb->ThreadLocalStoragePointer;
|
|
|
|
void **new = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, new_count * sizeof(*new));
|
|
|
|
|
|
|
|
if (!new) return -1;
|
|
|
|
if (old) memcpy( new, old, tls_module_count * sizeof(*new) );
|
|
|
|
teb->ThreadLocalStoragePointer = new;
|
2016-07-28 23:33:25 +02:00
|
|
|
#if defined(__APPLE__) && defined(__x86_64__)
|
|
|
|
if (teb->Reserved5[0])
|
|
|
|
((TEB*)teb->Reserved5[0])->ThreadLocalStoragePointer = new;
|
|
|
|
#endif
|
2013-12-23 18:16:51 +01:00
|
|
|
TRACE( "thread %04lx tls block %p -> %p\n", (ULONG_PTR)teb->ClientId.UniqueThread, old, new );
|
|
|
|
/* FIXME: can't free old block here, should be freed at thread exit */
|
|
|
|
}
|
|
|
|
|
2013-12-23 12:54:26 +01:00
|
|
|
tls_dirs = new_ptr;
|
|
|
|
tls_module_count = new_count;
|
|
|
|
}
|
|
|
|
|
2013-12-23 18:16:51 +01:00
|
|
|
/* allocate the data block in all running threads */
|
|
|
|
for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
|
|
|
|
{
|
|
|
|
TEB *teb = CONTAINING_RECORD( entry, TEB, TlsLinks );
|
|
|
|
|
|
|
|
if (!(new_ptr = RtlAllocateHeap( GetProcessHeap(), 0, size + dir->SizeOfZeroFill ))) return -1;
|
|
|
|
memcpy( new_ptr, (void *)dir->StartAddressOfRawData, size );
|
|
|
|
memset( (char *)new_ptr + size, 0, dir->SizeOfZeroFill );
|
|
|
|
|
|
|
|
TRACE( "thread %04lx slot %u: %u/%u bytes at %p\n",
|
|
|
|
(ULONG_PTR)teb->ClientId.UniqueThread, i, size, dir->SizeOfZeroFill, new_ptr );
|
|
|
|
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0,
|
|
|
|
interlocked_xchg_ptr( (void **)teb->ThreadLocalStoragePointer + i, new_ptr ));
|
|
|
|
}
|
|
|
|
|
2013-12-23 12:54:26 +01:00
|
|
|
*(DWORD *)dir->AddressOfIndex = i;
|
2015-07-14 10:36:12 +02:00
|
|
|
tls_dirs[i] = *dir;
|
2013-12-23 12:54:26 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* free_tls_slot
|
|
|
|
*
|
|
|
|
* Free the module TLS slot on unload.
|
|
|
|
* The loader_section must be locked while calling this function.
|
|
|
|
*/
|
|
|
|
static void free_tls_slot( LDR_MODULE *mod )
|
|
|
|
{
|
|
|
|
ULONG i = (USHORT)mod->TlsIndex;
|
|
|
|
|
|
|
|
if (mod->TlsIndex == -1) return;
|
|
|
|
assert( i < tls_module_count );
|
2015-07-14 10:36:12 +02:00
|
|
|
memset( &tls_dirs[i], 0, sizeof(tls_dirs[i]) );
|
2013-12-23 12:54:26 +01:00
|
|
|
}
|
|
|
|
|
2008-12-11 12:18:35 +01:00
|
|
|
|
2018-02-21 09:55:05 +01:00
|
|
|
/****************************************************************
|
|
|
|
* fixup_imports_ilonly
|
|
|
|
*
|
|
|
|
* Fixup imports for an IL-only module. All we do is import mscoree.
|
|
|
|
* The loader_section must be locked while calling this function.
|
|
|
|
*/
|
|
|
|
static NTSTATUS fixup_imports_ilonly( WINE_MODREF *wm, LPCWSTR load_path, void **entry )
|
|
|
|
{
|
|
|
|
static const WCHAR mscoreeW[] = {'m','s','c','o','r','e','e','.','d','l','l',0};
|
|
|
|
IMAGE_EXPORT_DIRECTORY *exports;
|
|
|
|
DWORD exp_size;
|
|
|
|
NTSTATUS status;
|
|
|
|
void *proc = NULL;
|
|
|
|
WINE_MODREF *prev, *imp;
|
|
|
|
|
|
|
|
if (!(wm->ldr.Flags & LDR_DONT_RESOLVE_REFS)) return STATUS_SUCCESS; /* already done */
|
|
|
|
wm->ldr.Flags &= ~LDR_DONT_RESOLVE_REFS;
|
|
|
|
|
|
|
|
wm->nDeps = 1;
|
2018-03-14 14:47:25 +01:00
|
|
|
wm->alloc_deps = 1;
|
2018-02-21 09:55:05 +01:00
|
|
|
wm->deps = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(WINE_MODREF *) );
|
|
|
|
|
|
|
|
prev = current_modref;
|
|
|
|
current_modref = wm;
|
2019-11-07 18:54:21 +01:00
|
|
|
if (!(status = load_dll( load_path, mscoreeW, NULL, 0, &imp ))) wm->deps[0] = imp;
|
2018-02-21 09:55:05 +01:00
|
|
|
current_modref = prev;
|
2018-02-26 17:04:30 +01:00
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
ERR( "mscoree.dll not found, IL-only binary %s cannot be loaded\n",
|
|
|
|
debugstr_w(wm->ldr.BaseDllName.Buffer) );
|
|
|
|
return status;
|
|
|
|
}
|
2018-02-21 09:55:05 +01:00
|
|
|
|
|
|
|
TRACE( "loaded mscoree for %s\n", debugstr_w(wm->ldr.FullDllName.Buffer) );
|
|
|
|
|
|
|
|
if ((exports = RtlImageDirectoryEntryToData( imp->ldr.BaseAddress, TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
|
2018-04-02 18:11:51 +02:00
|
|
|
{
|
|
|
|
const char *name = (wm->ldr.Flags & LDR_IMAGE_IS_DLL) ? "_CorDllMain" : "_CorExeMain";
|
|
|
|
proc = find_named_export( imp->ldr.BaseAddress, exports, exp_size, name, -1, load_path );
|
|
|
|
}
|
2018-02-21 09:55:05 +01:00
|
|
|
if (!proc) return STATUS_PROCEDURE_NOT_FOUND;
|
|
|
|
*entry = proc;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-17 17:32:37 +01:00
|
|
|
/****************************************************************
|
|
|
|
* fixup_imports
|
|
|
|
*
|
|
|
|
* Fixup all imports of a given module.
|
|
|
|
* The loader_section must be locked while calling this function.
|
|
|
|
*/
|
|
|
|
static NTSTATUS fixup_imports( WINE_MODREF *wm, LPCWSTR load_path )
|
|
|
|
{
|
2018-03-14 14:47:25 +01:00
|
|
|
int i, dep, nb_imports;
|
2014-02-17 17:32:37 +01:00
|
|
|
const IMAGE_IMPORT_DESCRIPTOR *imports;
|
2017-11-21 13:13:35 +01:00
|
|
|
WINE_MODREF *prev, *imp;
|
2014-02-17 17:32:37 +01:00
|
|
|
DWORD size;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG_PTR cookie;
|
|
|
|
|
|
|
|
if (!(wm->ldr.Flags & LDR_DONT_RESOLVE_REFS)) return STATUS_SUCCESS; /* already done */
|
|
|
|
wm->ldr.Flags &= ~LDR_DONT_RESOLVE_REFS;
|
|
|
|
|
2014-02-17 17:33:30 +01:00
|
|
|
wm->ldr.TlsIndex = alloc_tls_slot( &wm->ldr );
|
|
|
|
|
2014-02-17 17:32:37 +01:00
|
|
|
if (!(imports = RtlImageDirectoryEntryToData( wm->ldr.BaseAddress, TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
nb_imports = 0;
|
|
|
|
while (imports[nb_imports].Name && imports[nb_imports].FirstThunk) nb_imports++;
|
|
|
|
|
|
|
|
if (!nb_imports) return STATUS_SUCCESS; /* no imports */
|
|
|
|
|
|
|
|
if (!create_module_activation_context( &wm->ldr ))
|
|
|
|
RtlActivateActivationContext( 0, wm->ldr.ActivationContext, &cookie );
|
|
|
|
|
|
|
|
/* Allocate module dependency list */
|
2018-03-14 14:47:25 +01:00
|
|
|
wm->alloc_deps = nb_imports;
|
2014-02-17 17:32:37 +01:00
|
|
|
wm->deps = RtlAllocateHeap( GetProcessHeap(), 0, nb_imports*sizeof(WINE_MODREF *) );
|
|
|
|
|
|
|
|
/* load the imported modules. They are automatically
|
|
|
|
* added to the modref list of the process.
|
|
|
|
*/
|
|
|
|
prev = current_modref;
|
|
|
|
current_modref = wm;
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
for (i = 0; i < nb_imports; i++)
|
|
|
|
{
|
2018-03-14 14:47:25 +01:00
|
|
|
dep = wm->nDeps++;
|
|
|
|
|
2017-11-21 13:13:35 +01:00
|
|
|
if (!import_dll( wm->ldr.BaseAddress, &imports[i], load_path, &imp ))
|
2016-02-10 17:38:28 +01:00
|
|
|
{
|
2017-11-21 13:13:35 +01:00
|
|
|
imp = NULL;
|
2014-02-17 17:32:37 +01:00
|
|
|
status = STATUS_DLL_NOT_FOUND;
|
2016-02-10 17:38:28 +01:00
|
|
|
}
|
2018-03-14 14:47:25 +01:00
|
|
|
wm->deps[dep] = imp;
|
2014-02-17 17:32:37 +01:00
|
|
|
}
|
|
|
|
current_modref = prev;
|
|
|
|
if (wm->ldr.ActivationContext) RtlDeactivateActivationContext( 0, cookie );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-14 06:01:20 +01:00
|
|
|
/*************************************************************************
|
2003-09-29 22:42:24 +02:00
|
|
|
* alloc_module
|
2003-03-14 06:01:20 +01:00
|
|
|
*
|
|
|
|
* Allocate a WINE_MODREF structure and add it to the process list
|
2003-04-05 07:16:11 +02:00
|
|
|
* The loader_section must be locked while calling this function.
|
2003-03-14 06:01:20 +01:00
|
|
|
*/
|
2019-06-11 15:32:39 +02:00
|
|
|
static WINE_MODREF *alloc_module( HMODULE hModule, const UNICODE_STRING *nt_name, BOOL builtin )
|
2003-03-14 06:01:20 +01:00
|
|
|
{
|
2020-04-14 21:58:23 +02:00
|
|
|
WCHAR *buffer;
|
2003-03-14 06:01:20 +01:00
|
|
|
WINE_MODREF *wm;
|
2004-06-15 02:47:00 +02:00
|
|
|
const WCHAR *p;
|
|
|
|
const IMAGE_NT_HEADERS *nt = RtlImageNtHeader(hModule);
|
2003-07-01 05:38:56 +02:00
|
|
|
|
2018-02-28 10:11:55 +01:00
|
|
|
if (!(wm = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wm) ))) return NULL;
|
2003-09-29 22:42:24 +02:00
|
|
|
|
|
|
|
wm->ldr.BaseAddress = hModule;
|
|
|
|
wm->ldr.SizeOfImage = nt->OptionalHeader.SizeOfImage;
|
2019-06-11 15:32:39 +02:00
|
|
|
wm->ldr.Flags = LDR_DONT_RESOLVE_REFS | (builtin ? LDR_WINE_INTERNAL : 0);
|
2014-02-17 17:33:30 +01:00
|
|
|
wm->ldr.TlsIndex = -1;
|
2006-07-31 21:03:01 +02:00
|
|
|
wm->ldr.LoadCount = 1;
|
2003-09-29 22:42:24 +02:00
|
|
|
|
2020-04-14 21:58:23 +02:00
|
|
|
if (!(buffer = RtlAllocateHeap( GetProcessHeap(), 0, nt_name->Length - 3 * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, wm );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy( buffer, nt_name->Buffer + 4 /* \??\ prefix */, nt_name->Length - 4 * sizeof(WCHAR) );
|
|
|
|
buffer[nt_name->Length/sizeof(WCHAR) - 4] = 0;
|
|
|
|
if ((p = wcsrchr( buffer, '\\' ))) p++;
|
|
|
|
else p = buffer;
|
|
|
|
RtlInitUnicodeString( &wm->ldr.FullDllName, buffer );
|
2003-09-29 22:42:24 +02:00
|
|
|
RtlInitUnicodeString( &wm->ldr.BaseDllName, p );
|
|
|
|
|
2020-04-14 12:55:38 +02:00
|
|
|
if (!is_dll_native_subsystem( &wm->ldr, nt, p ))
|
2003-09-29 22:42:24 +02:00
|
|
|
{
|
2014-08-02 18:27:20 +02:00
|
|
|
if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL)
|
|
|
|
wm->ldr.Flags |= LDR_IMAGE_IS_DLL;
|
2003-11-25 06:28:57 +01:00
|
|
|
if (nt->OptionalHeader.AddressOfEntryPoint)
|
|
|
|
wm->ldr.EntryPoint = (char *)hModule + nt->OptionalHeader.AddressOfEntryPoint;
|
2003-09-29 22:42:24 +02:00
|
|
|
}
|
|
|
|
|
2003-11-25 06:28:57 +01:00
|
|
|
InsertTailList(&NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList,
|
|
|
|
&wm->ldr.InLoadOrderModuleList);
|
2016-07-07 06:43:25 +02:00
|
|
|
InsertTailList(&NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList,
|
|
|
|
&wm->ldr.InMemoryOrderModuleList);
|
2018-02-28 10:11:55 +01:00
|
|
|
/* wait until init is called for inserting into InInitializationOrderModuleList */
|
2006-12-07 20:52:16 +01:00
|
|
|
|
|
|
|
if (!(nt->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_NX_COMPAT))
|
|
|
|
{
|
2009-09-12 01:27:42 +02:00
|
|
|
ULONG flags = MEM_EXECUTE_OPTION_ENABLE;
|
2006-12-07 20:52:16 +01:00
|
|
|
WARN( "disabling no-exec because of %s\n", debugstr_w(wm->ldr.BaseDllName.Buffer) );
|
2009-09-12 01:27:42 +02:00
|
|
|
NtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &flags, sizeof(flags) );
|
2006-12-07 20:52:16 +01:00
|
|
|
}
|
2003-09-29 22:42:24 +02:00
|
|
|
return wm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-14 21:51:14 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* alloc_thread_tls
|
|
|
|
*
|
|
|
|
* Allocate the per-thread structure for module TLS storage.
|
|
|
|
*/
|
|
|
|
static NTSTATUS alloc_thread_tls(void)
|
|
|
|
{
|
|
|
|
void **pointers;
|
2010-12-15 13:16:55 +01:00
|
|
|
UINT i, size;
|
2003-05-14 21:51:14 +02:00
|
|
|
|
|
|
|
if (!tls_module_count) return STATUS_SUCCESS;
|
|
|
|
|
2013-12-23 12:27:39 +01:00
|
|
|
if (!(pointers = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
tls_module_count * sizeof(*pointers) )))
|
2003-05-14 21:51:14 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
for (i = 0; i < tls_module_count; i++)
|
|
|
|
{
|
2015-07-14 10:36:12 +02:00
|
|
|
const IMAGE_TLS_DIRECTORY *dir = &tls_dirs[i];
|
2013-12-23 12:27:39 +01:00
|
|
|
|
|
|
|
if (!dir) continue;
|
2010-12-15 13:16:55 +01:00
|
|
|
size = dir->EndAddressOfRawData - dir->StartAddressOfRawData;
|
2013-12-23 12:27:39 +01:00
|
|
|
if (!size && !dir->SizeOfZeroFill) continue;
|
|
|
|
|
|
|
|
if (!(pointers[i] = RtlAllocateHeap( GetProcessHeap(), 0, size + dir->SizeOfZeroFill )))
|
|
|
|
{
|
|
|
|
while (i) RtlFreeHeap( GetProcessHeap(), 0, pointers[--i] );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, pointers );
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
memcpy( pointers[i], (void *)dir->StartAddressOfRawData, size );
|
|
|
|
memset( (char *)pointers[i] + size, 0, dir->SizeOfZeroFill );
|
2003-05-14 21:51:14 +02:00
|
|
|
|
2013-12-23 18:16:51 +01:00
|
|
|
TRACE( "thread %04x slot %u: %u/%u bytes at %p\n",
|
|
|
|
GetCurrentThreadId(), i, size, dir->SizeOfZeroFill, pointers[i] );
|
2003-05-14 21:51:14 +02:00
|
|
|
}
|
2003-08-28 01:14:29 +02:00
|
|
|
NtCurrentTeb()->ThreadLocalStoragePointer = pointers;
|
2016-07-28 23:33:25 +02:00
|
|
|
#if defined(__APPLE__) && defined(__x86_64__)
|
|
|
|
__asm__ volatile (".byte 0x65\n\tmovq %0,%c1"
|
|
|
|
:
|
|
|
|
: "r" (pointers), "n" (FIELD_OFFSET(TEB, ThreadLocalStoragePointer)));
|
|
|
|
#endif
|
2003-05-14 21:51:14 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-08 06:13:26 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* call_tls_callbacks
|
|
|
|
*/
|
|
|
|
static void call_tls_callbacks( HMODULE module, UINT reason )
|
|
|
|
{
|
|
|
|
const IMAGE_TLS_DIRECTORY *dir;
|
|
|
|
const PIMAGE_TLS_CALLBACK *callback;
|
|
|
|
ULONG dirsize;
|
|
|
|
|
2019-05-24 11:22:16 +02:00
|
|
|
if (reason == DLL_WINE_PREATTACH) return;
|
|
|
|
|
2003-05-08 06:13:26 +02:00
|
|
|
dir = RtlImageDirectoryEntryToData( module, TRUE, IMAGE_DIRECTORY_ENTRY_TLS, &dirsize );
|
|
|
|
if (!dir || !dir->AddressOfCallBacks) return;
|
|
|
|
|
2005-07-19 13:44:32 +02:00
|
|
|
for (callback = (const PIMAGE_TLS_CALLBACK *)dir->AddressOfCallBacks; *callback; callback++)
|
2003-05-08 06:13:26 +02:00
|
|
|
{
|
2017-11-25 11:45:20 +01:00
|
|
|
TRACE_(relay)("\1Call TLS callback (proc=%p,module=%p,reason=%s,reserved=0)\n",
|
|
|
|
*callback, module, reason_names[reason] );
|
2007-03-13 11:21:37 +01:00
|
|
|
__TRY
|
|
|
|
{
|
2014-09-07 01:46:52 +02:00
|
|
|
call_dll_entry_point( (DLLENTRYPROC)*callback, module, reason, NULL );
|
2007-03-13 11:21:37 +01:00
|
|
|
}
|
2008-02-15 16:43:24 +01:00
|
|
|
__EXCEPT_ALL
|
2007-03-13 11:21:37 +01:00
|
|
|
{
|
2018-08-20 20:42:54 +02:00
|
|
|
TRACE_(relay)("\1exception %08x in TLS callback (proc=%p,module=%p,reason=%s,reserved=0)\n",
|
|
|
|
GetExceptionCode(), callback, module, reason_names[reason] );
|
2007-03-13 11:21:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
__ENDTRY
|
2017-11-25 11:45:20 +01:00
|
|
|
TRACE_(relay)("\1Ret TLS callback (proc=%p,module=%p,reason=%s,reserved=0)\n",
|
|
|
|
*callback, module, reason_names[reason] );
|
2003-05-08 06:13:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 12:22:24 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* call_constructors
|
|
|
|
*/
|
|
|
|
static void call_constructors( WINE_MODREF *wm )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_DLINFO
|
|
|
|
extern char **__wine_main_environ;
|
|
|
|
struct link_map *map;
|
|
|
|
void (*init_func)(int, char **, char **) = NULL;
|
|
|
|
void (**init_array)(int, char **, char **) = NULL;
|
|
|
|
ULONG_PTR i, init_arraysz = 0;
|
2020-04-19 10:43:44 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
const Elf64_Dyn *dyn;
|
|
|
|
#else
|
|
|
|
const Elf32_Dyn *dyn;
|
|
|
|
#endif
|
2020-04-16 12:22:24 +02:00
|
|
|
|
|
|
|
if (dlinfo( wm->so_handle, RTLD_DI_LINKMAP, &map ) == -1) return;
|
2020-04-19 10:43:44 +02:00
|
|
|
for (dyn = map->l_ld; dyn->d_tag; dyn++)
|
2020-04-16 12:22:24 +02:00
|
|
|
{
|
2020-04-19 10:43:44 +02:00
|
|
|
switch (dyn->d_tag)
|
2020-04-16 12:22:24 +02:00
|
|
|
{
|
2020-04-19 10:43:44 +02:00
|
|
|
case 0x60009990: init_array = (void *)((char *)map->l_addr + dyn->d_un.d_val); break;
|
|
|
|
case 0x60009991: init_arraysz = dyn->d_un.d_val; break;
|
|
|
|
case 0x60009992: init_func = (void *)((char *)map->l_addr + dyn->d_un.d_val); break;
|
2020-04-16 12:22:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "%s: got init_func %p init_array %p %lu\n", debugstr_us( &wm->ldr.BaseDllName ),
|
|
|
|
init_func, init_array, init_arraysz );
|
|
|
|
|
|
|
|
if (init_func) init_func( __wine_main_argc, __wine_main_argv, __wine_main_environ );
|
|
|
|
|
|
|
|
if (init_array)
|
|
|
|
for (i = 0; i < init_arraysz / sizeof(*init_array); i++)
|
|
|
|
init_array[i]( __wine_main_argc, __wine_main_argv, __wine_main_environ );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-20 05:55:59 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* MODULE_InitDLL
|
|
|
|
*/
|
2008-02-13 13:36:13 +01:00
|
|
|
static NTSTATUS MODULE_InitDLL( WINE_MODREF *wm, UINT reason, LPVOID lpReserved )
|
2003-03-20 05:55:59 +01:00
|
|
|
{
|
2003-09-29 22:42:24 +02:00
|
|
|
WCHAR mod_name[32];
|
2008-02-13 13:36:13 +01:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
2003-04-04 21:50:17 +02:00
|
|
|
DLLENTRYPROC entry = wm->ldr.EntryPoint;
|
|
|
|
void *module = wm->ldr.BaseAddress;
|
2012-09-29 22:29:11 +02:00
|
|
|
BOOL retv = FALSE;
|
2003-03-20 05:55:59 +01:00
|
|
|
|
|
|
|
/* Skip calls for modules loaded with special load flags */
|
|
|
|
|
2008-02-13 13:36:13 +01:00
|
|
|
if (wm->ldr.Flags & LDR_DONT_RESOLVE_REFS) return STATUS_SUCCESS;
|
2003-05-08 06:13:26 +02:00
|
|
|
if (wm->ldr.TlsIndex != -1) call_tls_callbacks( wm->ldr.BaseAddress, reason );
|
2020-04-16 12:22:24 +02:00
|
|
|
if (wm->so_handle && reason == DLL_PROCESS_ATTACH) call_constructors( wm );
|
2020-04-14 12:55:38 +02:00
|
|
|
if (!entry) return STATUS_SUCCESS;
|
2003-04-04 21:50:17 +02:00
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
2003-04-08 01:27:54 +02:00
|
|
|
{
|
2003-10-24 02:32:36 +02:00
|
|
|
size_t len = min( wm->ldr.BaseDllName.Length, sizeof(mod_name)-sizeof(WCHAR) );
|
2003-09-29 22:42:24 +02:00
|
|
|
memcpy( mod_name, wm->ldr.BaseDllName.Buffer, len );
|
|
|
|
mod_name[len / sizeof(WCHAR)] = 0;
|
2017-11-25 11:45:20 +01:00
|
|
|
TRACE_(relay)("\1Call PE DLL (proc=%p,module=%p %s,reason=%s,res=%p)\n",
|
|
|
|
entry, module, debugstr_w(mod_name), reason_names[reason], lpReserved );
|
2003-04-08 01:27:54 +02:00
|
|
|
}
|
2003-09-29 22:42:24 +02:00
|
|
|
else TRACE("(%p %s,%s,%p) - CALL\n", module, debugstr_w(wm->ldr.BaseDllName.Buffer),
|
|
|
|
reason_names[reason], lpReserved );
|
2003-03-20 05:55:59 +01:00
|
|
|
|
2008-02-13 13:36:13 +01:00
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
retv = call_dll_entry_point( entry, module, reason, lpReserved );
|
|
|
|
if (!retv)
|
|
|
|
status = STATUS_DLL_INIT_FAILED;
|
|
|
|
}
|
2008-02-15 16:43:24 +01:00
|
|
|
__EXCEPT_ALL
|
2008-02-13 13:36:13 +01:00
|
|
|
{
|
|
|
|
status = GetExceptionCode();
|
2018-08-20 20:42:54 +02:00
|
|
|
TRACE_(relay)("\1exception %08x in PE entry point (proc=%p,module=%p,reason=%s,res=%p)\n",
|
|
|
|
status, entry, module, reason_names[reason], lpReserved );
|
2008-02-13 13:36:13 +01:00
|
|
|
}
|
|
|
|
__ENDTRY
|
2003-03-20 05:55:59 +01:00
|
|
|
|
|
|
|
/* The state of the module list may have changed due to the call
|
2003-04-04 21:50:17 +02:00
|
|
|
to the dll. We cannot assume that this module has not been
|
2003-03-20 05:55:59 +01:00
|
|
|
deleted. */
|
2003-04-08 01:27:54 +02:00
|
|
|
if (TRACE_ON(relay))
|
2017-11-25 11:45:20 +01:00
|
|
|
TRACE_(relay)("\1Ret PE DLL (proc=%p,module=%p %s,reason=%s,res=%p) retval=%x\n",
|
|
|
|
entry, module, debugstr_w(mod_name), reason_names[reason], lpReserved, retv );
|
|
|
|
else
|
|
|
|
TRACE("(%p,%s,%p) - RETURN %d\n", module, reason_names[reason], lpReserved, retv );
|
2003-03-20 05:55:59 +01:00
|
|
|
|
2008-02-13 13:36:13 +01:00
|
|
|
return status;
|
2003-03-20 05:55:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-10-06 23:18:51 +02:00
|
|
|
* process_attach
|
2003-03-20 05:55:59 +01:00
|
|
|
*
|
|
|
|
* Send the process attach notification to all DLLs the given module
|
|
|
|
* depends on (recursively). This is somewhat complicated due to the fact that
|
|
|
|
*
|
|
|
|
* - we have to respect the module dependencies, i.e. modules implicitly
|
|
|
|
* referenced by another module have to be initialized before the module
|
|
|
|
* itself can be initialized
|
|
|
|
*
|
|
|
|
* - the initialization routine of a DLL can itself call LoadLibrary,
|
|
|
|
* thereby introducing a whole new set of dependencies (even involving
|
|
|
|
* the 'old' modules) at any time during the whole process
|
|
|
|
*
|
|
|
|
* (Note that this routine can be recursively entered not only directly
|
|
|
|
* from itself, but also via LoadLibrary from one of the called initialization
|
|
|
|
* routines.)
|
|
|
|
*
|
|
|
|
* Furthermore, we need to rearrange the main WINE_MODREF list to allow
|
|
|
|
* the process *detach* notifications to be sent in the correct order.
|
|
|
|
* This must not only take into account module dependencies, but also
|
|
|
|
* 'hidden' dependencies created by modules calling LoadLibrary in their
|
|
|
|
* attach notification routine.
|
|
|
|
*
|
|
|
|
* The strategy is rather simple: we move a WINE_MODREF to the head of the
|
|
|
|
* list after the attach notification has returned. This implies that the
|
|
|
|
* detach notifications are called in the reverse of the sequence the attach
|
|
|
|
* notifications *returned*.
|
2003-10-06 23:18:51 +02:00
|
|
|
*
|
|
|
|
* The loader_section must be locked while calling this function.
|
2003-03-20 05:55:59 +01:00
|
|
|
*/
|
2003-10-06 23:18:51 +02:00
|
|
|
static NTSTATUS process_attach( WINE_MODREF *wm, LPVOID lpReserved )
|
2003-03-20 05:55:59 +01:00
|
|
|
{
|
2003-05-14 21:51:14 +02:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
2007-07-26 11:06:17 +02:00
|
|
|
ULONG_PTR cookie;
|
2003-03-20 05:55:59 +01:00
|
|
|
int i;
|
|
|
|
|
2005-08-09 22:45:46 +02:00
|
|
|
if (process_detaching) return status;
|
|
|
|
|
2003-03-20 05:55:59 +01:00
|
|
|
/* prevent infinite recursion in case of cyclical dependencies */
|
2003-03-21 00:40:08 +01:00
|
|
|
if ( ( wm->ldr.Flags & LDR_LOAD_IN_PROGRESS )
|
|
|
|
|| ( wm->ldr.Flags & LDR_PROCESS_ATTACHED ) )
|
2003-10-06 23:18:51 +02:00
|
|
|
return status;
|
2003-03-20 05:55:59 +01:00
|
|
|
|
2003-09-29 22:42:24 +02:00
|
|
|
TRACE("(%s,%p) - START\n", debugstr_w(wm->ldr.BaseDllName.Buffer), lpReserved );
|
2003-03-20 05:55:59 +01:00
|
|
|
|
|
|
|
/* Tag current MODREF to prevent recursive loop */
|
2003-03-21 00:40:08 +01:00
|
|
|
wm->ldr.Flags |= LDR_LOAD_IN_PROGRESS;
|
2007-08-30 16:34:27 +02:00
|
|
|
if (lpReserved) wm->ldr.LoadCount = -1; /* pin it if imported by the main exe */
|
2007-07-26 11:06:17 +02:00
|
|
|
if (wm->ldr.ActivationContext) RtlActivateActivationContext( 0, wm->ldr.ActivationContext, &cookie );
|
2003-03-20 05:55:59 +01:00
|
|
|
|
|
|
|
/* Recursively attach all DLLs this one depends on */
|
2003-05-14 21:51:14 +02:00
|
|
|
for ( i = 0; i < wm->nDeps; i++ )
|
|
|
|
{
|
|
|
|
if (!wm->deps[i]) continue;
|
2003-10-06 23:18:51 +02:00
|
|
|
if ((status = process_attach( wm->deps[i], lpReserved )) != STATUS_SUCCESS) break;
|
2003-05-14 21:51:14 +02:00
|
|
|
}
|
2003-03-20 05:55:59 +01:00
|
|
|
|
2015-08-11 19:21:57 +02:00
|
|
|
if (!wm->ldr.InInitializationOrderModuleList.Flink)
|
|
|
|
InsertTailList(&NtCurrentTeb()->Peb->LdrData->InInitializationOrderModuleList,
|
|
|
|
&wm->ldr.InInitializationOrderModuleList);
|
|
|
|
|
2003-03-20 05:55:59 +01:00
|
|
|
/* Call DLL entry point */
|
2003-05-14 21:51:14 +02:00
|
|
|
if (status == STATUS_SUCCESS)
|
2003-03-20 05:55:59 +01:00
|
|
|
{
|
2003-04-08 01:27:54 +02:00
|
|
|
WINE_MODREF *prev = current_modref;
|
|
|
|
current_modref = wm;
|
2018-06-22 03:54:56 +02:00
|
|
|
|
|
|
|
call_ldr_notifications( LDR_DLL_NOTIFICATION_REASON_LOADED, &wm->ldr );
|
2008-02-13 13:36:13 +01:00
|
|
|
status = MODULE_InitDLL( wm, DLL_PROCESS_ATTACH, lpReserved );
|
|
|
|
if (status == STATUS_SUCCESS)
|
2018-06-22 03:54:56 +02:00
|
|
|
{
|
2003-05-14 21:51:14 +02:00
|
|
|
wm->ldr.Flags |= LDR_PROCESS_ATTACHED;
|
2018-06-22 03:54:56 +02:00
|
|
|
}
|
2003-05-14 21:51:14 +02:00
|
|
|
else
|
2005-01-11 17:01:31 +01:00
|
|
|
{
|
2009-11-25 08:18:07 +01:00
|
|
|
MODULE_InitDLL( wm, DLL_PROCESS_DETACH, lpReserved );
|
2018-06-22 03:54:56 +02:00
|
|
|
call_ldr_notifications( LDR_DLL_NOTIFICATION_REASON_UNLOADED, &wm->ldr );
|
|
|
|
|
2005-01-11 17:01:31 +01:00
|
|
|
/* point to the name so LdrInitializeThunk can print it */
|
|
|
|
last_failed_modref = wm;
|
|
|
|
WARN("Initialization of %s failed\n", debugstr_w(wm->ldr.BaseDllName.Buffer));
|
|
|
|
}
|
2003-04-08 01:27:54 +02:00
|
|
|
current_modref = prev;
|
2003-03-20 05:55:59 +01:00
|
|
|
}
|
|
|
|
|
2007-07-26 11:06:17 +02:00
|
|
|
if (wm->ldr.ActivationContext) RtlDeactivateActivationContext( 0, cookie );
|
2003-03-20 05:55:59 +01:00
|
|
|
/* Remove recursion flag */
|
2003-03-21 00:40:08 +01:00
|
|
|
wm->ldr.Flags &= ~LDR_LOAD_IN_PROGRESS;
|
2003-03-20 05:55:59 +01:00
|
|
|
|
2003-09-29 22:42:24 +02:00
|
|
|
TRACE("(%s,%p) - END\n", debugstr_w(wm->ldr.BaseDllName.Buffer), lpReserved );
|
2003-05-14 21:51:14 +02:00
|
|
|
return status;
|
2003-03-20 05:55:59 +01:00
|
|
|
}
|
|
|
|
|
2005-10-26 14:12:44 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* attach_implicitly_loaded_dlls
|
|
|
|
*
|
|
|
|
* Attach to the (builtin) dlls that have been implicitly loaded because
|
|
|
|
* of a dependency at the Unix level, but not imported at the Win32 level.
|
|
|
|
*/
|
|
|
|
static void attach_implicitly_loaded_dlls( LPVOID reserved )
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY mark, entry;
|
|
|
|
|
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
|
|
|
{
|
|
|
|
LDR_MODULE *mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
|
|
|
|
|
2020-04-14 12:55:38 +02:00
|
|
|
if (!(mod->Flags & LDR_IMAGE_IS_DLL)) continue;
|
2005-10-26 14:12:44 +02:00
|
|
|
if (mod->Flags & (LDR_LOAD_IN_PROGRESS | LDR_PROCESS_ATTACHED)) continue;
|
|
|
|
TRACE( "found implicitly loaded %s, attaching to it\n",
|
|
|
|
debugstr_w(mod->BaseDllName.Buffer));
|
|
|
|
process_attach( CONTAINING_RECORD(mod, WINE_MODREF, ldr), reserved );
|
|
|
|
break; /* restart the search from the start */
|
|
|
|
}
|
|
|
|
if (entry == mark) break; /* nothing found */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-20 05:55:59 +01:00
|
|
|
/*************************************************************************
|
2003-10-06 23:18:51 +02:00
|
|
|
* process_detach
|
2003-03-20 05:55:59 +01:00
|
|
|
*
|
|
|
|
* Send DLL process detach notifications. See the comment about calling
|
2013-07-19 12:13:09 +02:00
|
|
|
* sequence at process_attach.
|
2003-03-20 05:55:59 +01:00
|
|
|
*/
|
2013-07-19 12:13:09 +02:00
|
|
|
static void process_detach(void)
|
2003-03-20 05:55:59 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
PLIST_ENTRY mark, entry;
|
|
|
|
PLDR_MODULE mod;
|
2003-03-20 05:55:59 +01:00
|
|
|
|
2003-07-01 05:38:56 +02:00
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InInitializationOrderModuleList;
|
2003-03-20 05:55:59 +01:00
|
|
|
do
|
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
for (entry = mark->Blink; entry != mark; entry = entry->Blink)
|
2003-03-20 05:55:59 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
mod = CONTAINING_RECORD(entry, LDR_MODULE,
|
|
|
|
InInitializationOrderModuleList);
|
2003-03-20 05:55:59 +01:00
|
|
|
/* Check whether to detach this DLL */
|
2003-07-01 05:38:56 +02:00
|
|
|
if ( !(mod->Flags & LDR_PROCESS_ATTACHED) )
|
2003-03-20 05:55:59 +01:00
|
|
|
continue;
|
2013-07-19 12:13:09 +02:00
|
|
|
if ( mod->LoadCount && !process_detaching )
|
2003-03-20 05:55:59 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Call detach notification */
|
2003-07-01 05:38:56 +02:00
|
|
|
mod->Flags &= ~LDR_PROCESS_ATTACHED;
|
|
|
|
MODULE_InitDLL( CONTAINING_RECORD(mod, WINE_MODREF, ldr),
|
2013-07-19 12:13:09 +02:00
|
|
|
DLL_PROCESS_DETACH, ULongToPtr(process_detaching) );
|
2018-06-22 03:54:56 +02:00
|
|
|
call_ldr_notifications( LDR_DLL_NOTIFICATION_REASON_UNLOADED, mod );
|
2003-03-20 05:55:59 +01:00
|
|
|
|
|
|
|
/* Restart at head of WINE_MODREF list, as entries might have
|
|
|
|
been added and/or removed while performing the call ... */
|
|
|
|
break;
|
|
|
|
}
|
2003-07-01 05:38:56 +02:00
|
|
|
} while (entry != mark);
|
2003-03-20 05:55:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2017-11-20 17:09:29 +01:00
|
|
|
* thread_attach
|
2003-03-20 05:55:59 +01:00
|
|
|
*
|
|
|
|
* Send DLL thread attach notifications. These are sent in the
|
|
|
|
* reverse sequence of process detach notification.
|
2017-11-20 17:09:29 +01:00
|
|
|
* The loader_section must be locked while calling this function.
|
2003-03-20 05:55:59 +01:00
|
|
|
*/
|
2017-11-20 17:09:29 +01:00
|
|
|
static void thread_attach(void)
|
2003-03-20 05:55:59 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
PLIST_ENTRY mark, entry;
|
|
|
|
PLDR_MODULE mod;
|
2003-03-20 05:55:59 +01:00
|
|
|
|
2003-07-01 05:38:56 +02:00
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InInitializationOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
2003-03-20 05:55:59 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
mod = CONTAINING_RECORD(entry, LDR_MODULE,
|
|
|
|
InInitializationOrderModuleList);
|
|
|
|
if ( !(mod->Flags & LDR_PROCESS_ATTACHED) )
|
2003-03-20 05:55:59 +01:00
|
|
|
continue;
|
2003-07-01 05:38:56 +02:00
|
|
|
if ( mod->Flags & LDR_NO_DLL_CALLS )
|
2003-03-20 05:55:59 +01:00
|
|
|
continue;
|
|
|
|
|
2017-11-20 17:09:29 +01:00
|
|
|
MODULE_InitDLL( CONTAINING_RECORD(mod, WINE_MODREF, ldr), DLL_THREAD_ATTACH, NULL );
|
2003-03-20 05:55:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-04 05:36:56 +01:00
|
|
|
/******************************************************************
|
|
|
|
* LdrDisableThreadCalloutsForDll (NTDLL.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrDisableThreadCalloutsForDll(HMODULE hModule)
|
2002-01-29 19:30:16 +01:00
|
|
|
{
|
2003-03-04 05:36:56 +01:00
|
|
|
WINE_MODREF *wm;
|
|
|
|
NTSTATUS ret = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
|
2003-04-05 07:16:11 +02:00
|
|
|
wm = get_modref( hModule );
|
2003-05-08 06:13:26 +02:00
|
|
|
if (!wm || wm->ldr.TlsIndex != -1)
|
2003-03-04 05:36:56 +01:00
|
|
|
ret = STATUS_DLL_NOT_FOUND;
|
2002-01-29 19:30:16 +01:00
|
|
|
else
|
2003-03-21 00:40:08 +01:00
|
|
|
wm->ldr.Flags |= LDR_NO_DLL_CALLS;
|
2003-03-04 05:36:56 +01:00
|
|
|
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
|
|
|
|
return ret;
|
2002-01-29 19:30:16 +01:00
|
|
|
}
|
2002-06-10 04:28:00 +02:00
|
|
|
|
2003-03-18 19:29:13 +01:00
|
|
|
/******************************************************************
|
|
|
|
* LdrFindEntryForAddress (NTDLL.@)
|
|
|
|
*
|
|
|
|
* The loader_section must be locked while calling this function
|
|
|
|
*/
|
2003-07-01 05:38:56 +02:00
|
|
|
NTSTATUS WINAPI LdrFindEntryForAddress(const void* addr, PLDR_MODULE* pmod)
|
2003-03-18 19:29:13 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
PLIST_ENTRY mark, entry;
|
|
|
|
PLDR_MODULE mod;
|
2003-03-18 19:29:13 +01:00
|
|
|
|
2003-07-01 05:38:56 +02:00
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
2003-03-18 19:29:13 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
mod = CONTAINING_RECORD(entry, LDR_MODULE, InMemoryOrderModuleList);
|
2009-03-17 00:12:11 +01:00
|
|
|
if (mod->BaseAddress <= addr &&
|
2004-06-15 02:47:00 +02:00
|
|
|
(const char *)addr < (char*)mod->BaseAddress + mod->SizeOfImage)
|
2003-03-18 19:29:13 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
*pmod = mod;
|
2003-03-18 19:29:13 +01:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:59:41 +02:00
|
|
|
/******************************************************************
|
|
|
|
* LdrEnumerateLoadedModules (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrEnumerateLoadedModules( void *unknown, LDRENUMPROC callback, void *context )
|
|
|
|
{
|
|
|
|
LIST_ENTRY *mark, *entry;
|
|
|
|
LDR_MODULE *mod;
|
|
|
|
BOOLEAN stop = FALSE;
|
|
|
|
|
|
|
|
TRACE( "(%p, %p, %p)\n", unknown, callback, context );
|
|
|
|
|
|
|
|
if (unknown || !callback)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
|
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
|
|
|
{
|
|
|
|
mod = CONTAINING_RECORD( entry, LDR_MODULE, InMemoryOrderModuleList );
|
|
|
|
callback( mod, context, &stop );
|
|
|
|
if (stop) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-05-15 13:50:49 +02:00
|
|
|
/******************************************************************
|
|
|
|
* LdrRegisterDllNotification (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrRegisterDllNotification(ULONG flags, PLDR_DLL_NOTIFICATION_FUNCTION callback,
|
|
|
|
void *context, void **cookie)
|
|
|
|
{
|
2018-06-22 03:54:56 +02:00
|
|
|
struct ldr_notification *notify;
|
|
|
|
|
|
|
|
TRACE( "(%x, %p, %p, %p)\n", flags, callback, context, cookie );
|
|
|
|
|
|
|
|
if (!callback || !cookie)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
FIXME( "ignoring flags %x\n", flags );
|
|
|
|
|
|
|
|
notify = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*notify) );
|
|
|
|
if (!notify) return STATUS_NO_MEMORY;
|
|
|
|
notify->callback = callback;
|
|
|
|
notify->context = context;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
list_add_tail( &ldr_notifications, ¬ify->entry );
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
|
|
|
|
*cookie = notify;
|
|
|
|
return STATUS_SUCCESS;
|
2018-05-15 13:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* LdrUnregisterDllNotification (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrUnregisterDllNotification( void *cookie )
|
|
|
|
{
|
2018-06-22 03:54:56 +02:00
|
|
|
struct ldr_notification *notify = cookie;
|
|
|
|
|
|
|
|
TRACE( "(%p)\n", cookie );
|
|
|
|
|
|
|
|
if (!notify) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
list_remove( ¬ify->entry );
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, notify );
|
|
|
|
return STATUS_SUCCESS;
|
2018-05-15 13:50:49 +02:00
|
|
|
}
|
|
|
|
|
2003-03-20 05:29:21 +01:00
|
|
|
/******************************************************************
|
|
|
|
* LdrLockLoaderLock (NTDLL.@)
|
|
|
|
*
|
2014-05-16 07:03:27 +02:00
|
|
|
* Note: some flags are not implemented.
|
2003-03-20 05:29:21 +01:00
|
|
|
* Flag 0x01 is used to raise exceptions on errors.
|
|
|
|
*/
|
2014-05-28 06:58:59 +02:00
|
|
|
NTSTATUS WINAPI LdrLockLoaderLock( ULONG flags, ULONG *result, ULONG_PTR *magic )
|
2003-03-20 05:29:21 +01:00
|
|
|
{
|
2014-05-16 07:03:27 +02:00
|
|
|
if (flags & ~0x2) FIXME( "flags %x not supported\n", flags );
|
2003-03-20 05:29:21 +01:00
|
|
|
|
2014-05-16 07:03:27 +02:00
|
|
|
if (result) *result = 0;
|
|
|
|
if (magic) *magic = 0;
|
|
|
|
if (flags & ~0x3) return STATUS_INVALID_PARAMETER_1;
|
|
|
|
if (!result && (flags & 0x2)) return STATUS_INVALID_PARAMETER_2;
|
2003-03-20 05:29:21 +01:00
|
|
|
if (!magic) return STATUS_INVALID_PARAMETER_3;
|
2014-05-16 07:03:27 +02:00
|
|
|
|
|
|
|
if (flags & 0x2)
|
|
|
|
{
|
|
|
|
if (!RtlTryEnterCriticalSection( &loader_section ))
|
|
|
|
{
|
|
|
|
*result = 2;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
*result = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
if (result) *result = 1;
|
|
|
|
}
|
2003-03-20 05:29:21 +01:00
|
|
|
*magic = GetCurrentThreadId();
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* LdrUnlockLoaderUnlock (NTDLL.@)
|
|
|
|
*/
|
2014-05-28 06:58:59 +02:00
|
|
|
NTSTATUS WINAPI LdrUnlockLoaderLock( ULONG flags, ULONG_PTR magic )
|
2003-03-20 05:29:21 +01:00
|
|
|
{
|
|
|
|
if (magic)
|
|
|
|
{
|
|
|
|
if (magic != GetCurrentThreadId()) return STATUS_INVALID_PARAMETER_2;
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-05 07:16:11 +02:00
|
|
|
/******************************************************************
|
|
|
|
* LdrGetProcedureAddress (NTDLL.@)
|
2003-03-07 00:41:37 +01:00
|
|
|
*/
|
2003-09-29 22:42:24 +02:00
|
|
|
NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE module, const ANSI_STRING *name,
|
|
|
|
ULONG ord, PVOID *address)
|
2003-03-07 00:41:37 +01:00
|
|
|
{
|
2003-04-05 07:16:11 +02:00
|
|
|
IMAGE_EXPORT_DIRECTORY *exports;
|
|
|
|
DWORD exp_size;
|
|
|
|
NTSTATUS ret = STATUS_PROCEDURE_NOT_FOUND;
|
2002-06-10 04:28:00 +02:00
|
|
|
|
2003-03-07 00:41:37 +01:00
|
|
|
RtlEnterCriticalSection( &loader_section );
|
2003-04-05 07:16:11 +02:00
|
|
|
|
2005-11-29 17:10:30 +01:00
|
|
|
/* check if the module itself is invalid to return the proper error */
|
|
|
|
if (!get_modref( module )) ret = STATUS_DLL_NOT_FOUND;
|
|
|
|
else if ((exports = RtlImageDirectoryEntryToData( module, TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
|
2003-03-07 00:41:37 +01:00
|
|
|
{
|
2007-12-06 21:40:37 +01:00
|
|
|
LPCWSTR load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer;
|
|
|
|
void *proc = name ? find_named_export( module, exports, exp_size, name->Buffer, -1, load_path )
|
|
|
|
: find_ordinal_export( module, exports, exp_size, ord - exports->Base, load_path );
|
2003-04-05 07:16:11 +02:00
|
|
|
if (proc)
|
|
|
|
{
|
|
|
|
*address = proc;
|
|
|
|
ret = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2003-03-07 00:41:37 +01:00
|
|
|
|
2003-04-05 07:16:11 +02:00
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
return ret;
|
2002-06-10 04:28:00 +02:00
|
|
|
}
|
2002-08-09 21:57:38 +02:00
|
|
|
|
|
|
|
|
2014-02-25 23:08:24 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* is_16bit_builtin
|
|
|
|
*/
|
|
|
|
static BOOL is_16bit_builtin( HMODULE module )
|
|
|
|
{
|
|
|
|
const IMAGE_EXPORT_DIRECTORY *exports;
|
|
|
|
DWORD exp_size;
|
|
|
|
|
|
|
|
if (!(exports = RtlImageDirectoryEntryToData( module, TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return find_named_export( module, exports, exp_size, "__wine_spec_dos_header", -1, NULL ) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 10:26:13 +02:00
|
|
|
/* adjust an array of pointers to make them into RVAs */
|
|
|
|
static inline void fixup_rva_ptrs( void *array, BYTE *base, unsigned int count )
|
|
|
|
{
|
|
|
|
BYTE **src = array;
|
|
|
|
DWORD *dst = array;
|
|
|
|
|
|
|
|
for ( ; count; count--, src++, dst++) *dst = *src ? *src - base : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fixup an array of RVAs by adding the specified delta */
|
|
|
|
static inline void fixup_rva_dwords( DWORD *ptr, int delta, unsigned int count )
|
|
|
|
{
|
|
|
|
for ( ; count; count--, ptr++) if (*ptr) *ptr += delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* fixup an array of name/ordinal RVAs by adding the specified delta */
|
|
|
|
static inline void fixup_rva_names( UINT_PTR *ptr, int delta )
|
|
|
|
{
|
|
|
|
for ( ; *ptr; ptr++) if (!(*ptr & IMAGE_ORDINAL_FLAG)) *ptr += delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* fixup RVAs in the resource directory */
|
|
|
|
static void fixup_so_resources( IMAGE_RESOURCE_DIRECTORY *dir, BYTE *root, int delta )
|
|
|
|
{
|
|
|
|
IMAGE_RESOURCE_DIRECTORY_ENTRY *entry = (IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < dir->NumberOfNamedEntries + dir->NumberOfIdEntries; i++, entry++)
|
|
|
|
{
|
|
|
|
void *ptr = root + entry->u2.s2.OffsetToDirectory;
|
|
|
|
if (entry->u2.s2.DataIsDirectory) fixup_so_resources( ptr, root, delta );
|
|
|
|
else fixup_rva_dwords( &((IMAGE_RESOURCE_DATA_ENTRY *)ptr)->OffsetToData, delta, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* map_so_dll
|
2003-09-19 06:04:57 +02:00
|
|
|
*
|
2020-04-16 10:26:13 +02:00
|
|
|
* Map a builtin dll in memory and fixup RVAs.
|
2003-09-19 06:04:57 +02:00
|
|
|
*/
|
2020-04-16 10:26:13 +02:00
|
|
|
static NTSTATUS map_so_dll( const IMAGE_NT_HEADERS *nt_descr, HMODULE module )
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2020-04-16 10:26:13 +02:00
|
|
|
static const char builtin_signature[32] = "Wine builtin DLL";
|
|
|
|
IMAGE_DATA_DIRECTORY *dir;
|
|
|
|
IMAGE_DOS_HEADER *dos;
|
2003-09-19 06:04:57 +02:00
|
|
|
IMAGE_NT_HEADERS *nt;
|
2020-04-16 10:26:13 +02:00
|
|
|
IMAGE_SECTION_HEADER *sec;
|
|
|
|
BYTE *addr = (BYTE *)module;
|
|
|
|
DWORD code_start, code_end, data_start, data_end, align_mask;
|
|
|
|
int delta, nb_sections = 2; /* code + data */
|
|
|
|
unsigned int i;
|
|
|
|
DWORD size = (sizeof(IMAGE_DOS_HEADER)
|
|
|
|
+ sizeof(builtin_signature)
|
|
|
|
+ sizeof(IMAGE_NT_HEADERS)
|
|
|
|
+ nb_sections * sizeof(IMAGE_SECTION_HEADER));
|
|
|
|
|
|
|
|
if (wine_anon_mmap( addr, size, PROT_READ | PROT_WRITE, MAP_FIXED ) != addr) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
dos = (IMAGE_DOS_HEADER *)addr;
|
|
|
|
nt = (IMAGE_NT_HEADERS *)((BYTE *)(dos + 1) + sizeof(builtin_signature));
|
|
|
|
sec = (IMAGE_SECTION_HEADER *)(nt + 1);
|
|
|
|
|
|
|
|
/* build the DOS and NT headers */
|
|
|
|
|
|
|
|
dos->e_magic = IMAGE_DOS_SIGNATURE;
|
|
|
|
dos->e_cblp = 0x90;
|
|
|
|
dos->e_cp = 3;
|
|
|
|
dos->e_cparhdr = (sizeof(*dos) + 0xf) / 0x10;
|
|
|
|
dos->e_minalloc = 0;
|
|
|
|
dos->e_maxalloc = 0xffff;
|
|
|
|
dos->e_ss = 0x0000;
|
|
|
|
dos->e_sp = 0x00b8;
|
|
|
|
dos->e_lfanew = sizeof(*dos) + sizeof(builtin_signature);
|
|
|
|
|
|
|
|
*nt = *nt_descr;
|
|
|
|
|
|
|
|
delta = (const BYTE *)nt_descr - addr;
|
|
|
|
align_mask = nt->OptionalHeader.SectionAlignment - 1;
|
|
|
|
code_start = (size + align_mask) & ~align_mask;
|
|
|
|
data_start = delta & ~align_mask;
|
|
|
|
#ifdef __APPLE__
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2020-04-16 10:26:13 +02:00
|
|
|
Dl_info dli;
|
|
|
|
unsigned long data_size;
|
|
|
|
/* need the mach_header, not the PE header, to give to getsegmentdata(3) */
|
|
|
|
dladdr(addr, &dli);
|
|
|
|
code_end = getsegmentdata(dli.dli_fbase, "__DATA", &data_size) - addr;
|
|
|
|
data_end = (code_end + data_size + align_mask) & ~align_mask;
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
2020-04-16 10:26:13 +02:00
|
|
|
#else
|
|
|
|
code_end = data_start;
|
|
|
|
data_end = (nt->OptionalHeader.SizeOfImage + delta + align_mask) & ~align_mask;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fixup_rva_ptrs( &nt->OptionalHeader.AddressOfEntryPoint, addr, 1 );
|
|
|
|
|
|
|
|
nt->FileHeader.NumberOfSections = nb_sections;
|
|
|
|
nt->OptionalHeader.BaseOfCode = code_start;
|
|
|
|
#ifndef _WIN64
|
|
|
|
nt->OptionalHeader.BaseOfData = data_start;
|
|
|
|
#endif
|
|
|
|
nt->OptionalHeader.SizeOfCode = code_end - code_start;
|
|
|
|
nt->OptionalHeader.SizeOfInitializedData = data_end - data_start;
|
|
|
|
nt->OptionalHeader.SizeOfUninitializedData = 0;
|
|
|
|
nt->OptionalHeader.SizeOfImage = data_end;
|
|
|
|
nt->OptionalHeader.ImageBase = (ULONG_PTR)addr;
|
|
|
|
|
|
|
|
/* build the code section */
|
|
|
|
|
|
|
|
memcpy( sec->Name, ".text", sizeof(".text") );
|
|
|
|
sec->SizeOfRawData = code_end - code_start;
|
|
|
|
sec->Misc.VirtualSize = sec->SizeOfRawData;
|
|
|
|
sec->VirtualAddress = code_start;
|
|
|
|
sec->PointerToRawData = code_start;
|
|
|
|
sec->Characteristics = (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ);
|
|
|
|
sec++;
|
|
|
|
|
|
|
|
/* build the data section */
|
|
|
|
|
|
|
|
memcpy( sec->Name, ".data", sizeof(".data") );
|
|
|
|
sec->SizeOfRawData = data_end - data_start;
|
|
|
|
sec->Misc.VirtualSize = sec->SizeOfRawData;
|
|
|
|
sec->VirtualAddress = data_start;
|
|
|
|
sec->PointerToRawData = data_start;
|
|
|
|
sec->Characteristics = (IMAGE_SCN_CNT_INITIALIZED_DATA |
|
|
|
|
IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_READ);
|
|
|
|
sec++;
|
|
|
|
|
|
|
|
for (i = 0; i < nt->OptionalHeader.NumberOfRvaAndSizes; i++)
|
|
|
|
fixup_rva_dwords( &nt->OptionalHeader.DataDirectory[i].VirtualAddress, delta, 1 );
|
|
|
|
|
|
|
|
/* build the import directory */
|
|
|
|
|
|
|
|
dir = &nt->OptionalHeader.DataDirectory[IMAGE_FILE_IMPORT_DIRECTORY];
|
|
|
|
if (dir->Size)
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2020-04-16 10:26:13 +02:00
|
|
|
IMAGE_IMPORT_DESCRIPTOR *imports = (IMAGE_IMPORT_DESCRIPTOR *)(addr + dir->VirtualAddress);
|
2010-08-23 17:12:53 +02:00
|
|
|
|
2020-04-16 10:26:13 +02:00
|
|
|
while (imports->Name)
|
|
|
|
{
|
|
|
|
fixup_rva_dwords( &imports->u.OriginalFirstThunk, delta, 1 );
|
|
|
|
fixup_rva_dwords( &imports->Name, delta, 1 );
|
|
|
|
fixup_rva_dwords( &imports->FirstThunk, delta, 1 );
|
|
|
|
if (imports->u.OriginalFirstThunk)
|
|
|
|
fixup_rva_names( (UINT_PTR *)(addr + imports->u.OriginalFirstThunk), delta );
|
|
|
|
if (imports->FirstThunk)
|
|
|
|
fixup_rva_names( (UINT_PTR *)(addr + imports->FirstThunk), delta );
|
|
|
|
imports++;
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 17:40:54 +01:00
|
|
|
|
2020-04-16 10:26:13 +02:00
|
|
|
/* build the resource directory */
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2020-04-16 10:26:13 +02:00
|
|
|
dir = &nt->OptionalHeader.DataDirectory[IMAGE_FILE_RESOURCE_DIRECTORY];
|
|
|
|
if (dir->Size)
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2020-04-16 10:26:13 +02:00
|
|
|
void *ptr = addr + dir->VirtualAddress;
|
|
|
|
fixup_so_resources( ptr, ptr, delta );
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 10:26:13 +02:00
|
|
|
/* build the export directory */
|
|
|
|
|
|
|
|
dir = &nt->OptionalHeader.DataDirectory[IMAGE_FILE_EXPORT_DIRECTORY];
|
|
|
|
if (dir->Size)
|
2006-02-21 19:48:18 +01:00
|
|
|
{
|
2020-04-16 10:26:13 +02:00
|
|
|
IMAGE_EXPORT_DIRECTORY *exports = (IMAGE_EXPORT_DIRECTORY *)(addr + dir->VirtualAddress);
|
|
|
|
|
|
|
|
fixup_rva_dwords( &exports->Name, delta, 1 );
|
|
|
|
fixup_rva_dwords( &exports->AddressOfFunctions, delta, 1 );
|
|
|
|
fixup_rva_dwords( &exports->AddressOfNames, delta, 1 );
|
|
|
|
fixup_rva_dwords( &exports->AddressOfNameOrdinals, delta, 1 );
|
|
|
|
fixup_rva_dwords( (DWORD *)(addr + exports->AddressOfNames), delta, exports->NumberOfNames );
|
|
|
|
fixup_rva_ptrs( addr + exports->AddressOfFunctions, addr, exports->NumberOfFunctions );
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* build_so_dll_module
|
|
|
|
*
|
|
|
|
* Build the module for a .so builtin library.
|
|
|
|
*/
|
|
|
|
static NTSTATUS build_so_dll_module( const WCHAR *load_path, const UNICODE_STRING *nt_name,
|
|
|
|
HMODULE module, DWORD flags, WINE_MODREF **pwm )
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS *nt;
|
|
|
|
WINE_MODREF *wm;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!(nt = RtlImageNtHeader( module ))) return STATUS_INVALID_IMAGE_FORMAT;
|
|
|
|
|
|
|
|
if (!(wm = alloc_module( module, nt_name, TRUE ))) return STATUS_NO_MEMORY;
|
2006-02-21 19:48:18 +01:00
|
|
|
|
2020-04-16 10:26:13 +02:00
|
|
|
virtual_create_builtin_view( module );
|
|
|
|
|
|
|
|
if (!(flags & DONT_RESOLVE_DLL_REFERENCES) &&
|
|
|
|
((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) ||
|
|
|
|
nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_NATIVE ||
|
|
|
|
is_16bit_builtin( module )))
|
|
|
|
{
|
|
|
|
if ((status = fixup_imports( wm, load_path )))
|
2006-02-21 19:48:18 +01:00
|
|
|
{
|
2020-04-16 10:26:13 +02:00
|
|
|
/* the module has only been inserted in the load & memory order lists */
|
2006-02-21 19:48:18 +01:00
|
|
|
RemoveEntryList(&wm->ldr.InLoadOrderModuleList);
|
|
|
|
RemoveEntryList(&wm->ldr.InMemoryOrderModuleList);
|
|
|
|
/* FIXME: free the modref */
|
2020-04-16 10:26:13 +02:00
|
|
|
return status;
|
2006-02-21 19:48:18 +01:00
|
|
|
}
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
2006-02-21 19:48:18 +01:00
|
|
|
|
2020-04-16 10:26:13 +02:00
|
|
|
TRACE( "loaded %s %p %p\n", debugstr_us(nt_name), wm, module );
|
2003-09-19 06:04:57 +02:00
|
|
|
|
|
|
|
/* send the DLL load event */
|
|
|
|
|
|
|
|
SERVER_START_REQ( load_dll )
|
|
|
|
{
|
2008-12-29 16:47:51 +01:00
|
|
|
req->base = wine_server_client_ptr( module );
|
2003-09-19 06:04:57 +02:00
|
|
|
req->dbg_offset = nt->FileHeader.PointerToSymbolTable;
|
|
|
|
req->dbg_size = nt->FileHeader.NumberOfSymbols;
|
2008-12-29 17:10:11 +01:00
|
|
|
req->name = wine_server_client_ptr( &wm->ldr.FullDllName.Buffer );
|
2003-09-30 03:04:19 +02:00
|
|
|
wine_server_add_data( req, wm->ldr.FullDllName.Buffer, wm->ldr.FullDllName.Length );
|
2003-09-19 06:04:57 +02:00
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
/* setup relay debugging entry points */
|
|
|
|
if (TRACE_ON(relay)) RELAY_SetupDLL( module );
|
2020-04-16 10:26:13 +02:00
|
|
|
|
|
|
|
*pwm = wm;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* load_builtin_callback
|
|
|
|
*
|
|
|
|
* Load a library in memory; callback function for wine_dll_register
|
|
|
|
*/
|
|
|
|
static void load_builtin_callback( void *module, const char *filename )
|
|
|
|
{
|
|
|
|
static const WCHAR emptyW[1];
|
|
|
|
const WCHAR *load_path;
|
|
|
|
|
|
|
|
if (!module)
|
|
|
|
{
|
|
|
|
ERR("could not map image for %s\n", debugstr_us(builtin_load_info->filename) );
|
|
|
|
builtin_load_info->status = STATUS_NO_MEMORY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
load_path = builtin_load_info->load_path;
|
|
|
|
if (!load_path) load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer;
|
|
|
|
if (!load_path) load_path = emptyW;
|
|
|
|
|
|
|
|
builtin_load_info->status = build_so_dll_module( load_path, builtin_load_info->filename, module,
|
|
|
|
0, &builtin_load_info->wm );
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-10 18:31:56 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_security_cookie
|
|
|
|
*
|
|
|
|
* Create a random security cookie for buffer overflow protection. Make
|
|
|
|
* sure it does not accidentally match the default cookie value.
|
|
|
|
*/
|
|
|
|
static void set_security_cookie( void *module, SIZE_T len )
|
|
|
|
{
|
|
|
|
static ULONG seed;
|
|
|
|
IMAGE_LOAD_CONFIG_DIRECTORY *loadcfg;
|
|
|
|
ULONG loadcfg_size;
|
|
|
|
ULONG_PTR *cookie;
|
|
|
|
|
|
|
|
loadcfg = RtlImageDirectoryEntryToData( module, TRUE, IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &loadcfg_size );
|
|
|
|
if (!loadcfg) return;
|
|
|
|
if (loadcfg_size < offsetof(IMAGE_LOAD_CONFIG_DIRECTORY, SecurityCookie) + sizeof(loadcfg->SecurityCookie)) return;
|
|
|
|
if (!loadcfg->SecurityCookie) return;
|
|
|
|
if (loadcfg->SecurityCookie < (ULONG_PTR)module ||
|
|
|
|
loadcfg->SecurityCookie > (ULONG_PTR)module + len - sizeof(ULONG_PTR))
|
|
|
|
{
|
|
|
|
WARN( "security cookie %p outside of image %p-%p\n",
|
|
|
|
(void *)loadcfg->SecurityCookie, module, (char *)module + len );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cookie = (ULONG_PTR *)loadcfg->SecurityCookie;
|
|
|
|
TRACE( "initializing security cookie %p\n", cookie );
|
|
|
|
|
|
|
|
if (!seed) seed = NtGetTickCount() ^ GetCurrentProcessId();
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (*cookie == DEFAULT_SECURITY_COOKIE_16)
|
|
|
|
*cookie = RtlRandom( &seed ) >> 16; /* leave the high word clear */
|
|
|
|
else if (*cookie == DEFAULT_SECURITY_COOKIE_32)
|
|
|
|
*cookie = RtlRandom( &seed );
|
|
|
|
#ifdef DEFAULT_SECURITY_COOKIE_64
|
|
|
|
else if (*cookie == DEFAULT_SECURITY_COOKIE_64)
|
|
|
|
{
|
|
|
|
*cookie = RtlRandom( &seed );
|
|
|
|
/* fill up, but keep the highest word clear */
|
|
|
|
*cookie ^= (ULONG_PTR)RtlRandom( &seed ) << 16;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 10:59:47 +01:00
|
|
|
static NTSTATUS perform_relocations( void *module, IMAGE_NT_HEADERS *nt, SIZE_T len )
|
2015-08-18 09:25:40 +02:00
|
|
|
{
|
|
|
|
char *base;
|
|
|
|
IMAGE_BASE_RELOCATION *rel, *end;
|
|
|
|
const IMAGE_DATA_DIRECTORY *relocs;
|
|
|
|
const IMAGE_SECTION_HEADER *sec;
|
|
|
|
INT_PTR delta;
|
|
|
|
ULONG protect_old[96], i;
|
|
|
|
|
|
|
|
base = (char *)nt->OptionalHeader.ImageBase;
|
2019-02-09 10:59:47 +01:00
|
|
|
if (module == base) return STATUS_SUCCESS; /* nothing to do */
|
2015-08-18 09:25:40 +02:00
|
|
|
|
|
|
|
/* no relocations are performed on non page-aligned binaries */
|
|
|
|
if (nt->OptionalHeader.SectionAlignment < page_size)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if (!(nt->FileHeader.Characteristics & IMAGE_FILE_DLL) && NtCurrentTeb()->Peb->ImageBaseAddress)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
relocs = &nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
|
|
|
|
|
2015-08-20 07:08:07 +02:00
|
|
|
if (nt->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED)
|
2015-08-18 09:25:40 +02:00
|
|
|
{
|
|
|
|
WARN( "Need to relocate module from %p to %p, but there are no relocation records\n",
|
|
|
|
base, module );
|
|
|
|
return STATUS_CONFLICTING_ADDRESSES;
|
|
|
|
}
|
|
|
|
|
2015-08-20 07:08:07 +02:00
|
|
|
if (!relocs->Size) return STATUS_SUCCESS;
|
|
|
|
if (!relocs->VirtualAddress) return STATUS_CONFLICTING_ADDRESSES;
|
|
|
|
|
2018-08-02 21:54:37 +02:00
|
|
|
if (nt->FileHeader.NumberOfSections > ARRAY_SIZE( protect_old ))
|
2015-08-18 09:25:40 +02:00
|
|
|
return STATUS_INVALID_IMAGE_FORMAT;
|
|
|
|
|
|
|
|
sec = (const IMAGE_SECTION_HEADER *)((const char *)&nt->OptionalHeader +
|
|
|
|
nt->FileHeader.SizeOfOptionalHeader);
|
|
|
|
for (i = 0; i < nt->FileHeader.NumberOfSections; i++)
|
|
|
|
{
|
|
|
|
void *addr = get_rva( module, sec[i].VirtualAddress );
|
|
|
|
SIZE_T size = sec[i].SizeOfRawData;
|
|
|
|
NtProtectVirtualMemory( NtCurrentProcess(), &addr,
|
|
|
|
&size, PAGE_READWRITE, &protect_old[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE( "relocating from %p-%p to %p-%p\n",
|
|
|
|
base, base + len, module, (char *)module + len );
|
|
|
|
|
|
|
|
rel = get_rva( module, relocs->VirtualAddress );
|
|
|
|
end = get_rva( module, relocs->VirtualAddress + relocs->Size );
|
|
|
|
delta = (char *)module - base;
|
|
|
|
|
|
|
|
while (rel < end - 1 && rel->SizeOfBlock)
|
|
|
|
{
|
|
|
|
if (rel->VirtualAddress >= len)
|
|
|
|
{
|
|
|
|
WARN( "invalid address %p in relocation %p\n", get_rva( module, rel->VirtualAddress ), rel );
|
|
|
|
return STATUS_ACCESS_VIOLATION;
|
|
|
|
}
|
|
|
|
rel = LdrProcessRelocationBlock( get_rva( module, rel->VirtualAddress ),
|
|
|
|
(rel->SizeOfBlock - sizeof(*rel)) / sizeof(USHORT),
|
|
|
|
(USHORT *)(rel + 1), delta );
|
|
|
|
if (!rel) return STATUS_INVALID_IMAGE_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nt->FileHeader.NumberOfSections; i++)
|
|
|
|
{
|
|
|
|
void *addr = get_rva( module, sec[i].VirtualAddress );
|
|
|
|
SIZE_T size = sec[i].SizeOfRawData;
|
|
|
|
NtProtectVirtualMemory( NtCurrentProcess(), &addr,
|
|
|
|
&size, protect_old[i], &protect_old[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2015-08-10 18:31:56 +02:00
|
|
|
|
2018-10-25 13:48:46 +02:00
|
|
|
#ifdef _WIN64
|
|
|
|
/* convert PE header to 64-bit when loading a 32-bit IL-only module into a 64-bit process */
|
|
|
|
static BOOL convert_to_pe64( HMODULE module, const pe_image_info_t *info )
|
|
|
|
{
|
|
|
|
static const ULONG copy_dirs[] = { IMAGE_DIRECTORY_ENTRY_RESOURCE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_SECURITY,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_BASERELOC,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_DEBUG,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR };
|
|
|
|
IMAGE_OPTIONAL_HEADER32 hdr32 = { IMAGE_NT_OPTIONAL_HDR32_MAGIC };
|
|
|
|
IMAGE_OPTIONAL_HEADER64 hdr64 = { IMAGE_NT_OPTIONAL_HDR64_MAGIC };
|
|
|
|
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( module );
|
|
|
|
SIZE_T hdr_size = min( sizeof(hdr32), nt->FileHeader.SizeOfOptionalHeader );
|
|
|
|
IMAGE_SECTION_HEADER *sec = (IMAGE_SECTION_HEADER *)((char *)&nt->OptionalHeader + hdr_size);
|
2019-01-25 12:46:37 +01:00
|
|
|
SIZE_T size = info->header_size;
|
2018-10-25 13:48:46 +02:00
|
|
|
void *addr = module;
|
|
|
|
ULONG i, old_prot;
|
|
|
|
|
|
|
|
TRACE( "%p\n", module );
|
|
|
|
|
|
|
|
if (NtProtectVirtualMemory( NtCurrentProcess(), &addr, &size, PAGE_READWRITE, &old_prot ))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-01-25 12:46:37 +01:00
|
|
|
if ((char *)module + size < (char *)(nt + 1) + nt->FileHeader.NumberOfSections * sizeof(*sec))
|
|
|
|
{
|
|
|
|
NtProtectVirtualMemory( NtCurrentProcess(), &addr, &size, old_prot, &old_prot );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-10-25 13:48:46 +02:00
|
|
|
memcpy( &hdr32, &nt->OptionalHeader, hdr_size );
|
|
|
|
memcpy( &hdr64, &hdr32, offsetof( IMAGE_OPTIONAL_HEADER64, SizeOfStackReserve ));
|
|
|
|
hdr64.Magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
|
|
|
|
hdr64.AddressOfEntryPoint = 0;
|
|
|
|
hdr64.ImageBase = hdr32.ImageBase;
|
|
|
|
hdr64.SizeOfStackReserve = hdr32.SizeOfStackReserve;
|
|
|
|
hdr64.SizeOfStackCommit = hdr32.SizeOfStackCommit;
|
|
|
|
hdr64.SizeOfHeapReserve = hdr32.SizeOfHeapReserve;
|
|
|
|
hdr64.SizeOfHeapCommit = hdr32.SizeOfHeapCommit;
|
|
|
|
hdr64.LoaderFlags = hdr32.LoaderFlags;
|
|
|
|
hdr64.NumberOfRvaAndSizes = hdr32.NumberOfRvaAndSizes;
|
|
|
|
for (i = 0; i < ARRAY_SIZE( copy_dirs ); i++)
|
|
|
|
hdr64.DataDirectory[copy_dirs[i]] = hdr32.DataDirectory[copy_dirs[i]];
|
|
|
|
|
|
|
|
memmove( nt + 1, sec, nt->FileHeader.NumberOfSections * sizeof(*sec) );
|
|
|
|
nt->FileHeader.SizeOfOptionalHeader = sizeof(hdr64);
|
|
|
|
nt->OptionalHeader = hdr64;
|
|
|
|
NtProtectVirtualMemory( NtCurrentProcess(), &addr, &size, old_prot, &old_prot );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-30 14:16:34 +01:00
|
|
|
|
|
|
|
/* On WoW64 setups, an image mapping can also be created for the other 32/64 CPU */
|
|
|
|
/* but it cannot necessarily be loaded as a dll, so we need some additional checks */
|
2018-02-28 09:57:59 +01:00
|
|
|
static BOOL is_valid_binary( HMODULE module, const pe_image_info_t *info )
|
2018-01-30 14:16:34 +01:00
|
|
|
{
|
|
|
|
#ifdef __i386__
|
|
|
|
return info->machine == IMAGE_FILE_MACHINE_I386;
|
|
|
|
#elif defined(__arm__)
|
|
|
|
return info->machine == IMAGE_FILE_MACHINE_ARM ||
|
|
|
|
info->machine == IMAGE_FILE_MACHINE_THUMB ||
|
|
|
|
info->machine == IMAGE_FILE_MACHINE_ARMNT;
|
2018-10-25 13:48:46 +02:00
|
|
|
#elif defined(_WIN64) /* support 32-bit IL-only images on 64-bit */
|
2018-02-28 09:57:59 +01:00
|
|
|
#ifdef __x86_64__
|
|
|
|
if (info->machine == IMAGE_FILE_MACHINE_AMD64) return TRUE;
|
|
|
|
#else
|
|
|
|
if (info->machine == IMAGE_FILE_MACHINE_ARM64) return TRUE;
|
|
|
|
#endif
|
|
|
|
if (!info->contains_code) return TRUE;
|
2019-01-25 15:29:53 +01:00
|
|
|
if (!(info->image_flags & IMAGE_FLAGS_ComPlusNativeReady))
|
|
|
|
{
|
|
|
|
/* check COM header directly, ignoring runtime version */
|
|
|
|
DWORD size;
|
|
|
|
const IMAGE_COR20_HEADER *cor_header = RtlImageDirectoryEntryToData( module, TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, &size );
|
|
|
|
if (!cor_header || !(cor_header->Flags & COMIMAGE_FLAGS_ILONLY)) return FALSE;
|
|
|
|
}
|
2018-11-24 20:39:00 +01:00
|
|
|
return convert_to_pe64( module, info );
|
2018-01-30 14:16:34 +01:00
|
|
|
#else
|
|
|
|
return FALSE; /* no wow64 support on other platforms */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-03 14:14:36 +02:00
|
|
|
/******************************************************************
|
|
|
|
* get_module_path_end
|
|
|
|
*
|
|
|
|
* Returns the end of the directory component of the module path.
|
|
|
|
*/
|
|
|
|
static inline const WCHAR *get_module_path_end( const WCHAR *module )
|
|
|
|
{
|
|
|
|
const WCHAR *p;
|
|
|
|
const WCHAR *mod_end = module;
|
|
|
|
|
2020-03-31 11:47:47 +02:00
|
|
|
if ((p = wcsrchr( mod_end, '\\' ))) mod_end = p;
|
|
|
|
if ((p = wcsrchr( mod_end, '/' ))) mod_end = p;
|
2019-10-03 14:14:36 +02:00
|
|
|
if (mod_end == module + 2 && module[1] == ':') mod_end++;
|
|
|
|
if (mod_end == module && module[0] && module[1] == ':') mod_end += 2;
|
|
|
|
return mod_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* append_path
|
|
|
|
*
|
|
|
|
* Append a counted string to the load path. Helper for get_dll_load_path.
|
|
|
|
*/
|
|
|
|
static inline WCHAR *append_path( WCHAR *p, const WCHAR *str, int len )
|
|
|
|
{
|
2020-03-31 11:50:16 +02:00
|
|
|
if (len == -1) len = wcslen(str);
|
2019-10-03 14:14:36 +02:00
|
|
|
if (!len) return p;
|
|
|
|
memcpy( p, str, len * sizeof(WCHAR) );
|
|
|
|
p[len] = ';';
|
|
|
|
return p + len + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-01 09:33:52 +02:00
|
|
|
/******************************************************************
|
|
|
|
* get_dll_load_path
|
|
|
|
*/
|
2019-10-03 14:14:36 +02:00
|
|
|
static NTSTATUS get_dll_load_path( LPCWSTR module, LPCWSTR dll_dir, ULONG safe_mode, WCHAR **path )
|
2019-10-01 09:33:52 +02:00
|
|
|
{
|
|
|
|
static const WCHAR pathW[] = {'P','A','T','H',0};
|
|
|
|
|
|
|
|
const WCHAR *mod_end = module;
|
|
|
|
UNICODE_STRING name, value;
|
|
|
|
WCHAR *p, *ret;
|
2019-10-03 14:14:36 +02:00
|
|
|
int len = ARRAY_SIZE(system_path) + 1, path_len = 0;
|
2019-10-01 09:33:52 +02:00
|
|
|
|
|
|
|
if (module)
|
|
|
|
{
|
2019-10-03 14:14:36 +02:00
|
|
|
mod_end = get_module_path_end( module );
|
2019-10-01 09:33:52 +02:00
|
|
|
len += (mod_end - module) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &name, pathW );
|
|
|
|
value.Length = 0;
|
|
|
|
value.MaximumLength = 0;
|
|
|
|
value.Buffer = NULL;
|
|
|
|
if (RtlQueryEnvironmentVariable_U( NULL, &name, &value ) == STATUS_BUFFER_TOO_SMALL)
|
|
|
|
path_len = value.Length;
|
|
|
|
|
2020-03-31 11:50:16 +02:00
|
|
|
if (dll_dir) len += wcslen( dll_dir ) + 1;
|
2019-10-03 14:14:36 +02:00
|
|
|
else len += 2; /* current directory */
|
|
|
|
if (!(p = ret = RtlAllocateHeap( GetProcessHeap(), 0, path_len + len * sizeof(WCHAR) )))
|
2019-10-01 09:33:52 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
2019-10-03 14:14:36 +02:00
|
|
|
|
|
|
|
p = append_path( p, module, mod_end - module );
|
|
|
|
if (dll_dir) p = append_path( p, dll_dir, -1 );
|
|
|
|
else if (!safe_mode) p = append_path( p, dotW, -1 );
|
|
|
|
p = append_path( p, system_path, -1 );
|
|
|
|
if (!dll_dir && safe_mode) p = append_path( p, dotW, -1 );
|
|
|
|
|
|
|
|
value.Buffer = p;
|
2019-10-01 09:33:52 +02:00
|
|
|
value.MaximumLength = path_len;
|
|
|
|
|
|
|
|
while (RtlQueryEnvironmentVariable_U( NULL, &name, &value ) == STATUS_BUFFER_TOO_SMALL)
|
|
|
|
{
|
|
|
|
WCHAR *new_ptr;
|
|
|
|
|
|
|
|
/* grow the buffer and retry */
|
|
|
|
path_len = value.Length;
|
|
|
|
if (!(new_ptr = RtlReAllocateHeap( GetProcessHeap(), 0, ret, path_len + len * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, ret );
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
value.Buffer = new_ptr + (value.Buffer - ret);
|
|
|
|
value.MaximumLength = path_len;
|
|
|
|
ret = new_ptr;
|
|
|
|
}
|
|
|
|
value.Buffer[value.Length / sizeof(WCHAR)] = 0;
|
|
|
|
*path = ret;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-03 14:14:36 +02:00
|
|
|
/******************************************************************
|
|
|
|
* get_dll_load_path_search_flags
|
|
|
|
*/
|
|
|
|
static NTSTATUS get_dll_load_path_search_flags( LPCWSTR module, DWORD flags, WCHAR **path )
|
|
|
|
{
|
|
|
|
const WCHAR *image = NULL, *mod_end, *image_end;
|
|
|
|
struct dll_dir_entry *dir;
|
|
|
|
WCHAR *p, *ret;
|
|
|
|
int len = 1;
|
|
|
|
|
|
|
|
if (flags & LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)
|
|
|
|
flags |= (LOAD_LIBRARY_SEARCH_APPLICATION_DIR |
|
|
|
|
LOAD_LIBRARY_SEARCH_USER_DIRS |
|
|
|
|
LOAD_LIBRARY_SEARCH_SYSTEM32);
|
|
|
|
|
|
|
|
if (flags & LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
|
|
|
|
{
|
|
|
|
DWORD type = RtlDetermineDosPathNameType_U( module );
|
2020-03-25 14:15:36 +01:00
|
|
|
if (type != ABSOLUTE_DRIVE_PATH && type != ABSOLUTE_PATH && type != DEVICE_PATH)
|
2019-10-03 14:14:36 +02:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
mod_end = get_module_path_end( module );
|
|
|
|
len += (mod_end - module) + 1;
|
|
|
|
}
|
|
|
|
else module = NULL;
|
|
|
|
|
|
|
|
if (flags & LOAD_LIBRARY_SEARCH_APPLICATION_DIR)
|
|
|
|
{
|
|
|
|
image = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
|
|
|
|
image_end = get_module_path_end( image );
|
|
|
|
len += (image_end - image) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & LOAD_LIBRARY_SEARCH_USER_DIRS)
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY( dir, &dll_dir_list, struct dll_dir_entry, entry )
|
2020-03-31 11:50:16 +02:00
|
|
|
len += wcslen( dir->dir + 4 /* \??\ */ ) + 1;
|
2019-10-03 14:14:36 +02:00
|
|
|
if (dll_directory.Length) len += dll_directory.Length / sizeof(WCHAR) + 1;
|
|
|
|
}
|
|
|
|
|
2020-03-31 11:50:16 +02:00
|
|
|
if (flags & LOAD_LIBRARY_SEARCH_SYSTEM32) len += wcslen( system_dir );
|
2019-10-03 14:14:36 +02:00
|
|
|
|
|
|
|
if ((p = ret = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
if (module) p = append_path( p, module, mod_end - module );
|
|
|
|
if (image) p = append_path( p, image, image_end - image );
|
|
|
|
if (flags & LOAD_LIBRARY_SEARCH_USER_DIRS)
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY( dir, &dll_dir_list, struct dll_dir_entry, entry )
|
|
|
|
p = append_path( p, dir->dir + 4 /* \??\ */, -1 );
|
|
|
|
p = append_path( p, dll_directory.Buffer, dll_directory.Length / sizeof(WCHAR) );
|
|
|
|
}
|
2020-03-31 11:37:58 +02:00
|
|
|
if (flags & LOAD_LIBRARY_SEARCH_SYSTEM32) wcscpy( p, system_dir );
|
2019-10-03 14:14:36 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (p > ret) p--;
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*path = ret;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-22 11:34:55 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* open_dll_file
|
|
|
|
*
|
|
|
|
* Open a file for a new dll. Helper for find_dll_file.
|
|
|
|
*/
|
2019-04-22 11:36:39 +02:00
|
|
|
static NTSTATUS open_dll_file( UNICODE_STRING *nt_name, WINE_MODREF **pwm,
|
2019-04-22 11:34:55 +02:00
|
|
|
void **module, pe_image_info_t *image_info, struct stat *st )
|
|
|
|
{
|
|
|
|
FILE_BASIC_INFORMATION info;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
LARGE_INTEGER size;
|
|
|
|
SIZE_T len = 0;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE handle, mapping;
|
|
|
|
int fd, needs_close;
|
|
|
|
|
2019-06-05 19:08:23 +02:00
|
|
|
if ((*pwm = find_fullname_module( nt_name )))
|
|
|
|
{
|
|
|
|
NtUnmapViewOfSection( NtCurrentProcess(), *module );
|
|
|
|
*module = NULL;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2019-04-22 11:34:55 +02:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = nt_name;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if ((status = NtOpenFile( &handle, GENERIC_READ | SYNCHRONIZE, &attr, &io,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_DELETE,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE )))
|
|
|
|
{
|
|
|
|
if (status != STATUS_OBJECT_PATH_NOT_FOUND &&
|
|
|
|
status != STATUS_OBJECT_NAME_NOT_FOUND &&
|
|
|
|
!NtQueryAttributesFile( &attr, &info ))
|
|
|
|
{
|
|
|
|
/* if the file exists but failed to open, report the error */
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/* otherwise continue searching */
|
|
|
|
return STATUS_DLL_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL ))
|
|
|
|
{
|
|
|
|
fstat( fd, st );
|
|
|
|
if (needs_close) close( fd );
|
|
|
|
if ((*pwm = find_fileid_module( st )))
|
|
|
|
{
|
|
|
|
TRACE( "%s is the same file as existing module %p %s\n", debugstr_w( nt_name->Buffer ),
|
|
|
|
(*pwm)->ldr.BaseAddress, debugstr_w( (*pwm)->ldr.FullDllName.Buffer ));
|
|
|
|
NtClose( handle );
|
2019-06-05 19:08:23 +02:00
|
|
|
NtUnmapViewOfSection( NtCurrentProcess(), *module );
|
|
|
|
*module = NULL;
|
2019-04-22 11:34:55 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size.QuadPart = 0;
|
|
|
|
status = NtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_QUERY |
|
|
|
|
SECTION_MAP_READ | SECTION_MAP_EXECUTE,
|
|
|
|
NULL, &size, PAGE_EXECUTE_READ, SEC_IMAGE, handle );
|
|
|
|
NtClose( handle );
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
2019-06-05 19:08:23 +02:00
|
|
|
if (*module)
|
|
|
|
{
|
|
|
|
NtUnmapViewOfSection( NtCurrentProcess(), *module );
|
|
|
|
*module = NULL;
|
|
|
|
}
|
2019-04-22 11:34:55 +02:00
|
|
|
status = virtual_map_section( mapping, module, 0, 0, NULL, &len,
|
2019-08-01 10:07:38 +02:00
|
|
|
0, PAGE_EXECUTE_READ, image_info );
|
2019-04-22 11:34:55 +02:00
|
|
|
if (status == STATUS_IMAGE_NOT_AT_BASE) status = STATUS_SUCCESS;
|
|
|
|
NtClose( mapping );
|
|
|
|
}
|
|
|
|
if (!status && !is_valid_binary( *module, image_info ))
|
|
|
|
{
|
|
|
|
TRACE( "%s is for arch %x, continuing search\n", debugstr_us(nt_name), image_info->machine );
|
|
|
|
NtUnmapViewOfSection( NtCurrentProcess(), *module );
|
2019-06-05 19:08:23 +02:00
|
|
|
*module = NULL;
|
2019-04-22 11:34:55 +02:00
|
|
|
status = STATUS_IMAGE_MACHINE_TYPE_MISMATCH;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-19 06:04:57 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* load_native_dll (internal)
|
|
|
|
*/
|
2019-06-05 19:08:23 +02:00
|
|
|
static NTSTATUS load_native_dll( LPCWSTR load_path, const UNICODE_STRING *nt_name, void **module,
|
2019-02-09 10:59:47 +01:00
|
|
|
const pe_image_info_t *image_info, DWORD flags, WINE_MODREF** pwm,
|
|
|
|
struct stat *st )
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2019-06-05 19:08:23 +02:00
|
|
|
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( *module );
|
2003-09-19 06:04:57 +02:00
|
|
|
WINE_MODREF *wm;
|
|
|
|
NTSTATUS status;
|
2019-04-22 11:36:54 +02:00
|
|
|
const char *dll_type = (image_info->image_flags & IMAGE_FLAGS_WineBuiltin) ? "PE builtin" : "native";
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2019-04-22 11:36:54 +02:00
|
|
|
TRACE("Trying %s dll %s\n", dll_type, debugstr_us(nt_name) );
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2015-08-18 09:25:40 +02:00
|
|
|
/* perform base relocation, if necessary */
|
|
|
|
|
2019-06-05 19:08:23 +02:00
|
|
|
if ((status = perform_relocations( *module, nt, image_info->map_size ))) return status;
|
2003-09-19 06:04:57 +02:00
|
|
|
|
|
|
|
/* create the MODREF */
|
|
|
|
|
2019-06-11 15:32:39 +02:00
|
|
|
if (!(wm = alloc_module( *module, nt_name, (image_info->image_flags & IMAGE_FLAGS_WineBuiltin) )))
|
|
|
|
return STATUS_NO_MEMORY;
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2018-02-28 10:11:55 +01:00
|
|
|
wm->dev = st->st_dev;
|
|
|
|
wm->ino = st->st_ino;
|
2019-02-09 10:59:47 +01:00
|
|
|
if (image_info->loader_flags) wm->ldr.Flags |= LDR_COR_IMAGE;
|
|
|
|
if (image_info->image_flags & IMAGE_FLAGS_ComPlusILOnly) wm->ldr.Flags |= LDR_COR_ILONLY;
|
2018-02-21 09:55:05 +01:00
|
|
|
|
2019-06-05 19:08:23 +02:00
|
|
|
set_security_cookie( *module, image_info->map_size );
|
2015-08-10 18:31:56 +02:00
|
|
|
|
2003-09-19 06:04:57 +02:00
|
|
|
/* fixup imports */
|
|
|
|
|
2014-02-17 16:25:43 +01:00
|
|
|
if (!(flags & DONT_RESOLVE_DLL_REFERENCES) &&
|
|
|
|
((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) ||
|
|
|
|
nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_NATIVE))
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2018-04-02 18:11:51 +02:00
|
|
|
if (wm->ldr.Flags & LDR_COR_ILONLY)
|
|
|
|
status = fixup_imports_ilonly( wm, load_path, &wm->ldr.EntryPoint );
|
|
|
|
else
|
|
|
|
status = fixup_imports( wm, load_path );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
|
|
|
/* the module has only be inserted in the load & memory order lists */
|
|
|
|
RemoveEntryList(&wm->ldr.InLoadOrderModuleList);
|
|
|
|
RemoveEntryList(&wm->ldr.InMemoryOrderModuleList);
|
|
|
|
|
|
|
|
/* FIXME: there are several more dangling references
|
|
|
|
* left. Including dlls loaded by this dll before the
|
|
|
|
* failed one. Unrolling is rather difficult with the
|
|
|
|
* current structure and we can leave them lying
|
|
|
|
* around with no problems, so we don't care.
|
|
|
|
* As these might reference our wm, we don't free it.
|
|
|
|
*/
|
2019-06-05 19:08:23 +02:00
|
|
|
*module = NULL;
|
2018-01-30 14:16:34 +01:00
|
|
|
return status;
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send DLL load event */
|
|
|
|
|
|
|
|
SERVER_START_REQ( load_dll )
|
|
|
|
{
|
2019-06-05 19:08:23 +02:00
|
|
|
req->base = wine_server_client_ptr( *module );
|
2003-09-19 06:04:57 +02:00
|
|
|
req->dbg_offset = nt->FileHeader.PointerToSymbolTable;
|
|
|
|
req->dbg_size = nt->FileHeader.NumberOfSymbols;
|
2008-12-29 17:10:11 +01:00
|
|
|
req->name = wine_server_client_ptr( &wm->ldr.FullDllName.Buffer );
|
2003-09-30 03:04:19 +02:00
|
|
|
wine_server_add_data( req, wm->ldr.FullDllName.Buffer, wm->ldr.FullDllName.Length );
|
2003-09-19 06:04:57 +02:00
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2019-05-16 21:33:47 +02:00
|
|
|
if (image_info->image_flags & IMAGE_FLAGS_WineBuiltin)
|
|
|
|
{
|
2019-06-05 19:08:23 +02:00
|
|
|
if (TRACE_ON(relay)) RELAY_SetupDLL( *module );
|
2019-05-16 21:33:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-05 19:08:23 +02:00
|
|
|
if ((wm->ldr.Flags & LDR_IMAGE_IS_DLL) && TRACE_ON(snoop)) SNOOP_SetupDLL( *module );
|
2019-05-16 21:33:47 +02:00
|
|
|
}
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2019-06-05 19:08:23 +02:00
|
|
|
TRACE_(loaddll)( "Loaded %s at %p: %s\n", debugstr_w(wm->ldr.FullDllName.Buffer), *module, dll_type );
|
2005-05-23 12:33:34 +02:00
|
|
|
|
2006-02-28 12:41:25 +01:00
|
|
|
wm->ldr.LoadCount = 1;
|
2003-09-19 06:04:57 +02:00
|
|
|
*pwm = wm;
|
2019-06-05 19:08:23 +02:00
|
|
|
*module = NULL;
|
2018-01-30 14:16:34 +01:00
|
|
|
return STATUS_SUCCESS;
|
2003-09-29 22:42:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-22 11:36:54 +02:00
|
|
|
/* check if the library is the correct architecture */
|
|
|
|
/* only returns false for a valid library of the wrong arch */
|
|
|
|
static int check_library_arch( int fd )
|
|
|
|
{
|
|
|
|
#ifdef __APPLE__
|
|
|
|
struct /* Mach-O header */
|
|
|
|
{
|
|
|
|
unsigned int magic;
|
|
|
|
unsigned int cputype;
|
|
|
|
} header;
|
|
|
|
|
|
|
|
if (read( fd, &header, sizeof(header) ) != sizeof(header)) return 1;
|
|
|
|
if (header.magic != 0xfeedface) return 1;
|
|
|
|
if (sizeof(void *) == sizeof(int)) return !(header.cputype >> 24);
|
|
|
|
else return (header.cputype >> 24) == 1; /* CPU_ARCH_ABI64 */
|
|
|
|
#else
|
|
|
|
struct /* ELF header */
|
|
|
|
{
|
|
|
|
unsigned char magic[4];
|
|
|
|
unsigned char class;
|
|
|
|
unsigned char data;
|
|
|
|
unsigned char version;
|
|
|
|
} header;
|
|
|
|
|
|
|
|
if (read( fd, &header, sizeof(header) ) != sizeof(header)) return 1;
|
|
|
|
if (memcmp( header.magic, "\177ELF", 4 )) return 1;
|
|
|
|
if (header.version != 1 /* EV_CURRENT */) return 1;
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
if (header.data != 2 /* ELFDATA2MSB */) return 1;
|
|
|
|
#else
|
|
|
|
if (header.data != 1 /* ELFDATA2LSB */) return 1;
|
|
|
|
#endif
|
|
|
|
if (sizeof(void *) == sizeof(int)) return header.class == 1; /* ELFCLASS32 */
|
|
|
|
else return header.class == 2; /* ELFCLASS64 */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *prepend( char *buffer, const char *str, size_t len )
|
|
|
|
{
|
|
|
|
return memcpy( buffer - len, str, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* open_builtin_file
|
|
|
|
*/
|
|
|
|
static NTSTATUS open_builtin_file( char *name, WINE_MODREF **pwm, void **module,
|
|
|
|
pe_image_info_t *image_info, struct stat *st, char **so_name )
|
|
|
|
{
|
|
|
|
ANSI_STRING strA;
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
NTSTATUS status;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
nt_name.Buffer = NULL;
|
|
|
|
RtlInitString( &strA, name );
|
|
|
|
if ((status = wine_unix_to_nt_file_name( &strA, &nt_name ))) return status;
|
|
|
|
|
|
|
|
status = open_dll_file( &nt_name, pwm, module, image_info, st );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
|
|
|
|
/* ignore non-builtins */
|
|
|
|
if (!status && !*pwm && !(image_info->image_flags & IMAGE_FLAGS_WineBuiltin))
|
|
|
|
{
|
|
|
|
WARN( "%s found in WINEDLLPATH but not a builtin, ignoring\n", debugstr_a(name) );
|
|
|
|
NtUnmapViewOfSection( NtCurrentProcess(), *module );
|
2019-06-19 11:47:34 +02:00
|
|
|
*module = NULL;
|
2019-04-22 11:36:54 +02:00
|
|
|
status = STATUS_DLL_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != STATUS_DLL_NOT_FOUND) return status;
|
|
|
|
|
|
|
|
/* try .so file */
|
|
|
|
|
|
|
|
strcat( name, ".so" );
|
|
|
|
if ((fd = open( name, O_RDONLY )) != -1)
|
|
|
|
{
|
|
|
|
if (check_library_arch( fd ))
|
|
|
|
{
|
|
|
|
if ((*so_name = RtlAllocateHeap( GetProcessHeap(), 0, strlen(name) + 1 )))
|
|
|
|
strcpy( *so_name, name );
|
2019-06-19 11:47:34 +02:00
|
|
|
NtUnmapViewOfSection( NtCurrentProcess(), *module );
|
|
|
|
*module = NULL;
|
2019-04-22 11:36:54 +02:00
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else status = STATUS_IMAGE_MACHINE_TYPE_MISMATCH;
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* find_builtin_dll
|
|
|
|
*/
|
|
|
|
static NTSTATUS find_builtin_dll( const WCHAR *name, WINE_MODREF **pwm,
|
|
|
|
void **module, pe_image_info_t *image_info, struct stat *st,
|
|
|
|
char **so_name )
|
|
|
|
{
|
|
|
|
const char *path, *build_dir = wine_get_build_dir();
|
|
|
|
unsigned int i, pos, len, namelen, maxlen = 0;
|
|
|
|
char *ptr, *file;
|
|
|
|
NTSTATUS status = STATUS_DLL_NOT_FOUND;
|
|
|
|
BOOL found_image = FALSE;
|
|
|
|
|
2020-03-31 11:50:16 +02:00
|
|
|
len = wcslen( name );
|
2019-04-22 11:36:54 +02:00
|
|
|
if (build_dir) maxlen = strlen(build_dir) + sizeof("/programs/") + len;
|
2019-06-03 10:28:29 +02:00
|
|
|
for (i = 0; (path = wine_dll_enum_load_path( i )); i++) maxlen = max( maxlen, strlen(path)+1 );
|
2019-04-22 11:36:54 +02:00
|
|
|
maxlen += len + sizeof(".so");
|
|
|
|
|
|
|
|
if (!(file = RtlAllocateHeap( GetProcessHeap(), 0, maxlen ))) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
pos = maxlen - len - sizeof(".so");
|
|
|
|
/* we don't want to depend on the current codepage here */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (name[i] > 127) goto done;
|
|
|
|
file[pos + i] = (char)name[i];
|
|
|
|
if (file[pos + i] >= 'A' && file[pos + i] <= 'Z') file[pos + i] += 'a' - 'A';
|
|
|
|
}
|
|
|
|
file[--pos] = '/';
|
|
|
|
|
|
|
|
if (build_dir)
|
|
|
|
{
|
|
|
|
/* try as a dll */
|
|
|
|
ptr = file + pos;
|
|
|
|
namelen = len + 1;
|
|
|
|
file[pos + len + 1] = 0;
|
|
|
|
if (namelen > 4 && !memcmp( ptr + namelen - 4, ".dll", 4 )) namelen -= 4;
|
|
|
|
ptr = prepend( ptr, ptr, namelen );
|
|
|
|
ptr = prepend( ptr, "/dlls", sizeof("/dlls") - 1 );
|
|
|
|
ptr = prepend( ptr, build_dir, strlen(build_dir) );
|
|
|
|
status = open_builtin_file( ptr, pwm, module, image_info, st, so_name );
|
|
|
|
if (status != STATUS_DLL_NOT_FOUND) goto done;
|
|
|
|
|
|
|
|
/* now as a program */
|
|
|
|
ptr = file + pos;
|
|
|
|
namelen = len + 1;
|
|
|
|
file[pos + len + 1] = 0;
|
|
|
|
if (namelen > 4 && !memcmp( ptr + namelen - 4, ".exe", 4 )) namelen -= 4;
|
|
|
|
ptr = prepend( ptr, ptr, namelen );
|
|
|
|
ptr = prepend( ptr, "/programs", sizeof("/programs") - 1 );
|
|
|
|
ptr = prepend( ptr, build_dir, strlen(build_dir) );
|
|
|
|
status = open_builtin_file( ptr, pwm, module, image_info, st, so_name );
|
|
|
|
if (status != STATUS_DLL_NOT_FOUND) goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; (path = wine_dll_enum_load_path( i )); i++)
|
|
|
|
{
|
|
|
|
file[pos + len + 1] = 0;
|
|
|
|
ptr = prepend( file + pos, path, strlen(path) );
|
|
|
|
status = open_builtin_file( ptr, pwm, module, image_info, st, so_name );
|
|
|
|
if (status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH) found_image = TRUE;
|
|
|
|
else if (status != STATUS_DLL_NOT_FOUND) goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_image) status = STATUS_IMAGE_MACHINE_TYPE_MISMATCH;
|
|
|
|
WARN( "cannot find builtin library for %s\n", debugstr_w(name) );
|
|
|
|
|
|
|
|
done:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, file );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-19 06:04:57 +02:00
|
|
|
/***********************************************************************
|
2019-06-05 17:54:09 +02:00
|
|
|
* load_so_dll
|
2003-09-19 06:04:57 +02:00
|
|
|
*/
|
2019-06-05 17:54:09 +02:00
|
|
|
static NTSTATUS load_so_dll( LPCWSTR load_path, const UNICODE_STRING *nt_name,
|
2020-04-16 10:26:13 +02:00
|
|
|
const char *so_name, DWORD flags, WINE_MODREF** pwm )
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2020-04-14 21:58:56 +02:00
|
|
|
static const WCHAR soW[] = {'.','s','o',0};
|
|
|
|
DWORD len;
|
2015-12-30 06:37:58 +01:00
|
|
|
void *handle;
|
2020-04-15 19:37:44 +02:00
|
|
|
const IMAGE_NT_HEADERS *nt;
|
2003-10-08 00:56:34 +02:00
|
|
|
struct builtin_load_info info, *prev_info;
|
2019-06-05 17:54:09 +02:00
|
|
|
ANSI_STRING unix_name;
|
2020-04-14 21:58:56 +02:00
|
|
|
UNICODE_STRING win_name = *nt_name;
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2020-04-14 21:58:56 +02:00
|
|
|
unix_name.Buffer = NULL;
|
|
|
|
info.load_path = load_path;
|
|
|
|
info.filename = &win_name;
|
|
|
|
info.status = STATUS_SUCCESS;
|
|
|
|
info.wm = NULL;
|
|
|
|
|
|
|
|
if (!so_name)
|
2006-02-07 21:16:25 +01:00
|
|
|
{
|
2019-06-05 17:54:09 +02:00
|
|
|
if (wine_nt_to_unix_file_name( nt_name, &unix_name, FILE_OPEN, FALSE ))
|
|
|
|
return STATUS_DLL_NOT_FOUND;
|
2020-04-14 21:58:56 +02:00
|
|
|
|
|
|
|
/* remove .so extension from Windows name */
|
|
|
|
len = nt_name->Length / sizeof(WCHAR);
|
|
|
|
if (len > 3 && !wcsicmp( nt_name->Buffer + len - 3, soW )) win_name.Length -= 3 * sizeof(WCHAR);
|
2019-06-05 17:54:09 +02:00
|
|
|
}
|
2006-02-21 11:56:16 +01:00
|
|
|
|
2020-04-14 21:58:56 +02:00
|
|
|
TRACE( "loading %s from so lib %s\n", debugstr_us(&win_name),
|
|
|
|
debugstr_a( so_name ? so_name : unix_name.Buffer ));
|
2019-04-22 11:36:54 +02:00
|
|
|
|
2019-06-05 17:54:09 +02:00
|
|
|
prev_info = builtin_load_info;
|
|
|
|
builtin_load_info = &info;
|
2020-04-06 22:38:00 +02:00
|
|
|
handle = dlopen( so_name ? so_name : unix_name.Buffer, RTLD_NOW );
|
2020-04-16 10:26:13 +02:00
|
|
|
builtin_load_info = prev_info;
|
2019-06-05 17:54:09 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, unix_name.Buffer );
|
2006-02-07 21:16:25 +01:00
|
|
|
|
2019-06-05 17:54:09 +02:00
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
if (so_name)
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2020-04-06 22:38:00 +02:00
|
|
|
ERR("failed to load .so lib %s: %s\n", debugstr_a(so_name), dlerror() );
|
2020-04-15 19:37:44 +02:00
|
|
|
info.status = STATUS_PROCEDURE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN( "failed to load .so lib %s: %s\n", debugstr_us(nt_name), dlerror() );
|
|
|
|
info.status = STATUS_INVALID_IMAGE_FORMAT;
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
|
|
|
}
|
2006-02-09 12:15:57 +01:00
|
|
|
|
2019-06-05 17:54:09 +02:00
|
|
|
if (info.status != STATUS_SUCCESS) goto failed;
|
2003-09-19 06:04:57 +02:00
|
|
|
|
2020-04-15 19:37:44 +02:00
|
|
|
if (!info.wm && (nt = dlsym( handle, "__wine_spec_nt_header" )))
|
|
|
|
{
|
|
|
|
HMODULE module = (HMODULE)((nt->OptionalHeader.ImageBase + 0xffff) & ~0xffff);
|
|
|
|
if ((info.wm = get_modref( module ))) /* already loaded */
|
|
|
|
{
|
|
|
|
TRACE( "Found %s at %p for builtin %s\n",
|
|
|
|
debugstr_w(info.wm->ldr.FullDllName.Buffer), info.wm->ldr.BaseAddress,
|
|
|
|
debugstr_us(nt_name) );
|
|
|
|
if (info.wm->ldr.LoadCount != -1) info.wm->ldr.LoadCount++;
|
|
|
|
dlclose( handle );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-16 10:26:13 +02:00
|
|
|
if ((info.status = map_so_dll( nt, module ))) goto failed;
|
|
|
|
if ((info.status = build_so_dll_module( load_path, &win_name, module, flags, &info.wm )))
|
|
|
|
goto failed;
|
2020-04-15 19:37:44 +02:00
|
|
|
TRACE_(loaddll)( "Loaded %s at %p: builtin\n",
|
|
|
|
debugstr_w(info.wm->ldr.FullDllName.Buffer), info.wm->ldr.BaseAddress );
|
|
|
|
info.wm->ldr.LoadCount = 1;
|
2020-04-16 12:00:43 +02:00
|
|
|
info.wm->so_handle = handle;
|
2020-04-15 19:37:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!info.wm)
|
2003-10-08 00:56:34 +02:00
|
|
|
{
|
2006-02-21 19:43:22 +01:00
|
|
|
/* The constructor wasn't called, this means the .so is already
|
|
|
|
* loaded under a different name. Try to find the wm for it. */
|
2005-05-23 12:33:34 +02:00
|
|
|
|
2019-06-05 17:54:09 +02:00
|
|
|
if (!(info.wm = find_so_module( handle )))
|
2006-02-07 21:16:25 +01:00
|
|
|
{
|
2019-06-05 17:54:09 +02:00
|
|
|
info.status = STATUS_INVALID_IMAGE_FORMAT;
|
|
|
|
goto failed;
|
2006-02-07 21:16:25 +01:00
|
|
|
}
|
2019-06-05 17:54:09 +02:00
|
|
|
TRACE( "Found %s at %p for builtin %s\n",
|
|
|
|
debugstr_w(info.wm->ldr.FullDllName.Buffer), info.wm->ldr.BaseAddress,
|
|
|
|
debugstr_us(nt_name) );
|
|
|
|
if (info.wm->ldr.LoadCount != -1) info.wm->ldr.LoadCount++;
|
2020-04-06 22:38:00 +02:00
|
|
|
dlclose( handle ); /* release the libdl refcount */
|
2006-02-21 19:43:22 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-25 23:36:39 +02:00
|
|
|
TRACE_(loaddll)( "Loaded %s at %p: builtin\n", debugstr_w(info.wm->ldr.FullDllName.Buffer), info.wm->ldr.BaseAddress );
|
2006-02-28 12:41:25 +01:00
|
|
|
info.wm->ldr.LoadCount = 1;
|
2020-04-16 12:00:43 +02:00
|
|
|
info.wm->so_handle = handle;
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
2006-02-21 19:43:22 +01:00
|
|
|
|
2003-10-08 00:56:34 +02:00
|
|
|
*pwm = info.wm;
|
2003-09-19 06:04:57 +02:00
|
|
|
return STATUS_SUCCESS;
|
2019-06-05 17:54:09 +02:00
|
|
|
|
|
|
|
failed:
|
2020-04-15 19:37:44 +02:00
|
|
|
if (handle) dlclose( handle );
|
2019-06-05 17:54:09 +02:00
|
|
|
return info.status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* load_builtin_dll
|
|
|
|
*/
|
2019-06-05 19:08:23 +02:00
|
|
|
static NTSTATUS load_builtin_dll( LPCWSTR load_path, const UNICODE_STRING *nt_name, void **module_ptr,
|
2019-06-05 17:54:09 +02:00
|
|
|
DWORD flags, WINE_MODREF** pwm )
|
|
|
|
{
|
|
|
|
const WCHAR *name, *p;
|
|
|
|
NTSTATUS status;
|
|
|
|
void *module = NULL;
|
|
|
|
pe_image_info_t image_info;
|
|
|
|
struct stat st;
|
|
|
|
char *so_name;
|
|
|
|
|
|
|
|
/* Fix the name in case we have a full path and extension */
|
|
|
|
name = nt_name->Buffer;
|
2020-03-31 11:47:47 +02:00
|
|
|
if ((p = wcsrchr( name, '\\' ))) name = p + 1;
|
|
|
|
if ((p = wcsrchr( name, '/' ))) name = p + 1;
|
2019-06-05 17:54:09 +02:00
|
|
|
|
|
|
|
TRACE("Trying built-in %s\n", debugstr_w(name));
|
|
|
|
|
2019-06-05 19:08:23 +02:00
|
|
|
if (!module_ptr) module_ptr = &module;
|
|
|
|
|
|
|
|
status = find_builtin_dll( name, pwm, module_ptr, &image_info, &st, &so_name );
|
2019-06-05 17:54:09 +02:00
|
|
|
if (status) return status;
|
|
|
|
|
|
|
|
if (*pwm)
|
|
|
|
{
|
|
|
|
if ((*pwm)->ldr.LoadCount != -1) (*pwm)->ldr.LoadCount++;
|
|
|
|
TRACE( "Found %s for %s at %p, count=%d\n",
|
|
|
|
debugstr_w((*pwm)->ldr.FullDllName.Buffer), debugstr_w(name),
|
|
|
|
(*pwm)->ldr.BaseAddress, (*pwm)->ldr.LoadCount);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-06-05 19:08:23 +02:00
|
|
|
if (*module_ptr)
|
2019-06-05 17:54:09 +02:00
|
|
|
{
|
|
|
|
TRACE( "loading %s from PE builtin %s\n", debugstr_w(name), debugstr_us(nt_name) );
|
2019-06-05 19:08:23 +02:00
|
|
|
return load_native_dll( load_path, nt_name, module_ptr, &image_info, flags, pwm, &st );
|
2019-06-05 17:54:09 +02:00
|
|
|
}
|
|
|
|
|
2020-04-16 10:26:13 +02:00
|
|
|
status = load_so_dll( load_path, nt_name, so_name, flags, pwm );
|
2019-06-24 10:30:51 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, so_name );
|
|
|
|
return status;
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-25 21:33:46 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* find_actctx_dll
|
|
|
|
*
|
|
|
|
* Find the full path (if any) of the dll from the activation context.
|
|
|
|
*/
|
|
|
|
static NTSTATUS find_actctx_dll( LPCWSTR libname, LPWSTR *fullname )
|
|
|
|
{
|
|
|
|
static const WCHAR winsxsW[] = {'\\','w','i','n','s','x','s','\\'};
|
2007-07-31 20:31:42 +02:00
|
|
|
static const WCHAR dotManifestW[] = {'.','m','a','n','i','f','e','s','t',0};
|
2007-07-25 21:33:46 +02:00
|
|
|
|
|
|
|
ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info;
|
|
|
|
ACTCTX_SECTION_KEYED_DATA data;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
NTSTATUS status;
|
|
|
|
SIZE_T needed, size = 1024;
|
|
|
|
WCHAR *p;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &nameW, libname );
|
|
|
|
data.cbSize = sizeof(data);
|
|
|
|
status = RtlFindActivationContextSectionString( FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
|
|
|
|
ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
|
|
|
|
&nameW, &data );
|
|
|
|
if (status != STATUS_SUCCESS) return status;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
status = STATUS_NO_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
status = RtlQueryInformationActivationContext( 0, data.hActCtx, &data.ulAssemblyRosterIndex,
|
|
|
|
AssemblyDetailedInformationInActivationContext,
|
|
|
|
info, size, &needed );
|
|
|
|
if (status == STATUS_SUCCESS) break;
|
|
|
|
if (status != STATUS_BUFFER_TOO_SMALL) goto done;
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, info );
|
|
|
|
size = needed;
|
|
|
|
/* restart with larger buffer */
|
|
|
|
}
|
|
|
|
|
2020-02-05 20:00:44 +01:00
|
|
|
if (!info->lpAssemblyManifestPath)
|
2009-08-05 11:23:16 +02:00
|
|
|
{
|
|
|
|
status = STATUS_SXS_KEY_NOT_FOUND;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2020-03-31 11:47:47 +02:00
|
|
|
if ((p = wcsrchr( info->lpAssemblyManifestPath, '\\' )))
|
2007-07-31 20:31:42 +02:00
|
|
|
{
|
2020-03-27 13:39:44 +01:00
|
|
|
DWORD len, dirlen = info->ulAssemblyDirectoryNameLength / sizeof(WCHAR);
|
2007-07-31 20:31:42 +02:00
|
|
|
p++;
|
2020-03-31 11:50:16 +02:00
|
|
|
len = wcslen( p );
|
2020-03-27 13:39:44 +01:00
|
|
|
if (!dirlen || len <= dirlen ||
|
|
|
|
RtlCompareUnicodeStrings( p, dirlen, info->lpAssemblyDirectoryName, dirlen, TRUE ) ||
|
|
|
|
wcsicmp( p + dirlen, dotManifestW ))
|
2007-07-31 20:31:42 +02:00
|
|
|
{
|
|
|
|
/* manifest name does not match directory name, so it's not a global
|
|
|
|
* windows/winsxs manifest; use the manifest directory name instead */
|
|
|
|
dirlen = p - info->lpAssemblyManifestPath;
|
|
|
|
needed = (dirlen + 1) * sizeof(WCHAR) + nameW.Length;
|
|
|
|
if (!(*fullname = p = RtlAllocateHeap( GetProcessHeap(), 0, needed )))
|
|
|
|
{
|
|
|
|
status = STATUS_NO_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
memcpy( p, info->lpAssemblyManifestPath, dirlen * sizeof(WCHAR) );
|
|
|
|
p += dirlen;
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy( p, libname );
|
2007-07-31 20:31:42 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 20:00:44 +01:00
|
|
|
if (!info->lpAssemblyDirectoryName)
|
|
|
|
{
|
|
|
|
status = STATUS_SXS_KEY_NOT_FOUND;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2020-03-31 11:50:16 +02:00
|
|
|
needed = (wcslen(user_shared_data->NtSystemRoot) * sizeof(WCHAR) +
|
2011-06-16 12:27:01 +02:00
|
|
|
sizeof(winsxsW) + info->ulAssemblyDirectoryNameLength + nameW.Length + 2*sizeof(WCHAR));
|
2007-07-25 21:33:46 +02:00
|
|
|
|
|
|
|
if (!(*fullname = p = RtlAllocateHeap( GetProcessHeap(), 0, needed )))
|
|
|
|
{
|
|
|
|
status = STATUS_NO_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy( p, user_shared_data->NtSystemRoot );
|
2020-03-31 11:50:16 +02:00
|
|
|
p += wcslen(p);
|
2007-07-25 21:33:46 +02:00
|
|
|
memcpy( p, winsxsW, sizeof(winsxsW) );
|
2018-08-02 21:54:37 +02:00
|
|
|
p += ARRAY_SIZE( winsxsW );
|
2007-07-25 21:33:46 +02:00
|
|
|
memcpy( p, info->lpAssemblyDirectoryName, info->ulAssemblyDirectoryNameLength );
|
|
|
|
p += info->ulAssemblyDirectoryNameLength / sizeof(WCHAR);
|
|
|
|
*p++ = '\\';
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy( p, libname );
|
2007-07-25 21:33:46 +02:00
|
|
|
done:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, info );
|
|
|
|
RtlReleaseActivationContext( data.hActCtx );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-08 12:46:32 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* search_dll_file
|
|
|
|
*
|
|
|
|
* Search for dll in the specified paths.
|
|
|
|
*/
|
2019-02-08 19:58:40 +01:00
|
|
|
static NTSTATUS search_dll_file( LPCWSTR paths, LPCWSTR search, UNICODE_STRING *nt_name,
|
2019-02-09 15:29:54 +01:00
|
|
|
WINE_MODREF **pwm, void **module, pe_image_info_t *image_info,
|
|
|
|
struct stat *st )
|
2019-02-08 12:46:32 +01:00
|
|
|
{
|
|
|
|
WCHAR *name;
|
2019-02-09 21:21:47 +01:00
|
|
|
BOOL found_image = FALSE;
|
2019-02-08 12:46:32 +01:00
|
|
|
NTSTATUS status = STATUS_DLL_NOT_FOUND;
|
2020-03-31 11:50:16 +02:00
|
|
|
ULONG len = wcslen( paths );
|
2019-02-08 12:46:32 +01:00
|
|
|
|
2020-03-31 11:50:16 +02:00
|
|
|
if (len < wcslen( system_dir )) len = wcslen( system_dir );
|
|
|
|
len += wcslen( search ) + 2;
|
2019-02-08 12:46:32 +01:00
|
|
|
|
|
|
|
if (!(name = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
while (*paths)
|
|
|
|
{
|
|
|
|
LPCWSTR ptr = paths;
|
|
|
|
|
|
|
|
while (*ptr && *ptr != ';') ptr++;
|
|
|
|
len = ptr - paths;
|
|
|
|
if (*ptr == ';') ptr++;
|
|
|
|
memcpy( name, paths, len * sizeof(WCHAR) );
|
|
|
|
if (len && name[len - 1] != '\\') name[len++] = '\\';
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy( name + len, search );
|
2019-04-22 11:36:39 +02:00
|
|
|
|
|
|
|
nt_name->Buffer = NULL;
|
|
|
|
if ((status = RtlDosPathNameToNtPathName_U_WithStatus( name, nt_name, NULL, NULL ))) goto done;
|
|
|
|
|
|
|
|
status = open_dll_file( nt_name, pwm, module, image_info, st );
|
2019-02-09 21:21:47 +01:00
|
|
|
if (status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH) found_image = TRUE;
|
|
|
|
else if (status != STATUS_DLL_NOT_FOUND) goto done;
|
2019-02-08 19:58:40 +01:00
|
|
|
RtlFreeUnicodeString( nt_name );
|
2019-02-08 12:46:32 +01:00
|
|
|
paths = ptr;
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:21:47 +01:00
|
|
|
if (!found_image)
|
|
|
|
{
|
|
|
|
/* not found, return file in the system dir to be loaded as builtin */
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy( name, system_dir );
|
2020-03-31 11:41:22 +02:00
|
|
|
wcscat( name, search );
|
2019-02-09 21:21:47 +01:00
|
|
|
if (!RtlDosPathNameToNtPathName_U( name, nt_name, NULL, NULL )) status = STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else status = STATUS_IMAGE_MACHINE_TYPE_MISMATCH;
|
2019-02-08 12:46:32 +01:00
|
|
|
|
|
|
|
done:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, name );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 05:48:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* find_dll_file
|
|
|
|
*
|
|
|
|
* Find the file (or already loaded module) for a given dll name.
|
|
|
|
*/
|
2019-11-07 18:54:21 +01:00
|
|
|
static NTSTATUS find_dll_file( const WCHAR *load_path, const WCHAR *libname, const WCHAR *default_ext,
|
2019-02-08 12:46:32 +01:00
|
|
|
UNICODE_STRING *nt_name, WINE_MODREF **pwm,
|
2019-02-09 15:29:54 +01:00
|
|
|
void **module, pe_image_info_t *image_info, struct stat *st )
|
2003-10-07 05:48:42 +02:00
|
|
|
{
|
2019-02-08 12:46:32 +01:00
|
|
|
WCHAR *ext, *dllname;
|
2019-06-20 17:50:32 +02:00
|
|
|
NTSTATUS status;
|
2019-10-25 00:12:12 +02:00
|
|
|
ULONG wow64_old_value = 0;
|
2003-10-07 05:48:42 +02:00
|
|
|
|
2019-02-08 19:58:40 +01:00
|
|
|
*pwm = NULL;
|
2019-02-09 10:59:47 +01:00
|
|
|
*module = NULL;
|
2004-11-23 15:03:49 +01:00
|
|
|
dllname = NULL;
|
2019-11-07 18:54:21 +01:00
|
|
|
|
|
|
|
if (default_ext) /* first append default extension */
|
2004-11-23 15:03:49 +01:00
|
|
|
{
|
2020-03-31 11:47:47 +02:00
|
|
|
if (!(ext = wcsrchr( libname, '.')) || wcschr( ext, '/' ) || wcschr( ext, '\\'))
|
2019-11-07 18:54:21 +01:00
|
|
|
{
|
|
|
|
if (!(dllname = RtlAllocateHeap( GetProcessHeap(), 0,
|
2020-03-31 11:50:16 +02:00
|
|
|
(wcslen(libname)+wcslen(default_ext)+1) * sizeof(WCHAR))))
|
2019-11-07 18:54:21 +01:00
|
|
|
return STATUS_NO_MEMORY;
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy( dllname, libname );
|
2020-03-31 11:41:22 +02:00
|
|
|
wcscat( dllname, default_ext );
|
2019-11-07 18:54:21 +01:00
|
|
|
libname = dllname;
|
|
|
|
}
|
2004-11-23 15:03:49 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 00:12:12 +02:00
|
|
|
/* Win 7/2008R2 and up seem to re-enable WoW64 FS redirection when loading libraries */
|
|
|
|
if (is_wow64) RtlWow64EnableFsRedirectionEx( 0, &wow64_old_value );
|
|
|
|
|
2019-02-08 12:46:32 +01:00
|
|
|
nt_name->Buffer = NULL;
|
2006-01-18 14:22:19 +01:00
|
|
|
|
|
|
|
if (!contains_path( libname ))
|
|
|
|
{
|
2007-07-30 14:46:09 +02:00
|
|
|
WCHAR *fullname = NULL;
|
2007-07-25 21:33:46 +02:00
|
|
|
|
|
|
|
status = find_actctx_dll( libname, &fullname );
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
2007-07-31 20:31:42 +02:00
|
|
|
TRACE ("found %s for %s\n", debugstr_w(fullname), debugstr_w(libname) );
|
2007-07-25 21:33:46 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, dllname );
|
|
|
|
libname = dllname = fullname;
|
|
|
|
}
|
2019-06-20 17:50:32 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (status != STATUS_SXS_KEY_NOT_FOUND) goto done;
|
|
|
|
if ((*pwm = find_basename_module( libname )) != NULL)
|
|
|
|
{
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2006-01-18 14:22:19 +01:00
|
|
|
}
|
|
|
|
|
2003-10-07 05:48:42 +02:00
|
|
|
if (RtlDetermineDosPathNameType_U( libname ) == RELATIVE_PATH)
|
2019-02-09 15:29:54 +01:00
|
|
|
status = search_dll_file( load_path, libname, nt_name, pwm, module, image_info, st );
|
2019-04-22 11:36:39 +02:00
|
|
|
else if (!(status = RtlDosPathNameToNtPathName_U_WithStatus( libname, nt_name, NULL, NULL )))
|
|
|
|
status = open_dll_file( nt_name, pwm, module, image_info, st );
|
2018-02-28 09:59:02 +01:00
|
|
|
|
2019-02-09 21:21:47 +01:00
|
|
|
if (status == STATUS_IMAGE_MACHINE_TYPE_MISMATCH) status = STATUS_INVALID_IMAGE_FORMAT;
|
|
|
|
|
2019-02-08 19:58:40 +01:00
|
|
|
done:
|
2004-11-23 15:03:49 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, dllname );
|
2019-10-25 00:12:12 +02:00
|
|
|
if (wow64_old_value) RtlWow64EnableFsRedirectionEx( 1, &wow64_old_value );
|
2019-02-08 19:58:40 +01:00
|
|
|
return status;
|
2003-10-07 05:48:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-14 06:01:20 +01:00
|
|
|
/***********************************************************************
|
2003-04-05 07:16:11 +02:00
|
|
|
* load_dll (internal)
|
2003-03-14 06:01:20 +01:00
|
|
|
*
|
|
|
|
* Load a PE style module according to the load order.
|
2003-09-29 22:42:24 +02:00
|
|
|
* The loader_section must be locked while calling this function.
|
2003-03-14 06:01:20 +01:00
|
|
|
*/
|
2019-11-07 18:54:21 +01:00
|
|
|
static NTSTATUS load_dll( const WCHAR *load_path, const WCHAR *libname, const WCHAR *default_ext,
|
|
|
|
DWORD flags, WINE_MODREF** pwm )
|
2003-03-14 06:01:20 +01:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
enum loadorder loadorder;
|
2003-09-25 22:33:41 +02:00
|
|
|
WINE_MODREF *main_exe;
|
2019-02-08 12:46:32 +01:00
|
|
|
UNICODE_STRING nt_name;
|
2018-02-28 10:11:55 +01:00
|
|
|
struct stat st;
|
2019-02-09 10:59:47 +01:00
|
|
|
void *module;
|
|
|
|
pe_image_info_t image_info;
|
2003-10-07 05:48:42 +02:00
|
|
|
NTSTATUS nts;
|
2003-03-14 06:01:20 +01:00
|
|
|
|
2003-10-02 06:58:49 +02:00
|
|
|
TRACE( "looking for %s in %s\n", debugstr_w(libname), debugstr_w(load_path) );
|
2003-03-14 06:01:20 +01:00
|
|
|
|
2019-11-07 18:54:21 +01:00
|
|
|
nts = find_dll_file( load_path, libname, default_ext, &nt_name, pwm, &module, &image_info, &st );
|
2003-10-07 05:48:42 +02:00
|
|
|
|
|
|
|
if (*pwm) /* found already loaded module */
|
2003-03-14 06:01:20 +01:00
|
|
|
{
|
2003-10-07 05:48:42 +02:00
|
|
|
if ((*pwm)->ldr.LoadCount != -1) (*pwm)->ldr.LoadCount++;
|
|
|
|
|
2007-10-25 23:36:39 +02:00
|
|
|
TRACE("Found %s for %s at %p, count=%d\n",
|
2003-10-07 05:48:42 +02:00
|
|
|
debugstr_w((*pwm)->ldr.FullDllName.Buffer), debugstr_w(libname),
|
|
|
|
(*pwm)->ldr.BaseAddress, (*pwm)->ldr.LoadCount);
|
2019-02-08 12:46:32 +01:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2003-10-07 05:48:42 +02:00
|
|
|
return STATUS_SUCCESS;
|
2003-03-14 06:01:20 +01:00
|
|
|
}
|
|
|
|
|
2019-02-09 10:59:47 +01:00
|
|
|
if (nts && nts != STATUS_DLL_NOT_FOUND && nts != STATUS_INVALID_IMAGE_NOT_MZ) goto done;
|
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
main_exe = get_modref( NtCurrentTeb()->Peb->ImageBaseAddress );
|
2019-02-08 22:07:54 +01:00
|
|
|
loadorder = get_load_order( main_exe ? main_exe->ldr.BaseDllName.Buffer : NULL, &nt_name );
|
2003-03-14 06:01:20 +01:00
|
|
|
|
2019-02-09 10:59:47 +01:00
|
|
|
switch (nts)
|
2008-03-05 12:21:19 +01:00
|
|
|
{
|
2019-02-09 10:59:47 +01:00
|
|
|
case STATUS_INVALID_IMAGE_NOT_MZ: /* not in PE format, maybe it's a .so file */
|
|
|
|
switch (loadorder)
|
|
|
|
{
|
|
|
|
case LO_NATIVE:
|
|
|
|
case LO_NATIVE_BUILTIN:
|
|
|
|
case LO_BUILTIN:
|
|
|
|
case LO_BUILTIN_NATIVE:
|
|
|
|
case LO_DEFAULT:
|
2020-04-16 10:26:13 +02:00
|
|
|
if (!load_so_dll( load_path, &nt_name, NULL, flags, pwm )) nts = STATUS_SUCCESS;
|
2019-02-09 10:59:47 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nts = STATUS_DLL_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STATUS_SUCCESS: /* valid PE file */
|
2019-04-22 11:36:54 +02:00
|
|
|
if (image_info.image_flags & IMAGE_FLAGS_WineBuiltin)
|
|
|
|
{
|
|
|
|
switch (loadorder)
|
|
|
|
{
|
|
|
|
case LO_NATIVE_BUILTIN:
|
|
|
|
case LO_BUILTIN:
|
|
|
|
case LO_BUILTIN_NATIVE:
|
|
|
|
case LO_DEFAULT:
|
2019-06-05 19:08:23 +02:00
|
|
|
nts = load_builtin_dll( load_path, &nt_name, &module, flags, pwm );
|
2019-12-17 12:04:31 +01:00
|
|
|
if (nts == STATUS_DLL_NOT_FOUND)
|
|
|
|
nts = load_native_dll( load_path, &nt_name, &module, &image_info, flags, pwm, &st );
|
2019-04-22 11:36:54 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nts = STATUS_DLL_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
}
|
2019-06-05 19:08:23 +02:00
|
|
|
if (module) NtUnmapViewOfSection( NtCurrentProcess(), module );
|
2019-04-22 11:36:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-02-09 15:29:54 +01:00
|
|
|
if (!(image_info.image_flags & IMAGE_FLAGS_WineFakeDll))
|
2019-02-09 10:59:47 +01:00
|
|
|
{
|
|
|
|
switch (loadorder)
|
|
|
|
{
|
|
|
|
case LO_NATIVE:
|
|
|
|
case LO_NATIVE_BUILTIN:
|
2019-06-05 19:08:23 +02:00
|
|
|
nts = load_native_dll( load_path, &nt_name, &module, &image_info, flags, pwm, &st );
|
2019-02-09 10:59:47 +01:00
|
|
|
break;
|
|
|
|
case LO_BUILTIN:
|
2019-12-17 12:04:31 +01:00
|
|
|
nts = load_builtin_dll( load_path, &nt_name, &module, flags, pwm );
|
2019-02-09 10:59:47 +01:00
|
|
|
break;
|
|
|
|
case LO_BUILTIN_NATIVE:
|
|
|
|
case LO_DEFAULT:
|
2019-12-17 12:04:31 +01:00
|
|
|
nts = load_builtin_dll( load_path, &nt_name, &module, flags, pwm );
|
2019-02-09 10:59:47 +01:00
|
|
|
if (nts == STATUS_SUCCESS && loadorder == LO_DEFAULT &&
|
|
|
|
(MODULE_InitDLL( *pwm, DLL_WINE_PREATTACH, NULL ) != STATUS_SUCCESS))
|
|
|
|
{
|
|
|
|
/* stub-only dll, try native */
|
|
|
|
TRACE( "%s pre-attach returned FALSE, preferring native\n", debugstr_us(&nt_name) );
|
|
|
|
LdrUnloadDll( (*pwm)->ldr.BaseAddress );
|
|
|
|
nts = STATUS_DLL_NOT_FOUND;
|
2019-12-17 12:04:31 +01:00
|
|
|
/* map the dll again if it was unmapped */
|
|
|
|
if (!module && open_dll_file( &nt_name, pwm, &module, &image_info, &st )) break;
|
2019-02-09 10:59:47 +01:00
|
|
|
}
|
|
|
|
if (nts == STATUS_DLL_NOT_FOUND)
|
2019-06-05 19:08:23 +02:00
|
|
|
nts = load_native_dll( load_path, &nt_name, &module, &image_info, flags, pwm, &st );
|
2019-02-09 10:59:47 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nts = STATUS_DLL_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (module) NtUnmapViewOfSection( NtCurrentProcess(), module );
|
|
|
|
break;
|
|
|
|
}
|
2019-02-08 12:49:47 +01:00
|
|
|
TRACE( "%s is a fake Wine dll\n", debugstr_us(&nt_name) );
|
2019-02-09 10:59:47 +01:00
|
|
|
NtUnmapViewOfSection( NtCurrentProcess(), module );
|
|
|
|
/* fall through */
|
2008-03-05 12:21:19 +01:00
|
|
|
|
2019-02-09 10:59:47 +01:00
|
|
|
case STATUS_DLL_NOT_FOUND: /* no file found, try builtin */
|
|
|
|
switch (loadorder)
|
2003-03-14 06:01:20 +01:00
|
|
|
{
|
2019-02-09 10:59:47 +01:00
|
|
|
case LO_NATIVE_BUILTIN:
|
|
|
|
case LO_BUILTIN:
|
|
|
|
case LO_BUILTIN_NATIVE:
|
|
|
|
case LO_DEFAULT:
|
2019-06-05 19:08:23 +02:00
|
|
|
nts = load_builtin_dll( load_path, &nt_name, NULL, flags, pwm );
|
2019-02-09 10:59:47 +01:00
|
|
|
break;
|
|
|
|
default:
|
2006-03-21 15:10:22 +01:00
|
|
|
nts = STATUS_DLL_NOT_FOUND;
|
2019-02-09 10:59:47 +01:00
|
|
|
break;
|
2006-03-21 15:10:22 +01:00
|
|
|
}
|
2006-02-21 11:56:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2003-03-14 06:01:20 +01:00
|
|
|
|
2019-02-08 19:58:40 +01:00
|
|
|
done:
|
2006-02-21 11:56:16 +01:00
|
|
|
if (nts == STATUS_SUCCESS)
|
2019-04-22 11:36:54 +02:00
|
|
|
TRACE("Loaded module %s at %p\n", debugstr_us(&nt_name), (*pwm)->ldr.BaseAddress);
|
2019-02-08 12:46:32 +01:00
|
|
|
else
|
|
|
|
WARN("Failed to load module %s; status=%x\n", debugstr_w(libname), nts);
|
2003-03-14 06:01:20 +01:00
|
|
|
|
2019-02-08 12:46:32 +01:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2003-10-02 06:58:49 +02:00
|
|
|
return nts;
|
2003-03-14 06:01:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* LdrLoadDll (NTDLL.@)
|
|
|
|
*/
|
2012-01-06 11:21:13 +01:00
|
|
|
NTSTATUS WINAPI DECLSPEC_HOTPATCH LdrLoadDll(LPCWSTR path_name, DWORD flags,
|
|
|
|
const UNICODE_STRING *libname, HMODULE* hModule)
|
2003-03-14 06:01:20 +01:00
|
|
|
{
|
|
|
|
WINE_MODREF *wm;
|
2003-09-29 22:42:24 +02:00
|
|
|
NTSTATUS nts;
|
2003-03-14 06:01:20 +01:00
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
|
2003-10-08 00:56:34 +02:00
|
|
|
if (!path_name) path_name = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer;
|
2019-11-07 18:54:21 +01:00
|
|
|
nts = load_dll( path_name, libname->Buffer, dllW, flags, &wm );
|
2003-09-29 22:42:24 +02:00
|
|
|
|
|
|
|
if (nts == STATUS_SUCCESS && !(wm->ldr.Flags & LDR_DONT_RESOLVE_REFS))
|
2003-03-14 06:01:20 +01:00
|
|
|
{
|
2003-10-06 23:18:51 +02:00
|
|
|
nts = process_attach( wm, NULL );
|
2003-05-14 21:51:14 +02:00
|
|
|
if (nts != STATUS_SUCCESS)
|
2003-03-14 06:01:20 +01:00
|
|
|
{
|
2003-03-20 23:05:26 +01:00
|
|
|
LdrUnloadDll(wm->ldr.BaseAddress);
|
2003-03-14 06:01:20 +01:00
|
|
|
wm = NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-03-20 23:05:26 +01:00
|
|
|
*hModule = (wm) ? wm->ldr.BaseAddress : NULL;
|
2003-03-14 06:01:20 +01:00
|
|
|
|
2003-09-29 22:42:24 +02:00
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
2003-03-14 06:01:20 +01:00
|
|
|
return nts;
|
|
|
|
}
|
|
|
|
|
2007-05-16 16:35:43 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* LdrGetDllHandle (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrGetDllHandle( LPCWSTR load_path, ULONG flags, const UNICODE_STRING *name, HMODULE *base )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
2019-02-08 12:46:32 +01:00
|
|
|
UNICODE_STRING nt_name;
|
2007-05-16 16:35:43 +02:00
|
|
|
WINE_MODREF *wm;
|
2019-02-09 10:59:47 +01:00
|
|
|
void *module;
|
|
|
|
pe_image_info_t image_info;
|
2018-02-28 10:11:55 +01:00
|
|
|
struct stat st;
|
2007-05-16 16:35:43 +02:00
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
|
|
|
|
if (!load_path) load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer;
|
|
|
|
|
2019-11-07 18:54:21 +01:00
|
|
|
status = find_dll_file( load_path, name->Buffer, dllW, &nt_name, &wm, &module, &image_info, &st );
|
2007-05-16 16:35:43 +02:00
|
|
|
|
2019-02-09 10:59:47 +01:00
|
|
|
if (wm) *base = wm->ldr.BaseAddress;
|
|
|
|
else
|
2007-05-16 16:35:43 +02:00
|
|
|
{
|
2019-02-09 10:59:47 +01:00
|
|
|
if (status == STATUS_SUCCESS) NtUnmapViewOfSection( NtCurrentProcess(), module );
|
|
|
|
status = STATUS_DLL_NOT_FOUND;
|
2007-05-16 16:35:43 +02:00
|
|
|
}
|
2019-02-09 10:59:47 +01:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2007-05-16 16:35:43 +02:00
|
|
|
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
TRACE( "%s -> %p (load path %s)\n", debugstr_us(name), status ? NULL : *base, debugstr_w(load_path) );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-16 16:39:29 +02:00
|
|
|
/******************************************************************
|
|
|
|
* LdrAddRefDll (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrAddRefDll( ULONG flags, HMODULE module )
|
|
|
|
{
|
|
|
|
NTSTATUS ret = STATUS_SUCCESS;
|
|
|
|
WINE_MODREF *wm;
|
|
|
|
|
2013-10-14 06:07:58 +02:00
|
|
|
if (flags & ~LDR_ADDREF_DLL_PIN) FIXME( "%p flags %x not implemented\n", module, flags );
|
2007-05-16 16:39:29 +02:00
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
|
|
|
|
if ((wm = get_modref( module )))
|
|
|
|
{
|
2013-10-14 06:07:58 +02:00
|
|
|
if (flags & LDR_ADDREF_DLL_PIN)
|
|
|
|
wm->ldr.LoadCount = -1;
|
|
|
|
else
|
|
|
|
if (wm->ldr.LoadCount != -1) wm->ldr.LoadCount++;
|
2007-05-16 16:39:29 +02:00
|
|
|
TRACE( "(%s) ldr.LoadCount: %d\n", debugstr_w(wm->ldr.BaseDllName.Buffer), wm->ldr.LoadCount );
|
|
|
|
}
|
|
|
|
else ret = STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-02 20:38:51 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* LdrProcessRelocationBlock (NTDLL.@)
|
|
|
|
*
|
|
|
|
* Apply relocations to a given page of a mapped PE image.
|
|
|
|
*/
|
|
|
|
IMAGE_BASE_RELOCATION * WINAPI LdrProcessRelocationBlock( void *page, UINT count,
|
2008-12-22 00:07:58 +01:00
|
|
|
USHORT *relocs, INT_PTR delta )
|
2008-04-02 20:38:51 +02:00
|
|
|
{
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
USHORT offset = *relocs & 0xfff;
|
|
|
|
int type = *relocs >> 12;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case IMAGE_REL_BASED_ABSOLUTE:
|
|
|
|
break;
|
|
|
|
case IMAGE_REL_BASED_HIGH:
|
|
|
|
*(short *)((char *)page + offset) += HIWORD(delta);
|
|
|
|
break;
|
|
|
|
case IMAGE_REL_BASED_LOW:
|
|
|
|
*(short *)((char *)page + offset) += LOWORD(delta);
|
|
|
|
break;
|
|
|
|
case IMAGE_REL_BASED_HIGHLOW:
|
|
|
|
*(int *)((char *)page + offset) += delta;
|
|
|
|
break;
|
2017-07-07 12:39:23 +02:00
|
|
|
#ifdef _WIN64
|
2008-12-22 00:07:58 +01:00
|
|
|
case IMAGE_REL_BASED_DIR64:
|
|
|
|
*(INT_PTR *)((char *)page + offset) += delta;
|
|
|
|
break;
|
2013-01-20 18:02:10 +01:00
|
|
|
#elif defined(__arm__)
|
|
|
|
case IMAGE_REL_BASED_THUMB_MOV32:
|
|
|
|
{
|
|
|
|
DWORD inst = *(INT_PTR *)((char *)page + offset);
|
|
|
|
DWORD imm16 = ((inst << 1) & 0x0800) + ((inst << 12) & 0xf000) +
|
2013-04-12 23:19:46 +02:00
|
|
|
((inst >> 20) & 0x0700) + ((inst >> 16) & 0x00ff);
|
2014-01-02 22:24:57 +01:00
|
|
|
DWORD hi_delta;
|
2013-01-20 18:02:10 +01:00
|
|
|
|
|
|
|
if ((inst & 0x8000fbf0) != 0x0000f240)
|
|
|
|
ERR("wrong Thumb2 instruction %08x, expected MOVW\n", inst);
|
|
|
|
|
|
|
|
imm16 += LOWORD(delta);
|
2014-01-02 22:24:57 +01:00
|
|
|
hi_delta = HIWORD(delta) + HIWORD(imm16);
|
2013-01-20 18:02:10 +01:00
|
|
|
*(INT_PTR *)((char *)page + offset) = (inst & 0x8f00fbf0) + ((imm16 >> 1) & 0x0400) +
|
|
|
|
((imm16 >> 12) & 0x000f) +
|
|
|
|
((imm16 << 20) & 0x70000000) +
|
2013-04-12 23:19:46 +02:00
|
|
|
((imm16 << 16) & 0xff0000);
|
2013-01-20 18:02:10 +01:00
|
|
|
|
2014-01-02 22:24:57 +01:00
|
|
|
if (hi_delta != 0)
|
2013-01-20 18:02:10 +01:00
|
|
|
{
|
|
|
|
inst = *(INT_PTR *)((char *)page + offset + 4);
|
|
|
|
imm16 = ((inst << 1) & 0x0800) + ((inst << 12) & 0xf000) +
|
2013-04-12 23:19:46 +02:00
|
|
|
((inst >> 20) & 0x0700) + ((inst >> 16) & 0x00ff);
|
2013-01-20 18:02:10 +01:00
|
|
|
|
|
|
|
if ((inst & 0x8000fbf0) != 0x0000f2c0)
|
|
|
|
ERR("wrong Thumb2 instruction %08x, expected MOVT\n", inst);
|
|
|
|
|
2014-01-02 22:24:57 +01:00
|
|
|
imm16 += hi_delta;
|
2013-01-20 18:02:10 +01:00
|
|
|
if (imm16 > 0xffff)
|
|
|
|
ERR("resulting immediate value won't fit: %08x\n", imm16);
|
|
|
|
*(INT_PTR *)((char *)page + offset + 4) = (inst & 0x8f00fbf0) +
|
|
|
|
((imm16 >> 1) & 0x0400) +
|
|
|
|
((imm16 >> 12) & 0x000f) +
|
|
|
|
((imm16 << 20) & 0x70000000) +
|
2013-04-12 23:19:46 +02:00
|
|
|
((imm16 << 16) & 0xff0000);
|
2013-01-20 18:02:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-12-22 00:07:58 +01:00
|
|
|
#endif
|
2008-04-02 20:38:51 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unknown/unsupported fixup type %x.\n", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
relocs++;
|
|
|
|
}
|
|
|
|
return (IMAGE_BASE_RELOCATION *)relocs; /* return address of next block */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-21 01:34:36 +01:00
|
|
|
/******************************************************************
|
|
|
|
* LdrQueryProcessModuleInformation
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrQueryProcessModuleInformation(PSYSTEM_MODULE_INFORMATION smi,
|
|
|
|
ULONG buf_size, ULONG* req_size)
|
|
|
|
{
|
|
|
|
SYSTEM_MODULE* sm = &smi->Modules[0];
|
|
|
|
ULONG size = sizeof(ULONG);
|
|
|
|
NTSTATUS nts = STATUS_SUCCESS;
|
|
|
|
ANSI_STRING str;
|
|
|
|
char* ptr;
|
2003-07-01 05:38:56 +02:00
|
|
|
PLIST_ENTRY mark, entry;
|
|
|
|
PLDR_MODULE mod;
|
2007-06-19 16:58:42 +02:00
|
|
|
WORD id = 0;
|
2003-03-21 01:34:36 +01:00
|
|
|
|
|
|
|
smi->ModulesCount = 0;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
2003-07-01 05:38:56 +02:00
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
|
|
|
|
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
|
2003-03-21 01:34:36 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
|
2003-03-21 01:34:36 +01:00
|
|
|
size += sizeof(*sm);
|
|
|
|
if (size <= buf_size)
|
|
|
|
{
|
2019-10-20 11:18:52 +02:00
|
|
|
sm->Section = 0; /* FIXME */
|
|
|
|
sm->MappedBaseAddress = mod->BaseAddress;
|
2003-07-01 05:38:56 +02:00
|
|
|
sm->ImageBaseAddress = mod->BaseAddress;
|
|
|
|
sm->ImageSize = mod->SizeOfImage;
|
|
|
|
sm->Flags = mod->Flags;
|
2019-10-20 11:18:52 +02:00
|
|
|
sm->LoadOrderIndex = id++;
|
|
|
|
sm->InitOrderIndex = 0; /* FIXME */
|
|
|
|
sm->LoadCount = mod->LoadCount;
|
2003-03-21 01:34:36 +01:00
|
|
|
str.Length = 0;
|
|
|
|
str.MaximumLength = MAXIMUM_FILENAME_LENGTH;
|
2005-09-02 16:47:36 +02:00
|
|
|
str.Buffer = (char*)sm->Name;
|
2003-07-01 05:38:56 +02:00
|
|
|
RtlUnicodeStringToAnsiString(&str, &mod->FullDllName, FALSE);
|
2005-09-02 16:47:36 +02:00
|
|
|
ptr = strrchr(str.Buffer, '\\');
|
|
|
|
sm->NameOffset = (ptr != NULL) ? (ptr - str.Buffer + 1) : 0;
|
2003-03-21 01:34:36 +01:00
|
|
|
|
|
|
|
smi->ModulesCount++;
|
|
|
|
sm++;
|
|
|
|
}
|
|
|
|
else nts = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
|
|
|
|
if (req_size) *req_size = size;
|
|
|
|
|
|
|
|
return nts;
|
|
|
|
}
|
|
|
|
|
2006-11-03 13:52:02 +01:00
|
|
|
|
2010-01-20 17:11:03 +01:00
|
|
|
static NTSTATUS query_dword_option( HANDLE hkey, LPCWSTR name, ULONG *value )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING str;
|
|
|
|
ULONG size;
|
|
|
|
WCHAR buffer[64];
|
|
|
|
KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &str, name );
|
|
|
|
|
|
|
|
size = sizeof(buffer) - sizeof(WCHAR);
|
|
|
|
if ((status = NtQueryValueKey( hkey, &str, KeyValuePartialInformation, buffer, size, &size )))
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (info->Type != REG_DWORD)
|
|
|
|
{
|
|
|
|
buffer[size / sizeof(WCHAR)] = 0;
|
2020-03-31 11:49:15 +02:00
|
|
|
*value = wcstoul( (WCHAR *)info->Data, 0, 16 );
|
2010-01-20 17:11:03 +01:00
|
|
|
}
|
|
|
|
else memcpy( value, info->Data, sizeof(*value) );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS query_string_option( HANDLE hkey, LPCWSTR name, ULONG type,
|
|
|
|
void *data, ULONG in_size, ULONG *out_size )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING str;
|
|
|
|
ULONG size;
|
|
|
|
char *buffer;
|
|
|
|
KEY_VALUE_PARTIAL_INFORMATION *info;
|
|
|
|
static const int info_size = FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION, Data );
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &str, name );
|
|
|
|
|
|
|
|
size = info_size + in_size;
|
|
|
|
if (!(buffer = RtlAllocateHeap( GetProcessHeap(), 0, size ))) return STATUS_NO_MEMORY;
|
|
|
|
info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
|
|
|
|
status = NtQueryValueKey( hkey, &str, KeyValuePartialInformation, buffer, size, &size );
|
|
|
|
if (!status || status == STATUS_BUFFER_OVERFLOW)
|
|
|
|
{
|
|
|
|
if (out_size) *out_size = info->DataLength;
|
|
|
|
if (data && !status) memcpy( data, info->Data, info->DataLength );
|
|
|
|
}
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, buffer );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* LdrQueryImageFileExecutionOptions (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrQueryImageFileExecutionOptions( const UNICODE_STRING *key, LPCWSTR value, ULONG type,
|
|
|
|
void *data, ULONG in_size, ULONG *out_size )
|
|
|
|
{
|
|
|
|
static const WCHAR optionsW[] = {'M','a','c','h','i','n','e','\\',
|
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'W','i','n','d','o','w','s',' ','N','T','\\',
|
|
|
|
'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
|
|
|
|
'I','m','a','g','e',' ','F','i','l','e',' ',
|
|
|
|
'E','x','e','c','u','t','i','o','n',' ','O','p','t','i','o','n','s','\\'};
|
2018-08-02 21:54:37 +02:00
|
|
|
WCHAR path[MAX_PATH + ARRAY_SIZE( optionsW )];
|
2010-01-20 17:11:03 +01:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING name_str;
|
|
|
|
HANDLE hkey;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG len;
|
|
|
|
WCHAR *p;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &name_str;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
2020-03-30 12:09:38 +02:00
|
|
|
p = key->Buffer + key->Length / sizeof(WCHAR);
|
|
|
|
while (p > key->Buffer && p[-1] != '\\') p--;
|
2010-01-20 17:11:03 +01:00
|
|
|
len = key->Length - (p - key->Buffer) * sizeof(WCHAR);
|
|
|
|
name_str.Buffer = path;
|
|
|
|
name_str.Length = sizeof(optionsW) + len;
|
|
|
|
name_str.MaximumLength = name_str.Length;
|
|
|
|
memcpy( path, optionsW, sizeof(optionsW) );
|
2018-08-02 21:54:37 +02:00
|
|
|
memcpy( path + ARRAY_SIZE( optionsW ), p, len );
|
2010-01-20 17:11:03 +01:00
|
|
|
if ((status = NtOpenKey( &hkey, KEY_QUERY_VALUE, &attr ))) return status;
|
|
|
|
|
|
|
|
if (type == REG_DWORD)
|
|
|
|
{
|
|
|
|
if (out_size) *out_size = sizeof(ULONG);
|
|
|
|
if (in_size >= sizeof(ULONG)) status = query_dword_option( hkey, value, data );
|
|
|
|
else status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
else status = query_string_option( hkey, value, type, data, in_size, out_size );
|
|
|
|
|
|
|
|
NtClose( hkey );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 13:52:02 +01:00
|
|
|
/******************************************************************
|
|
|
|
* RtlDllShutdownInProgress (NTDLL.@)
|
|
|
|
*/
|
|
|
|
BOOLEAN WINAPI RtlDllShutdownInProgress(void)
|
|
|
|
{
|
|
|
|
return process_detaching;
|
|
|
|
}
|
|
|
|
|
2013-11-11 23:20:41 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* LdrResolveDelayLoadedAPI (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void* WINAPI LdrResolveDelayLoadedAPI( void* base, const IMAGE_DELAYLOAD_DESCRIPTOR* desc,
|
2018-11-10 22:29:27 +01:00
|
|
|
PDELAYLOAD_FAILURE_DLL_CALLBACK dllhook,
|
|
|
|
PDELAYLOAD_FAILURE_SYSTEM_ROUTINE syshook,
|
2013-11-11 23:20:41 +01:00
|
|
|
IMAGE_THUNK_DATA* addr, ULONG flags )
|
|
|
|
{
|
|
|
|
IMAGE_THUNK_DATA *pIAT, *pINT;
|
|
|
|
DELAYLOAD_INFO delayinfo;
|
|
|
|
UNICODE_STRING mod;
|
|
|
|
const CHAR* name;
|
|
|
|
HMODULE *phmod;
|
|
|
|
NTSTATUS nts;
|
|
|
|
FARPROC fp;
|
|
|
|
DWORD id;
|
|
|
|
|
2019-08-06 17:45:18 +02:00
|
|
|
TRACE( "(%p, %p, %p, %p, %p, 0x%08x)\n", base, desc, dllhook, syshook, addr, flags );
|
2013-11-11 23:20:41 +01:00
|
|
|
|
|
|
|
phmod = get_rva(base, desc->ModuleHandleRVA);
|
|
|
|
pIAT = get_rva(base, desc->ImportAddressTableRVA);
|
|
|
|
pINT = get_rva(base, desc->ImportNameTableRVA);
|
|
|
|
name = get_rva(base, desc->DllNameRVA);
|
|
|
|
id = addr - pIAT;
|
|
|
|
|
|
|
|
if (!*phmod)
|
|
|
|
{
|
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz(&mod, name))
|
|
|
|
{
|
|
|
|
nts = STATUS_NO_MEMORY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
nts = LdrLoadDll(NULL, 0, &mod, phmod);
|
|
|
|
RtlFreeUnicodeString(&mod);
|
|
|
|
if (nts) goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IMAGE_SNAP_BY_ORDINAL(pINT[id].u1.Ordinal))
|
|
|
|
nts = LdrGetProcedureAddress(*phmod, NULL, LOWORD(pINT[id].u1.Ordinal), (void**)&fp);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const IMAGE_IMPORT_BY_NAME* iibn = get_rva(base, pINT[id].u1.AddressOfData);
|
|
|
|
ANSI_STRING fnc;
|
|
|
|
|
|
|
|
RtlInitAnsiString(&fnc, (char*)iibn->Name);
|
|
|
|
nts = LdrGetProcedureAddress(*phmod, &fnc, 0, (void**)&fp);
|
|
|
|
}
|
|
|
|
if (!nts)
|
|
|
|
{
|
|
|
|
pIAT[id].u1.Function = (ULONG_PTR)fp;
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
delayinfo.Size = sizeof(delayinfo);
|
|
|
|
delayinfo.DelayloadDescriptor = desc;
|
|
|
|
delayinfo.ThunkAddress = addr;
|
|
|
|
delayinfo.TargetDllName = name;
|
|
|
|
delayinfo.TargetApiDescriptor.ImportDescribedByName = !IMAGE_SNAP_BY_ORDINAL(pINT[id].u1.Ordinal);
|
|
|
|
delayinfo.TargetApiDescriptor.Description.Ordinal = LOWORD(pINT[id].u1.Ordinal);
|
|
|
|
delayinfo.TargetModuleBase = *phmod;
|
|
|
|
delayinfo.Unused = NULL;
|
|
|
|
delayinfo.LastError = nts;
|
2018-11-10 22:29:27 +01:00
|
|
|
|
|
|
|
if (dllhook)
|
|
|
|
return dllhook(4, &delayinfo);
|
|
|
|
|
|
|
|
if (IMAGE_SNAP_BY_ORDINAL(pINT[id].u1.Ordinal))
|
|
|
|
{
|
|
|
|
DWORD_PTR ord = LOWORD(pINT[id].u1.Ordinal);
|
|
|
|
return syshook(name, (const char *)ord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const IMAGE_IMPORT_BY_NAME* iibn = get_rva(base, pINT[id].u1.AddressOfData);
|
|
|
|
return syshook(name, (const char *)iibn->Name);
|
|
|
|
}
|
2013-11-11 23:20:41 +01:00
|
|
|
}
|
2006-11-03 13:52:02 +01:00
|
|
|
|
2003-03-04 05:36:56 +01:00
|
|
|
/******************************************************************
|
|
|
|
* LdrShutdownProcess (NTDLL.@)
|
|
|
|
*
|
|
|
|
*/
|
2003-05-08 06:13:26 +02:00
|
|
|
void WINAPI LdrShutdownProcess(void)
|
2003-03-04 05:36:56 +01:00
|
|
|
{
|
|
|
|
TRACE("()\n");
|
2013-11-02 14:34:13 +01:00
|
|
|
process_detaching = TRUE;
|
2013-07-19 12:13:09 +02:00
|
|
|
process_detach();
|
2003-03-04 05:36:56 +01:00
|
|
|
}
|
|
|
|
|
2013-07-19 12:15:15 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlExitUserProcess (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlExitUserProcess( DWORD status )
|
|
|
|
{
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
NtTerminateProcess( 0, status );
|
|
|
|
LdrShutdownProcess();
|
|
|
|
NtTerminateProcess( GetCurrentProcess(), status );
|
2019-05-14 21:02:50 +02:00
|
|
|
exit( get_unix_exit_code( status ));
|
2013-07-19 12:15:15 +02:00
|
|
|
}
|
|
|
|
|
2003-03-04 05:36:56 +01:00
|
|
|
/******************************************************************
|
|
|
|
* LdrShutdownThread (NTDLL.@)
|
|
|
|
*
|
|
|
|
*/
|
2003-05-08 06:13:26 +02:00
|
|
|
void WINAPI LdrShutdownThread(void)
|
2003-03-04 05:36:56 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
PLIST_ENTRY mark, entry;
|
|
|
|
PLDR_MODULE mod;
|
2013-12-23 12:27:39 +01:00
|
|
|
UINT i;
|
|
|
|
void **pointers;
|
2003-07-01 05:38:56 +02:00
|
|
|
|
2003-03-04 05:36:56 +01:00
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
/* don't do any detach calls if process is exiting */
|
2003-05-08 06:13:26 +02:00
|
|
|
if (process_detaching) return;
|
2003-03-04 05:36:56 +01:00
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
|
2003-07-01 05:38:56 +02:00
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InInitializationOrderModuleList;
|
|
|
|
for (entry = mark->Blink; entry != mark; entry = entry->Blink)
|
2003-03-04 05:36:56 +01:00
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
mod = CONTAINING_RECORD(entry, LDR_MODULE,
|
|
|
|
InInitializationOrderModuleList);
|
|
|
|
if ( !(mod->Flags & LDR_PROCESS_ATTACHED) )
|
2003-03-04 05:36:56 +01:00
|
|
|
continue;
|
2003-07-01 05:38:56 +02:00
|
|
|
if ( mod->Flags & LDR_NO_DLL_CALLS )
|
2003-03-04 05:36:56 +01:00
|
|
|
continue;
|
|
|
|
|
2003-07-01 05:38:56 +02:00
|
|
|
MODULE_InitDLL( CONTAINING_RECORD(mod, WINE_MODREF, ldr),
|
|
|
|
DLL_THREAD_DETACH, NULL );
|
2003-03-04 05:36:56 +01:00
|
|
|
}
|
|
|
|
|
2013-12-23 18:16:51 +01:00
|
|
|
RtlAcquirePebLock();
|
|
|
|
RemoveEntryList( &NtCurrentTeb()->TlsLinks );
|
|
|
|
RtlReleasePebLock();
|
|
|
|
|
2013-12-23 12:27:39 +01:00
|
|
|
if ((pointers = NtCurrentTeb()->ThreadLocalStoragePointer))
|
|
|
|
{
|
|
|
|
for (i = 0; i < tls_module_count; i++) RtlFreeHeap( GetProcessHeap(), 0, pointers[i] );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, pointers );
|
|
|
|
}
|
2013-12-23 18:16:51 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->FlsSlots );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->TlsExpansionSlots );
|
2003-03-04 05:36:56 +01:00
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
}
|
|
|
|
|
2006-03-18 18:41:21 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* free_modref
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void free_modref( WINE_MODREF *wm )
|
|
|
|
{
|
|
|
|
RemoveEntryList(&wm->ldr.InLoadOrderModuleList);
|
|
|
|
RemoveEntryList(&wm->ldr.InMemoryOrderModuleList);
|
|
|
|
if (wm->ldr.InInitializationOrderModuleList.Flink)
|
|
|
|
RemoveEntryList(&wm->ldr.InInitializationOrderModuleList);
|
|
|
|
|
|
|
|
TRACE(" unloading %s\n", debugstr_w(wm->ldr.FullDllName.Buffer));
|
|
|
|
if (!TRACE_ON(module))
|
|
|
|
TRACE_(loaddll)("Unloaded module %s : %s\n",
|
|
|
|
debugstr_w(wm->ldr.FullDllName.Buffer),
|
|
|
|
(wm->ldr.Flags & LDR_WINE_INTERNAL) ? "builtin" : "native" );
|
|
|
|
|
|
|
|
SERVER_START_REQ( unload_dll )
|
|
|
|
{
|
2008-12-29 16:47:51 +01:00
|
|
|
req->base = wine_server_client_ptr( wm->ldr.BaseAddress );
|
2006-03-18 18:41:21 +01:00
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2013-12-23 12:54:26 +01:00
|
|
|
free_tls_slot( &wm->ldr );
|
2007-07-25 16:50:32 +02:00
|
|
|
RtlReleaseActivationContext( wm->ldr.ActivationContext );
|
2020-04-16 12:00:43 +02:00
|
|
|
if (wm->so_handle) dlclose( wm->so_handle );
|
2014-10-04 02:51:51 +02:00
|
|
|
NtUnmapViewOfSection( NtCurrentProcess(), wm->ldr.BaseAddress );
|
2006-03-18 18:41:21 +01:00
|
|
|
if (cached_modref == wm) cached_modref = NULL;
|
|
|
|
RtlFreeUnicodeString( &wm->ldr.FullDllName );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, wm->deps );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, wm );
|
|
|
|
}
|
|
|
|
|
2003-03-14 05:00:52 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* MODULE_FlushModrefs
|
|
|
|
*
|
|
|
|
* Remove all unused modrefs and call the internal unloading routines
|
|
|
|
* for the library type.
|
2003-04-05 07:16:11 +02:00
|
|
|
*
|
|
|
|
* The loader_section must be locked while calling this function.
|
2003-03-14 05:00:52 +01:00
|
|
|
*/
|
|
|
|
static void MODULE_FlushModrefs(void)
|
|
|
|
{
|
2003-07-01 05:38:56 +02:00
|
|
|
PLIST_ENTRY mark, entry, prev;
|
|
|
|
PLDR_MODULE mod;
|
|
|
|
WINE_MODREF*wm;
|
2003-03-14 05:00:52 +01:00
|
|
|
|
2003-07-01 05:38:56 +02:00
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InInitializationOrderModuleList;
|
|
|
|
for (entry = mark->Blink; entry != mark; entry = prev)
|
2003-03-14 05:00:52 +01:00
|
|
|
{
|
2006-03-18 18:41:21 +01:00
|
|
|
mod = CONTAINING_RECORD(entry, LDR_MODULE, InInitializationOrderModuleList);
|
2003-07-01 05:38:56 +02:00
|
|
|
wm = CONTAINING_RECORD(mod, WINE_MODREF, ldr);
|
|
|
|
prev = entry->Blink;
|
2006-03-18 18:41:21 +01:00
|
|
|
if (!mod->LoadCount) free_modref( wm );
|
|
|
|
}
|
2003-03-14 05:00:52 +01:00
|
|
|
|
2006-03-18 18:41:21 +01:00
|
|
|
/* check load order list too for modules that haven't been initialized yet */
|
|
|
|
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
|
|
|
|
for (entry = mark->Blink; entry != mark; entry = prev)
|
|
|
|
{
|
|
|
|
mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
|
|
|
|
wm = CONTAINING_RECORD(mod, WINE_MODREF, ldr);
|
|
|
|
prev = entry->Blink;
|
|
|
|
if (!mod->LoadCount) free_modref( wm );
|
2003-03-14 05:00:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MODULE_DecRefCount
|
|
|
|
*
|
2003-04-05 07:16:11 +02:00
|
|
|
* The loader_section must be locked while calling this function.
|
2003-03-14 05:00:52 +01:00
|
|
|
*/
|
|
|
|
static void MODULE_DecRefCount( WINE_MODREF *wm )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2003-03-21 00:40:08 +01:00
|
|
|
if ( wm->ldr.Flags & LDR_UNLOAD_IN_PROGRESS )
|
2003-03-14 05:00:52 +01:00
|
|
|
return;
|
|
|
|
|
2003-03-20 23:05:26 +01:00
|
|
|
if ( wm->ldr.LoadCount <= 0 )
|
2003-03-14 05:00:52 +01:00
|
|
|
return;
|
|
|
|
|
2003-03-20 23:05:26 +01:00
|
|
|
--wm->ldr.LoadCount;
|
2003-09-29 22:42:24 +02:00
|
|
|
TRACE("(%s) ldr.LoadCount: %d\n", debugstr_w(wm->ldr.BaseDllName.Buffer), wm->ldr.LoadCount );
|
2003-03-14 05:00:52 +01:00
|
|
|
|
2003-03-20 23:05:26 +01:00
|
|
|
if ( wm->ldr.LoadCount == 0 )
|
2003-03-14 05:00:52 +01:00
|
|
|
{
|
2003-03-21 00:40:08 +01:00
|
|
|
wm->ldr.Flags |= LDR_UNLOAD_IN_PROGRESS;
|
2003-03-14 05:00:52 +01:00
|
|
|
|
|
|
|
for ( i = 0; i < wm->nDeps; i++ )
|
|
|
|
if ( wm->deps[i] )
|
|
|
|
MODULE_DecRefCount( wm->deps[i] );
|
|
|
|
|
2003-03-21 00:40:08 +01:00
|
|
|
wm->ldr.Flags &= ~LDR_UNLOAD_IN_PROGRESS;
|
2019-04-23 07:47:30 +02:00
|
|
|
|
|
|
|
module_push_unload_trace( &wm->ldr );
|
2003-03-14 05:00:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* LdrUnloadDll (NTDLL.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrUnloadDll( HMODULE hModule )
|
|
|
|
{
|
2013-07-19 12:13:09 +02:00
|
|
|
WINE_MODREF *wm;
|
2003-03-14 05:00:52 +01:00
|
|
|
NTSTATUS retv = STATUS_SUCCESS;
|
|
|
|
|
2013-07-19 12:13:09 +02:00
|
|
|
if (process_detaching) return retv;
|
|
|
|
|
2003-03-14 05:00:52 +01:00
|
|
|
TRACE("(%p)\n", hModule);
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
|
2013-07-19 12:13:09 +02:00
|
|
|
free_lib_count++;
|
|
|
|
if ((wm = get_modref( hModule )) != NULL)
|
2003-03-14 05:00:52 +01:00
|
|
|
{
|
2013-07-19 12:13:09 +02:00
|
|
|
TRACE("(%s) - START\n", debugstr_w(wm->ldr.BaseDllName.Buffer));
|
2003-03-14 05:00:52 +01:00
|
|
|
|
2013-07-19 12:13:09 +02:00
|
|
|
/* Recursively decrement reference counts */
|
|
|
|
MODULE_DecRefCount( wm );
|
2003-03-14 05:00:52 +01:00
|
|
|
|
2013-07-19 12:13:09 +02:00
|
|
|
/* Call process detach notifications */
|
|
|
|
if ( free_lib_count <= 1 )
|
|
|
|
{
|
|
|
|
process_detach();
|
|
|
|
MODULE_FlushModrefs();
|
2003-03-14 05:00:52 +01:00
|
|
|
}
|
|
|
|
|
2013-07-19 12:13:09 +02:00
|
|
|
TRACE("END\n");
|
2003-03-14 05:00:52 +01:00
|
|
|
}
|
2013-07-19 12:13:09 +02:00
|
|
|
else
|
|
|
|
retv = STATUS_DLL_NOT_FOUND;
|
|
|
|
|
|
|
|
free_lib_count--;
|
2003-03-14 05:00:52 +01:00
|
|
|
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
2002-08-09 21:57:38 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlImageNtHeader (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE hModule)
|
|
|
|
{
|
2002-08-16 00:09:53 +02:00
|
|
|
IMAGE_NT_HEADERS *ret;
|
2002-08-09 21:57:38 +02:00
|
|
|
|
2002-08-16 00:09:53 +02:00
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *)hModule;
|
|
|
|
|
|
|
|
ret = NULL;
|
|
|
|
if (dos->e_magic == IMAGE_DOS_SIGNATURE)
|
|
|
|
{
|
|
|
|
ret = (IMAGE_NT_HEADERS *)((char *)dos + dos->e_lfanew);
|
|
|
|
if (ret->Signature != IMAGE_NT_SIGNATURE) ret = NULL;
|
|
|
|
}
|
|
|
|
}
|
2005-12-16 17:17:57 +01:00
|
|
|
__EXCEPT_PAGE_FAULT
|
2002-08-09 21:57:38 +02:00
|
|
|
{
|
2002-08-16 00:09:53 +02:00
|
|
|
return NULL;
|
2002-08-09 21:57:38 +02:00
|
|
|
}
|
2002-08-16 00:09:53 +02:00
|
|
|
__ENDTRY
|
2002-08-09 21:57:38 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 16:49:09 +01:00
|
|
|
/******************************************************************
|
|
|
|
* LdrInitializeThunk (NTDLL.@)
|
2008-03-26 17:08:38 +01:00
|
|
|
*
|
2017-11-20 17:09:29 +01:00
|
|
|
* Attach to all the loaded dlls.
|
|
|
|
* If this is the first time, perform the full process initialization.
|
2008-03-26 17:08:38 +01:00
|
|
|
*/
|
2019-02-14 16:49:09 +01:00
|
|
|
void WINAPI LdrInitializeThunk( CONTEXT *context, void **entry, ULONG_PTR unknown3, ULONG_PTR unknown4 )
|
2008-03-26 17:08:38 +01:00
|
|
|
{
|
2019-09-20 01:36:04 +02:00
|
|
|
static const LARGE_INTEGER zero;
|
2020-04-14 12:55:38 +02:00
|
|
|
static int attach_done;
|
|
|
|
int i;
|
2008-03-26 17:08:38 +01:00
|
|
|
NTSTATUS status;
|
2020-04-14 12:55:38 +02:00
|
|
|
ULONG_PTR cookie;
|
2017-11-20 17:09:29 +01:00
|
|
|
WINE_MODREF *wm;
|
|
|
|
LPCWSTR load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer;
|
2008-03-26 17:08:38 +01:00
|
|
|
|
2009-02-20 11:15:06 +01:00
|
|
|
pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL );
|
2008-05-20 10:59:20 +02:00
|
|
|
|
2019-02-14 16:49:09 +01:00
|
|
|
if (process_detaching) return;
|
2017-11-20 17:09:29 +01:00
|
|
|
|
2008-03-26 17:08:38 +01:00
|
|
|
RtlEnterCriticalSection( &loader_section );
|
2017-11-20 17:09:29 +01:00
|
|
|
|
|
|
|
wm = get_modref( NtCurrentTeb()->Peb->ImageBaseAddress );
|
|
|
|
assert( wm );
|
|
|
|
|
|
|
|
if (!imports_fixup_done)
|
2008-03-26 17:08:38 +01:00
|
|
|
{
|
2017-11-20 17:09:29 +01:00
|
|
|
actctx_init();
|
2018-02-21 09:55:05 +01:00
|
|
|
if (wm->ldr.Flags & LDR_COR_ILONLY)
|
|
|
|
status = fixup_imports_ilonly( wm, load_path, entry );
|
|
|
|
else
|
|
|
|
status = fixup_imports( wm, load_path );
|
|
|
|
|
|
|
|
if (status)
|
2017-11-30 16:00:14 +01:00
|
|
|
{
|
|
|
|
ERR( "Importing dlls for %s failed, status %x\n",
|
|
|
|
debugstr_w(NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer), status );
|
|
|
|
NtTerminateProcess( GetCurrentProcess(), status );
|
|
|
|
}
|
2017-11-20 17:09:29 +01:00
|
|
|
imports_fixup_done = TRUE;
|
2008-03-26 17:08:38 +01:00
|
|
|
}
|
2017-11-20 17:09:29 +01:00
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
InsertHeadList( &tls_links, &NtCurrentTeb()->TlsLinks );
|
|
|
|
RtlReleasePebLock();
|
|
|
|
|
2020-04-14 12:55:38 +02:00
|
|
|
if (!attach_done) /* first time around */
|
2017-11-20 17:09:29 +01:00
|
|
|
{
|
2020-04-14 12:55:38 +02:00
|
|
|
attach_done = 1;
|
2017-11-30 16:00:14 +01:00
|
|
|
if ((status = alloc_thread_tls()) != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR( "TLS init failed when loading %s, status %x\n",
|
|
|
|
debugstr_w(NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer), status );
|
|
|
|
NtTerminateProcess( GetCurrentProcess(), status );
|
|
|
|
}
|
2020-04-14 12:55:38 +02:00
|
|
|
wm->ldr.LoadCount = -1;
|
2020-04-21 11:23:15 +02:00
|
|
|
wm->ldr.Flags |= LDR_PROCESS_ATTACHED; /* don't try to attach again */
|
2020-04-14 12:55:38 +02:00
|
|
|
if (wm->ldr.ActivationContext)
|
|
|
|
RtlActivateActivationContext( 0, wm->ldr.ActivationContext, &cookie );
|
|
|
|
|
|
|
|
for (i = 0; i < wm->nDeps; i++)
|
2017-11-20 17:09:29 +01:00
|
|
|
{
|
2020-04-14 12:55:38 +02:00
|
|
|
if (!wm->deps[i]) continue;
|
|
|
|
if ((status = process_attach( wm->deps[i], context )) != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (last_failed_modref)
|
|
|
|
ERR( "%s failed to initialize, aborting\n",
|
|
|
|
debugstr_w(last_failed_modref->ldr.BaseDllName.Buffer) + 1 );
|
|
|
|
ERR( "Initializing dlls for %s failed, status %x\n",
|
|
|
|
debugstr_w(NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer), status );
|
|
|
|
NtTerminateProcess( GetCurrentProcess(), status );
|
|
|
|
}
|
2017-11-20 17:09:29 +01:00
|
|
|
}
|
2017-12-01 20:31:21 +01:00
|
|
|
attach_implicitly_loaded_dlls( context );
|
2017-11-29 17:11:10 +01:00
|
|
|
virtual_release_address_space();
|
2020-04-16 12:22:24 +02:00
|
|
|
if (wm->so_handle) call_constructors( wm );
|
2020-04-14 12:55:38 +02:00
|
|
|
if (wm->ldr.ActivationContext) RtlDeactivateActivationContext( 0, cookie );
|
2017-11-20 17:09:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-30 16:00:14 +01:00
|
|
|
if ((status = alloc_thread_tls()) != STATUS_SUCCESS)
|
|
|
|
NtTerminateThread( GetCurrentThread(), status );
|
2017-11-20 17:09:29 +01:00
|
|
|
thread_attach();
|
|
|
|
}
|
|
|
|
|
2008-03-26 17:08:38 +01:00
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
2019-09-20 01:36:04 +02:00
|
|
|
|
|
|
|
NtDelayExecution( TRUE, &zero );
|
2008-03-26 17:08:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-20 17:30:00 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* load_global_options
|
|
|
|
*/
|
|
|
|
static void load_global_options(void)
|
|
|
|
{
|
|
|
|
static const WCHAR sessionW[] = {'M','a','c','h','i','n','e','\\',
|
|
|
|
'S','y','s','t','e','m','\\',
|
|
|
|
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
|
|
|
'C','o','n','t','r','o','l','\\',
|
|
|
|
'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
|
|
|
|
static const WCHAR globalflagW[] = {'G','l','o','b','a','l','F','l','a','g',0};
|
2019-10-01 09:32:46 +02:00
|
|
|
static const WCHAR safesearchW[] = {'S','a','f','e','P','r','o','c','e','s','s','S','e','a','r','c','h','M','o','d','e',0};
|
2019-10-03 14:14:36 +02:00
|
|
|
static const WCHAR safedllmodeW[] = {'S','a','f','e','D','l','l','S','e','a','r','c','h','M','o','d','e',0};
|
2010-01-20 17:30:00 +01:00
|
|
|
static const WCHAR critsectW[] = {'C','r','i','t','i','c','a','l','S','e','c','t','i','o','n','T','i','m','e','o','u','t',0};
|
|
|
|
static const WCHAR heapresW[] = {'H','e','a','p','S','e','g','m','e','n','t','R','e','s','e','r','v','e',0};
|
|
|
|
static const WCHAR heapcommitW[] = {'H','e','a','p','S','e','g','m','e','n','t','C','o','m','m','i','t',0};
|
|
|
|
static const WCHAR decommittotalW[] = {'H','e','a','p','D','e','C','o','m','m','i','t','T','o','t','a','l','F','r','e','e','T','h','r','e','s','h','o','l','d',0};
|
|
|
|
static const WCHAR decommitfreeW[] = {'H','e','a','p','D','e','C','o','m','m','i','t','F','r','e','e','B','l','o','c','k','T','h','r','e','s','h','o','l','d',0};
|
|
|
|
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING name_str;
|
|
|
|
HANDLE hkey;
|
|
|
|
ULONG value;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &name_str;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &name_str, sessionW );
|
|
|
|
|
2019-11-07 16:54:31 +01:00
|
|
|
if (!NtOpenKey( &hkey, KEY_QUERY_VALUE, &attr ))
|
|
|
|
{
|
|
|
|
query_dword_option( hkey, globalflagW, &NtCurrentTeb()->Peb->NtGlobalFlag );
|
|
|
|
query_dword_option( hkey, safesearchW, &path_safe_mode );
|
|
|
|
query_dword_option( hkey, safedllmodeW, &dll_safe_mode );
|
2010-01-20 17:30:00 +01:00
|
|
|
|
2019-11-07 16:54:31 +01:00
|
|
|
if (!query_dword_option( hkey, critsectW, &value ))
|
|
|
|
NtCurrentTeb()->Peb->CriticalSectionTimeout.QuadPart = (ULONGLONG)value * -10000000;
|
2010-01-20 17:30:00 +01:00
|
|
|
|
2019-11-07 16:54:31 +01:00
|
|
|
if (!query_dword_option( hkey, heapresW, &value ))
|
|
|
|
NtCurrentTeb()->Peb->HeapSegmentReserve = value;
|
2010-01-20 17:30:00 +01:00
|
|
|
|
2019-11-07 16:54:31 +01:00
|
|
|
if (!query_dword_option( hkey, heapcommitW, &value ))
|
|
|
|
NtCurrentTeb()->Peb->HeapSegmentCommit = value;
|
2010-01-20 17:30:00 +01:00
|
|
|
|
2019-11-07 16:54:31 +01:00
|
|
|
if (!query_dword_option( hkey, decommittotalW, &value ))
|
|
|
|
NtCurrentTeb()->Peb->HeapDeCommitTotalFreeThreshold = value;
|
2010-01-20 17:30:00 +01:00
|
|
|
|
2019-11-07 16:54:31 +01:00
|
|
|
if (!query_dword_option( hkey, decommitfreeW, &value ))
|
|
|
|
NtCurrentTeb()->Peb->HeapDeCommitFreeBlockThreshold = value;
|
2010-01-20 17:30:00 +01:00
|
|
|
|
2019-11-07 16:54:31 +01:00
|
|
|
NtClose( hkey );
|
|
|
|
}
|
|
|
|
LdrQueryImageFileExecutionOptions( &NtCurrentTeb()->Peb->ProcessParameters->ImagePathName,
|
|
|
|
globalflagW, REG_DWORD, &NtCurrentTeb()->Peb->NtGlobalFlag,
|
|
|
|
sizeof(DWORD), NULL );
|
|
|
|
heap_set_debug_flags( GetProcessHeap() );
|
2010-01-20 17:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-09 21:57:38 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlImageDirectoryEntryToData (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PVOID WINAPI RtlImageDirectoryEntryToData( HMODULE module, BOOL image, WORD dir, ULONG *size )
|
|
|
|
{
|
|
|
|
const IMAGE_NT_HEADERS *nt;
|
|
|
|
DWORD addr;
|
|
|
|
|
2018-03-06 16:08:10 +01:00
|
|
|
if ((ULONG_PTR)module & 1) image = FALSE; /* mapped as data file */
|
|
|
|
module = (HMODULE)((ULONG_PTR)module & ~3);
|
2002-08-09 21:57:38 +02:00
|
|
|
if (!(nt = RtlImageNtHeader( module ))) return NULL;
|
2009-09-25 12:46:39 +02:00
|
|
|
if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
|
|
|
|
{
|
2010-03-27 16:41:14 +01:00
|
|
|
const IMAGE_NT_HEADERS64 *nt64 = (const IMAGE_NT_HEADERS64 *)nt;
|
2009-09-25 12:46:39 +02:00
|
|
|
|
|
|
|
if (dir >= nt64->OptionalHeader.NumberOfRvaAndSizes) return NULL;
|
|
|
|
if (!(addr = nt64->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL;
|
|
|
|
*size = nt64->OptionalHeader.DataDirectory[dir].Size;
|
|
|
|
if (image || addr < nt64->OptionalHeader.SizeOfHeaders) return (char *)module + addr;
|
|
|
|
}
|
|
|
|
else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
|
|
|
{
|
2010-03-27 16:41:14 +01:00
|
|
|
const IMAGE_NT_HEADERS32 *nt32 = (const IMAGE_NT_HEADERS32 *)nt;
|
2009-09-25 12:46:39 +02:00
|
|
|
|
|
|
|
if (dir >= nt32->OptionalHeader.NumberOfRvaAndSizes) return NULL;
|
|
|
|
if (!(addr = nt32->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL;
|
|
|
|
*size = nt32->OptionalHeader.DataDirectory[dir].Size;
|
|
|
|
if (image || addr < nt32->OptionalHeader.SizeOfHeaders) return (char *)module + addr;
|
|
|
|
}
|
|
|
|
else return NULL;
|
2002-08-09 21:57:38 +02:00
|
|
|
|
|
|
|
/* not mapped as image, need to find the section containing the virtual address */
|
|
|
|
return RtlImageRvaToVa( nt, module, addr, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlImageRvaToSection (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PIMAGE_SECTION_HEADER WINAPI RtlImageRvaToSection( const IMAGE_NT_HEADERS *nt,
|
|
|
|
HMODULE module, DWORD rva )
|
|
|
|
{
|
|
|
|
int i;
|
2004-06-15 02:47:00 +02:00
|
|
|
const IMAGE_SECTION_HEADER *sec;
|
|
|
|
|
|
|
|
sec = (const IMAGE_SECTION_HEADER*)((const char*)&nt->OptionalHeader +
|
|
|
|
nt->FileHeader.SizeOfOptionalHeader);
|
2002-08-09 21:57:38 +02:00
|
|
|
for (i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++)
|
|
|
|
{
|
|
|
|
if ((sec->VirtualAddress <= rva) && (sec->VirtualAddress + sec->SizeOfRawData > rva))
|
2004-06-15 02:47:00 +02:00
|
|
|
return (PIMAGE_SECTION_HEADER)sec;
|
2002-08-09 21:57:38 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlImageRvaToVa (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PVOID WINAPI RtlImageRvaToVa( const IMAGE_NT_HEADERS *nt, HMODULE module,
|
|
|
|
DWORD rva, IMAGE_SECTION_HEADER **section )
|
|
|
|
{
|
|
|
|
IMAGE_SECTION_HEADER *sec;
|
|
|
|
|
|
|
|
if (section && *section) /* try this section first */
|
|
|
|
{
|
|
|
|
sec = *section;
|
|
|
|
if ((sec->VirtualAddress <= rva) && (sec->VirtualAddress + sec->SizeOfRawData > rva))
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
if (!(sec = RtlImageRvaToSection( nt, module, rva ))) return NULL;
|
|
|
|
found:
|
|
|
|
if (section) *section = sec;
|
|
|
|
return (char *)module + sec->PointerToRawData + (rva - sec->VirtualAddress);
|
|
|
|
}
|
2003-09-19 06:04:57 +02:00
|
|
|
|
|
|
|
|
2006-05-27 10:55:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlPcToFileHeader (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PVOID WINAPI RtlPcToFileHeader( PVOID pc, PVOID *address )
|
|
|
|
{
|
|
|
|
LDR_MODULE *module;
|
|
|
|
PVOID ret = NULL;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &loader_section );
|
|
|
|
if (!LdrFindEntryForAddress( pc, &module )) ret = module->BaseAddress;
|
|
|
|
RtlLeaveCriticalSection( &loader_section );
|
|
|
|
*address = ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-01 13:59:51 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* LdrGetDllDirectory (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrGetDllDirectory( UNICODE_STRING *dir )
|
|
|
|
{
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dlldir_section );
|
|
|
|
dir->Length = dll_directory.Length + sizeof(WCHAR);
|
|
|
|
if (dir->MaximumLength >= dir->Length) RtlCopyUnicodeString( dir, &dll_directory );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
if (dir->MaximumLength) dir->Buffer[0] = 0;
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &dlldir_section );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* LdrSetDllDirectory (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrSetDllDirectory( const UNICODE_STRING *dir )
|
|
|
|
{
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
UNICODE_STRING new;
|
|
|
|
|
|
|
|
if (!dir->Buffer) RtlInitUnicodeString( &new, NULL );
|
|
|
|
else if ((status = RtlDuplicateUnicodeString( 1, dir, &new ))) return status;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dlldir_section );
|
|
|
|
RtlFreeUnicodeString( &dll_directory );
|
|
|
|
dll_directory = new;
|
|
|
|
RtlLeaveCriticalSection( &dlldir_section );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-03 14:14:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* LdrAddDllDirectory (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrAddDllDirectory( const UNICODE_STRING *dir, void **cookie )
|
|
|
|
{
|
|
|
|
FILE_BASIC_INFORMATION info;
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
NTSTATUS status;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
DWORD len;
|
|
|
|
struct dll_dir_entry *ptr;
|
|
|
|
DOS_PATHNAME_TYPE type = RtlDetermineDosPathNameType_U( dir->Buffer );
|
|
|
|
|
|
|
|
if (type != ABSOLUTE_PATH && type != ABSOLUTE_DRIVE_PATH)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
status = RtlDosPathNameToNtPathName_U_WithStatus( dir->Buffer, &nt_name, NULL, NULL );
|
|
|
|
if (status) return status;
|
|
|
|
len = nt_name.Length / sizeof(WCHAR);
|
|
|
|
if (!(ptr = RtlAllocateHeap( GetProcessHeap(), 0, offsetof(struct dll_dir_entry, dir[++len] ))))
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
memcpy( ptr->dir, nt_name.Buffer, len * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &nt_name;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
status = NtQueryAttributesFile( &attr, &info );
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
TRACE( "%s\n", debugstr_w( ptr->dir ));
|
|
|
|
RtlEnterCriticalSection( &dlldir_section );
|
|
|
|
list_add_head( &dll_dir_list, &ptr->entry );
|
|
|
|
RtlLeaveCriticalSection( &dlldir_section );
|
|
|
|
*cookie = ptr;
|
|
|
|
}
|
|
|
|
else RtlFreeHeap( GetProcessHeap(), 0, ptr );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* LdrRemoveDllDirectory (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrRemoveDllDirectory( void *cookie )
|
|
|
|
{
|
|
|
|
struct dll_dir_entry *ptr = cookie;
|
|
|
|
|
|
|
|
TRACE( "%s\n", debugstr_w( ptr->dir ));
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dlldir_section );
|
|
|
|
list_remove( &ptr->entry );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, ptr );
|
|
|
|
RtlLeaveCriticalSection( &dlldir_section );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* LdrSetDefaultDllDirectories (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrSetDefaultDllDirectories( ULONG flags )
|
|
|
|
{
|
|
|
|
/* LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR doesn't make sense in default dirs */
|
|
|
|
const ULONG load_library_search_flags = (LOAD_LIBRARY_SEARCH_APPLICATION_DIR |
|
|
|
|
LOAD_LIBRARY_SEARCH_USER_DIRS |
|
|
|
|
LOAD_LIBRARY_SEARCH_SYSTEM32 |
|
|
|
|
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
|
|
|
|
|
|
|
|
if (!flags || (flags & ~load_library_search_flags)) return STATUS_INVALID_PARAMETER;
|
|
|
|
default_search_flags = flags;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* LdrGetDllPath (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI LdrGetDllPath( PCWSTR module, ULONG flags, PWSTR *path, PWSTR *unknown )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
const ULONG load_library_search_flags = (LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
|
|
|
|
LOAD_LIBRARY_SEARCH_APPLICATION_DIR |
|
|
|
|
LOAD_LIBRARY_SEARCH_USER_DIRS |
|
|
|
|
LOAD_LIBRARY_SEARCH_SYSTEM32 |
|
|
|
|
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
|
|
|
|
|
|
|
|
if (flags & LOAD_WITH_ALTERED_SEARCH_PATH)
|
|
|
|
{
|
|
|
|
if (flags & load_library_search_flags) return STATUS_INVALID_PARAMETER;
|
|
|
|
if (default_search_flags) flags |= default_search_flags | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
|
|
|
|
}
|
|
|
|
else if (!(flags & load_library_search_flags)) flags |= default_search_flags;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &dlldir_section );
|
|
|
|
|
|
|
|
if (flags & load_library_search_flags)
|
|
|
|
{
|
|
|
|
status = get_dll_load_path_search_flags( module, flags, path );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const WCHAR *dlldir = dll_directory.Length ? dll_directory.Buffer : NULL;
|
|
|
|
if (!(flags & LOAD_WITH_ALTERED_SEARCH_PATH))
|
|
|
|
module = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
|
|
|
|
status = get_dll_load_path( module, dlldir, dll_safe_mode, path );
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlLeaveCriticalSection( &dlldir_section );
|
|
|
|
*unknown = NULL;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-01 09:32:46 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* RtlSetSearchPathMode (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlSetSearchPathMode( ULONG flags )
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
switch (flags)
|
|
|
|
{
|
|
|
|
case BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE:
|
|
|
|
val = 1;
|
|
|
|
break;
|
|
|
|
case BASE_SEARCH_PATH_DISABLE_SAFE_SEARCHMODE:
|
|
|
|
val = 0;
|
|
|
|
break;
|
|
|
|
case BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT:
|
|
|
|
interlocked_xchg( (int *)&path_safe_mode, 2 );
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
default:
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int prev = path_safe_mode;
|
|
|
|
if (prev == 2) break; /* permanently set */
|
|
|
|
if (interlocked_cmpxchg( (int *)&path_safe_mode, val, prev ) == prev) return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-03 19:26:01 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlGetExePath (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlGetExePath( PCWSTR name, PWSTR *path )
|
|
|
|
{
|
|
|
|
static const WCHAR emptyW[1];
|
|
|
|
const WCHAR *dlldir = dotW;
|
|
|
|
const WCHAR *module = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
|
|
|
|
|
|
|
|
/* same check as NeedCurrentDirectoryForExePathW */
|
2020-03-31 11:43:50 +02:00
|
|
|
if (!wcschr( name, '\\' ))
|
2019-10-03 19:26:01 +02:00
|
|
|
{
|
|
|
|
static const WCHAR env_name[] = {'N','o','D','e','f','a','u','l','t','C','u','r','r','e','n','t',
|
|
|
|
'D','i','r','e','c','t','o','r','y','I','n',
|
|
|
|
'E','x','e','P','a','t','h',0};
|
|
|
|
UNICODE_STRING name, value = { 0 };
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &name, env_name );
|
|
|
|
if (RtlQueryEnvironmentVariable_U( NULL, &name, &value ) != STATUS_VARIABLE_NOT_FOUND)
|
|
|
|
dlldir = emptyW;
|
|
|
|
}
|
|
|
|
return get_dll_load_path( module, dlldir, FALSE, path );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-01 09:33:52 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlGetSearchPath (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlGetSearchPath( PWSTR *path )
|
|
|
|
{
|
2019-10-03 14:14:36 +02:00
|
|
|
const WCHAR *module = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
|
|
|
|
return get_dll_load_path( module, NULL, path_safe_mode, path );
|
2019-10-01 09:33:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlReleasePath (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlReleasePath( PWSTR path )
|
|
|
|
{
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, path );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-24 13:49:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* NtLoadDriver (NTDLL.@)
|
|
|
|
* ZwLoadDriver (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtLoadDriver( const UNICODE_STRING *DriverServiceName )
|
|
|
|
{
|
|
|
|
FIXME("(%p), stub!\n",DriverServiceName);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NtUnloadDriver (NTDLL.@)
|
|
|
|
* ZwUnloadDriver (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtUnloadDriver( const UNICODE_STRING *DriverServiceName )
|
|
|
|
{
|
|
|
|
FIXME("(%p), stub!\n",DriverServiceName);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-29 17:11:37 +02:00
|
|
|
/******************************************************************
|
|
|
|
* DllMain (NTDLL.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
|
|
|
|
{
|
|
|
|
if (reason == DLL_PROCESS_ATTACH) LdrDisableThreadCalloutsForDll( inst );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-19 06:04:57 +02:00
|
|
|
/***********************************************************************
|
2003-10-10 02:12:17 +02:00
|
|
|
* __wine_process_init
|
2003-09-19 06:04:57 +02:00
|
|
|
*/
|
2006-04-03 12:07:20 +02:00
|
|
|
void __wine_process_init(void)
|
2003-09-19 06:04:57 +02:00
|
|
|
{
|
2020-04-21 11:27:11 +02:00
|
|
|
extern IMAGE_NT_HEADERS __wine_spec_nt_header;
|
2020-04-14 21:58:56 +02:00
|
|
|
static const WCHAR ntdllW[] = {'\\','?','?','\\','C',':','\\','w','i','n','d','o','w','s','\\',
|
|
|
|
's','y','s','t','e','m','3','2','\\',
|
|
|
|
'n','t','d','l','l','.','d','l','l',0};
|
2019-06-05 17:54:09 +02:00
|
|
|
static const WCHAR kernel32W[] = {'\\','?','?','\\','C',':','\\','w','i','n','d','o','w','s','\\',
|
2019-04-22 11:36:54 +02:00
|
|
|
's','y','s','t','e','m','3','2','\\',
|
|
|
|
'k','e','r','n','e','l','3','2','.','d','l','l',0};
|
2019-11-07 18:54:21 +01:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params;
|
2003-10-10 02:12:17 +02:00
|
|
|
WINE_MODREF *wm;
|
|
|
|
NTSTATUS status;
|
|
|
|
ANSI_STRING func_name;
|
2019-02-08 12:49:47 +01:00
|
|
|
UNICODE_STRING nt_name;
|
2020-04-21 11:27:11 +02:00
|
|
|
HMODULE ntdll_module;
|
2019-06-14 17:32:43 +02:00
|
|
|
INITIAL_TEB stack;
|
2019-11-07 17:00:39 +01:00
|
|
|
BOOL suspend;
|
|
|
|
SIZE_T info_size;
|
|
|
|
TEB *teb = thread_init();
|
|
|
|
PEB *peb = teb->Peb;
|
2003-10-10 02:12:17 +02:00
|
|
|
|
2019-11-07 17:00:39 +01:00
|
|
|
/* setup the server connection */
|
|
|
|
server_init_process();
|
|
|
|
info_size = server_init_thread( peb, &suspend );
|
|
|
|
|
|
|
|
peb->ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL );
|
|
|
|
peb->LoaderLock = &loader_section;
|
|
|
|
|
2019-11-13 20:55:03 +01:00
|
|
|
init_unix_codepage();
|
2019-11-07 17:00:39 +01:00
|
|
|
init_directories();
|
|
|
|
init_user_process_params( info_size );
|
2020-04-21 11:27:11 +02:00
|
|
|
params = peb->ProcessParameters;
|
2019-11-07 17:00:39 +01:00
|
|
|
|
|
|
|
NtCreateKeyedEvent( &keyed_event, GENERIC_READ | GENERIC_WRITE, NULL, 0 );
|
2003-10-10 02:12:17 +02:00
|
|
|
|
2004-04-20 02:36:29 +02:00
|
|
|
/* retrieve current umask */
|
|
|
|
FILE_umask = umask(0777);
|
|
|
|
umask( FILE_umask );
|
|
|
|
|
2010-01-20 17:30:00 +01:00
|
|
|
load_global_options();
|
2019-11-07 16:54:31 +01:00
|
|
|
version_init();
|
2010-01-20 17:30:00 +01:00
|
|
|
|
2003-10-10 02:12:17 +02:00
|
|
|
/* setup the load callback and create ntdll modref */
|
2020-04-14 21:58:56 +02:00
|
|
|
RtlInitUnicodeString( &nt_name, ntdllW );
|
|
|
|
default_load_info.filename = &nt_name;
|
2003-09-19 06:04:57 +02:00
|
|
|
wine_dll_set_callback( load_builtin_callback );
|
2020-04-21 11:27:11 +02:00
|
|
|
ntdll_module = (HMODULE)((__wine_spec_nt_header.OptionalHeader.ImageBase + 0xffff) & ~0xffff);
|
|
|
|
if (!get_modref( ntdll_module ))
|
|
|
|
{
|
|
|
|
map_so_dll( &__wine_spec_nt_header, ntdll_module );
|
|
|
|
status = build_so_dll_module( params->DllPath.Buffer, &nt_name, ntdll_module, 0, &wm );
|
|
|
|
assert( !status );
|
|
|
|
}
|
2003-10-10 02:12:17 +02:00
|
|
|
|
2019-02-08 12:49:47 +01:00
|
|
|
RtlInitUnicodeString( &nt_name, kernel32W );
|
2020-04-21 11:27:11 +02:00
|
|
|
if ((status = load_builtin_dll( params->DllPath.Buffer, &nt_name, NULL, 0, &wm )) != STATUS_SUCCESS)
|
2003-10-10 02:12:17 +02:00
|
|
|
{
|
2006-10-16 13:49:06 +02:00
|
|
|
MESSAGE( "wine: could not load kernel32.dll, status %x\n", status );
|
2003-10-10 02:12:17 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2019-12-10 11:08:40 +01:00
|
|
|
RtlInitAnsiString( &func_name, "__wine_start_process" );
|
2003-10-10 02:12:17 +02:00
|
|
|
if ((status = LdrGetProcedureAddress( wm->ldr.BaseAddress, &func_name,
|
2019-12-10 11:08:40 +01:00
|
|
|
0, (void **)&kernel32_start_process )) != STATUS_SUCCESS)
|
2003-10-10 02:12:17 +02:00
|
|
|
{
|
2019-12-10 11:08:40 +01:00
|
|
|
MESSAGE( "wine: could not find __wine_start_process in kernel32.dll, status %x\n", status );
|
2003-10-10 02:12:17 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2019-02-14 16:45:03 +01:00
|
|
|
|
2019-11-19 10:08:27 +01:00
|
|
|
init_locale( wm->ldr.BaseAddress );
|
|
|
|
|
2019-11-07 18:54:21 +01:00
|
|
|
if (!(status = load_dll( params->DllPath.Buffer, params->ImagePathName.Buffer, NULL,
|
|
|
|
DONT_RESOLVE_DLL_REFERENCES, &wm )))
|
|
|
|
{
|
|
|
|
peb->ImageBaseAddress = wm->ldr.BaseAddress;
|
|
|
|
TRACE( "main exe loaded %s at %p\n", debugstr_us(¶ms->ImagePathName), peb->ImageBaseAddress );
|
2019-11-11 21:04:27 +01:00
|
|
|
if (wm->ldr.Flags & LDR_IMAGE_IS_DLL)
|
|
|
|
{
|
|
|
|
MESSAGE( "wine: %s is a dll, not an executable\n", debugstr_w(wm->ldr.FullDllName.Buffer) );
|
|
|
|
NtTerminateProcess( GetCurrentProcess(), STATUS_INVALID_IMAGE_FORMAT );
|
|
|
|
}
|
2019-11-07 18:54:21 +01:00
|
|
|
}
|
2019-11-11 21:04:27 +01:00
|
|
|
else
|
2019-11-07 18:54:21 +01:00
|
|
|
{
|
2019-11-11 21:04:27 +01:00
|
|
|
if (!info_size) status = restart_process( params, status );
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case STATUS_INVALID_IMAGE_WIN_64:
|
|
|
|
ERR( "%s 64-bit application not supported in 32-bit prefix\n",
|
|
|
|
debugstr_us(¶ms->ImagePathName) );
|
|
|
|
break;
|
|
|
|
case STATUS_INVALID_IMAGE_WIN_16:
|
|
|
|
case STATUS_INVALID_IMAGE_NE_FORMAT:
|
|
|
|
case STATUS_INVALID_IMAGE_PROTECT:
|
|
|
|
ERR( "%s 16-bit application not supported on this system\n",
|
|
|
|
debugstr_us(¶ms->ImagePathName) );
|
|
|
|
break;
|
|
|
|
case STATUS_INVALID_IMAGE_FORMAT:
|
|
|
|
ERR( "%s not supported on this system\n", debugstr_us(¶ms->ImagePathName) );
|
|
|
|
break;
|
|
|
|
case STATUS_DLL_NOT_FOUND:
|
|
|
|
ERR( "%s not found\n", debugstr_us(¶ms->ImagePathName) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR( "failed to load %s, error %x\n", debugstr_us(¶ms->ImagePathName), status );
|
|
|
|
break;
|
|
|
|
}
|
2019-11-07 18:54:21 +01:00
|
|
|
NtTerminateProcess( GetCurrentProcess(), status );
|
|
|
|
}
|
|
|
|
|
2019-02-14 16:49:09 +01:00
|
|
|
virtual_set_large_address_space();
|
|
|
|
|
|
|
|
/* the main exe needs to be the first in the load order list */
|
|
|
|
RemoveEntryList( &wm->ldr.InLoadOrderModuleList );
|
2019-11-07 17:00:39 +01:00
|
|
|
InsertHeadList( &peb->LdrData->InLoadOrderModuleList, &wm->ldr.InLoadOrderModuleList );
|
2019-02-14 16:49:09 +01:00
|
|
|
RemoveEntryList( &wm->ldr.InMemoryOrderModuleList );
|
2019-11-07 17:00:39 +01:00
|
|
|
InsertHeadList( &peb->LdrData->InMemoryOrderModuleList, &wm->ldr.InMemoryOrderModuleList );
|
2019-02-14 16:49:09 +01:00
|
|
|
|
2019-11-07 17:00:39 +01:00
|
|
|
virtual_alloc_thread_stack( &stack, 0, 0, NULL );
|
|
|
|
teb->Tib.StackBase = stack.StackBase;
|
|
|
|
teb->Tib.StackLimit = stack.StackLimit;
|
|
|
|
teb->DeallocationStack = stack.DeallocationStack;
|
2019-06-14 17:32:43 +02:00
|
|
|
|
2019-02-14 16:49:09 +01:00
|
|
|
server_init_process_done();
|
2003-09-19 06:04:57 +02:00
|
|
|
}
|