Commit 9f58ee70 authored by Alexandre Julliard's avatar Alexandre Julliard

Set the system directory in ntdll as soon as we have determined it.

parent 9f1b8197
......@@ -790,10 +790,12 @@ done:
*/
static void init_windows_dirs(void)
{
extern void __wine_init_windows_dir( const WCHAR *windir, const WCHAR *sysdir );
static const WCHAR windirW[] = {'w','i','n','d','i','r',0};
static const WCHAR winsysdirW[] = {'w','i','n','s','y','s','d','i','r',0};
static const WCHAR default_windirW[] = {'c',':','\\','w','i','n','d','o','w','s',0};
static const WCHAR default_sysdirW[] = {'c',':','\\','w','i','n','d','o','w','s','\\','s','y','s','t','e','m',0};
static const WCHAR default_sysdirW[] = {'\\','s','y','s','t','e','m',0};
DWORD len;
WCHAR *buffer;
......@@ -804,11 +806,7 @@ static void init_windows_dirs(void)
GetEnvironmentVariableW( windirW, buffer, len );
DIR_Windows = buffer;
}
else
{
DIR_Windows = default_windirW;
SetEnvironmentVariableW( windirW, DIR_Windows );
}
else DIR_Windows = default_windirW;
if ((len = GetEnvironmentVariableW( winsysdirW, NULL, 0 )))
{
......@@ -818,8 +816,11 @@ static void init_windows_dirs(void)
}
else
{
DIR_System = default_sysdirW;
SetEnvironmentVariableW( winsysdirW, DIR_System );
len = strlenW( DIR_Windows );
buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) + sizeof(default_sysdirW) );
memcpy( buffer, DIR_Windows, len * sizeof(WCHAR) );
memcpy( buffer + len, default_sysdirW, sizeof(default_sysdirW) );
DIR_System = buffer;
}
if (GetFileAttributesW( DIR_Windows ) == INVALID_FILE_ATTRIBUTES)
......@@ -831,6 +832,9 @@ static void init_windows_dirs(void)
TRACE_(file)( "WindowsDir = %s\n", debugstr_w(DIR_Windows) );
TRACE_(file)( "SystemDir = %s\n", debugstr_w(DIR_System) );
/* set the directories in ntdll too */
__wine_init_windows_dir( DIR_Windows, DIR_System );
}
......@@ -839,7 +843,7 @@ static void init_windows_dirs(void)
*
* Main process initialisation code
*/
static BOOL process_init( char *argv[], char **environ )
static BOOL process_init(void)
{
static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2',0};
BOOL ret;
......@@ -926,7 +930,7 @@ static BOOL process_init( char *argv[], char **environ )
LOCALE_Init();
/* Copy the parent environment */
if (!build_initial_environment( environ )) return FALSE;
if (!build_initial_environment( __wine_main_environ )) return FALSE;
/* Create device symlinks */
VOLUME_CreateDevices();
......@@ -1001,9 +1005,7 @@ void __wine_kernel_init(void)
PEB *peb = NtCurrentTeb()->Peb;
/* Initialize everything */
if (!process_init( __wine_main_argv, __wine_main_environ )) exit(1);
/* update argc in case options have been removed */
for (__wine_main_argc = 0; __wine_main_argv[__wine_main_argc]; __wine_main_argc++) /*nothing*/;
if (!process_init()) exit(1);
__wine_main_argv++; /* remove argv[0] (wine itself) */
__wine_main_argc--;
......
......@@ -91,7 +91,7 @@ static UINT tls_module_count; /* number of modules with TLS directory */
static UINT tls_total_size; /* total size of TLS storage */
static const IMAGE_TLS_DIRECTORY **tls_dirs; /* array of TLS directories */
static UNICODE_STRING system_dir; /* system directory */
UNICODE_STRING system_dir = { 0, 0, NULL }; /* system directory */
static CRITICAL_SECTION loader_section;
static CRITICAL_SECTION_DEBUG critsect_debug =
......@@ -1538,7 +1538,8 @@ static NTSTATUS load_dll( LPCWSTR load_path, LPCWSTR libname, DWORD flags, WINE_
TRACE("Loaded module %s (%s) at %p\n",
debugstr_w(filename), filetype, (*pwm)->ldr.BaseAddress);
if (!TRACE_ON(module))
TRACE_(loaddll)("Loaded module %s : %s\n", debugstr_w(filename), filetype);
TRACE_(loaddll)("Loaded module %s : %s\n",
debugstr_w((*pwm)->ldr.FullDllName.Buffer), filetype);
/* Set the ldr.LoadCount here so that an attach failure will */
/* decrement the dependencies through the MODULE_FreeLibrary call. */
(*pwm)->ldr.LoadCount = 1;
......@@ -1837,43 +1838,6 @@ PIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE hModule)
/******************************************************************
* init_system_dir
*
* System dir initialization once kernel32 has been loaded.
*/
static inline void init_system_dir(void)
{
PLIST_ENTRY mark, entry;
LPWSTR buffer, p;
if (!MODULE_GetSystemDirectory( &system_dir ))
{
ERR( "Couldn't get system dir\n");
exit(1);
}
/* prepend the system dir to the name of the already created modules */
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
{
LDR_MODULE *mod = CONTAINING_RECORD( entry, LDR_MODULE, InLoadOrderModuleList );
assert( mod->Flags & LDR_WINE_INTERNAL );
buffer = RtlAllocateHeap( GetProcessHeap(), 0,
system_dir.Length + mod->FullDllName.Length + 2*sizeof(WCHAR) );
if (!buffer) continue;
strcpyW( buffer, system_dir.Buffer );
p = buffer + strlenW( buffer );
if (p > buffer && p[-1] != '\\') *p++ = '\\';
strcpyW( p, mod->FullDllName.Buffer );
RtlInitUnicodeString( &mod->FullDllName, buffer );
RtlInitUnicodeString( &mod->BaseDllName, p );
}
}
/******************************************************************
* LdrInitializeThunk (NTDLL.@)
*
* FIXME: the arguments are not correct, main_file is a Wine invention.
......@@ -1887,8 +1851,6 @@ void WINAPI LdrInitializeThunk( HANDLE main_file, ULONG unknown2, ULONG unknown3
UNICODE_STRING *main_exe_name = &peb->ProcessParameters->ImagePathName;
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( peb->ImageBaseAddress );
init_system_dir();
/* allocate the modref for the main exe */
if (!(wm = alloc_module( peb->ImageBaseAddress, main_exe_name->Buffer )))
{
......@@ -2025,6 +1987,39 @@ PVOID WINAPI RtlImageRvaToVa( const IMAGE_NT_HEADERS *nt, HMODULE module,
}
/******************************************************************
* __wine_init_windows_dir (NTDLL.@)
*
* Windows and system dir initialization once kernel32 has been loaded.
*/
void __wine_init_windows_dir( const WCHAR *windir, const WCHAR *sysdir )
{
PLIST_ENTRY mark, entry;
LPWSTR buffer, p;
RtlCreateUnicodeString( &system_dir, sysdir );
/* prepend the system dir to the name of the already created modules */
mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
for (entry = mark->Flink; entry != mark; entry = entry->Flink)
{
LDR_MODULE *mod = CONTAINING_RECORD( entry, LDR_MODULE, InLoadOrderModuleList );
assert( mod->Flags & LDR_WINE_INTERNAL );
buffer = RtlAllocateHeap( GetProcessHeap(), 0,
system_dir.Length + mod->FullDllName.Length + 2*sizeof(WCHAR) );
if (!buffer) continue;
strcpyW( buffer, system_dir.Buffer );
p = buffer + strlenW( buffer );
if (p > buffer && p[-1] != '\\') *p++ = '\\';
strcpyW( p, mod->FullDllName.Buffer );
RtlInitUnicodeString( &mod->FullDllName, buffer );
RtlInitUnicodeString( &mod->BaseDllName, p );
}
}
/***********************************************************************
* __wine_process_init
*/
......
......@@ -471,30 +471,6 @@ static BOOL get_registry_value( HKEY hkey, const WCHAR *module, enum loadorder_t
/***************************************************************************
* MODULE_GetSystemDirectory
*
* Retrieve the system directory. The string must be freed by the caller.
*/
BOOL MODULE_GetSystemDirectory( UNICODE_STRING *sysdir )
{
static const WCHAR winsysdirW[] = {'w','i','n','s','y','s','d','i','r',0};
UNICODE_STRING name;
RtlInitUnicodeString( &name, winsysdirW );
sysdir->MaximumLength = 0;
if (RtlQueryEnvironmentVariable_U( NULL, &name, sysdir ) != STATUS_BUFFER_TOO_SMALL)
return FALSE;
sysdir->MaximumLength = sysdir->Length + sizeof(WCHAR);
if (!(sysdir->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, sysdir->MaximumLength )))
return FALSE;
if (RtlQueryEnvironmentVariable_U( NULL, &name, sysdir ) == STATUS_SUCCESS)
return TRUE;
RtlFreeUnicodeString( sysdir );
return FALSE;
}
/***************************************************************************
* MODULE_GetLoadOrderW (internal)
*
* Locate the loadorder of a module.
......@@ -513,7 +489,6 @@ void MODULE_GetLoadOrderW( enum loadorder_type loadorder[], const WCHAR *app_nam
'D','l','l','O','v','e','r','r','i','d','e','s',0};
static HKEY std_key = (HKEY)-1; /* key to standard section, cached */
static UNICODE_STRING sysdir;
HKEY app_key = 0;
WCHAR *module, *basename;
......@@ -528,11 +503,10 @@ void MODULE_GetLoadOrderW( enum loadorder_type loadorder[], const WCHAR *app_nam
/* Strip path information if the module resides in the system directory
*/
if (!sysdir.Buffer && !MODULE_GetSystemDirectory( &sysdir )) return;
RtlInitUnicodeString( &path_str, path );
if (RtlPrefixUnicodeString( &sysdir, &path_str, TRUE ))
if (RtlPrefixUnicodeString( &system_dir, &path_str, TRUE ))
{
const WCHAR *p = path + sysdir.Length / sizeof(WCHAR);
const WCHAR *p = path + system_dir.Length / sizeof(WCHAR);
while (*p == '\\' || *p == '/') p++;
if (!strchrW( p, '\\' ) && !strchrW( p, '/' )) path = p;
}
......
......@@ -1127,6 +1127,7 @@
# Filesystem
@ cdecl wine_nt_to_unix_file_name(ptr ptr long long)
@ cdecl __wine_init_windows_dir(wstr wstr)
################################################################
# Wine dll separation hacks, these will go away, don't use them
......
......@@ -59,7 +59,6 @@ extern void DECLSPEC_NORETURN server_protocol_perror( const char *err );
extern void DECLSPEC_NORETURN server_abort_thread( int status );
/* module handling */
extern BOOL MODULE_GetSystemDirectory( UNICODE_STRING *sysdir );
extern void RELAY_InitDebugLists(void);
extern FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
DWORD exp_size, FARPROC proc, const WCHAR *user );
......@@ -67,6 +66,7 @@ extern FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY
FARPROC origfun, DWORD ordinal, const WCHAR *user );
extern void RELAY_SetupDLL( HMODULE hmod );
extern void SNOOP_SetupDLL( HMODULE hmod );
extern UNICODE_STRING system_dir;
/* redefine these to make sure we don't reference kernel symbols */
#define GetProcessHeap() (NtCurrentTeb()->Peb->ProcessHeap)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment