Alexandre Julliard : ntdll: Hardcode the windows and system directories.

Alexandre Julliard julliard at winehq.org
Mon Feb 19 13:52:02 CST 2018


Module: wine
Branch: master
Commit: 12276796c95007fc12eb38a41ca25b4daee7e1b3
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=12276796c95007fc12eb38a41ca25b4daee7e1b3

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Feb 19 19:38:29 2018 +0100

ntdll: Hardcode the windows and system directories.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/process.c |  5 -----
 dlls/ntdll/directory.c  | 10 ++--------
 dlls/ntdll/loader.c     | 46 +++++++---------------------------------------
 dlls/ntdll/loadorder.c  |  6 ++----
 dlls/ntdll/ntdll.spec   |  1 -
 dlls/ntdll/ntdll_misc.h |  4 ++--
 dlls/ntdll/rtlstr.c     |  1 +
 dlls/ntdll/thread.c     |  2 ++
 8 files changed, 16 insertions(+), 59 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 62dc815..bbadae0 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -958,8 +958,6 @@ done:
  */
 static void init_windows_dirs(void)
 {
-    extern void CDECL __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};
@@ -1013,9 +1011,6 @@ 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 );
 }
 
 
diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c
index 3b76f9b..4655a634 100644
--- a/dlls/ntdll/directory.c
+++ b/dlls/ntdll/directory.c
@@ -205,8 +205,6 @@ static RTL_RUN_ONCE init_once = RTL_RUN_ONCE_INIT;
 /* at some point we may want to allow Winelib apps to set this */
 static const BOOL is_case_sensitive = FALSE;
 
-UNICODE_STRING system_dir = { 0, 0, NULL };  /* system directory */
-
 static struct file_identity windir;
 
 static RTL_CRITICAL_SECTION dir_section;
@@ -2378,14 +2376,10 @@ static int get_redirect_path( char *unix_name, int pos, const WCHAR *name, int l
 #endif
 
 /***********************************************************************
- *           DIR_init_windows_dir
+ *           init_directories
  */
-void DIR_init_windows_dir( const WCHAR *win, const WCHAR *sys )
+void init_directories(void)
 {
-    /* FIXME: should probably store paths as NT file names */
-
-    RtlCreateUnicodeString( &system_dir, sys );
-
 #ifndef _WIN64
     if (is_wow64) init_redirects();
 #endif
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 77a16b3..3fcbbf7 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -63,6 +63,10 @@ WINE_DECLARE_DEBUG_CHANNEL(imports);
 typedef DWORD (CALLBACK *DLLENTRYPROC)(HMODULE,DWORD,LPVOID);
 typedef void  (CALLBACK *LDRENUMPROC)(LDR_MODULE *, void *, BOOLEAN *);
 
+/* 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};
+
 static BOOL imports_fixup_done = FALSE;  /* set once the imports have been fixed up, before attaching them */
 static BOOL process_detaching = FALSE;  /* set on process detach to avoid deadlocks with thread detach */
 static int free_lib_count;   /* recursion depth of LdrUnloadDll calls */
@@ -1521,12 +1525,10 @@ static WCHAR *get_builtin_fullname( const WCHAR *path, const char *filename )
     }
 
     if ((fullname = RtlAllocateHeap( GetProcessHeap(), 0,
-                                     system_dir.MaximumLength + (len + 1) * sizeof(WCHAR) )))
+                                     (strlenW(system_dir) + len + 1) * sizeof(WCHAR) )))
     {
-        memcpy( fullname, system_dir.Buffer, system_dir.Length );
-        p = fullname + system_dir.Length / sizeof(WCHAR);
-        if (p > fullname && p[-1] != '\\') *p++ = '\\';
-        ascii_to_unicode( p, filename, len + 1 );
+        strcpyW( fullname, system_dir );
+        ascii_to_unicode( fullname + strlenW(fullname), filename, len + 1 );
     }
     return fullname;
 }
@@ -3284,40 +3286,6 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
 }
 
 
-/******************************************************************
- *		__wine_init_windows_dir   (NTDLL.@)
- *
- * Windows and system dir initialization once kernel32 has been loaded.
- */
-void CDECL __wine_init_windows_dir( const WCHAR *windir, const WCHAR *sysdir )
-{
-    PLIST_ENTRY mark, entry;
-    LPWSTR buffer, p;
-
-    strcpyW( user_shared_data->NtSystemRoot, windir );
-    DIR_init_windows_dir( windir, 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
  */
diff --git a/dlls/ntdll/loadorder.c b/dlls/ntdll/loadorder.c
index 157d2cb..c6c0245 100644
--- a/dlls/ntdll/loadorder.c
+++ b/dlls/ntdll/loadorder.c
@@ -434,7 +434,6 @@ enum loadorder get_load_order( const WCHAR *app_name, const WCHAR *path )
     enum loadorder ret = LO_INVALID;
     HANDLE std_key, app_key = 0;
     WCHAR *module, *basename;
-    UNICODE_STRING path_str;
     int len;
 
     if (!init_done) init_load_order();
@@ -445,10 +444,9 @@ enum loadorder get_load_order( const WCHAR *app_name, const WCHAR *path )
 
     /* Strip path information if the module resides in the system directory
      */
-    RtlInitUnicodeString( &path_str, path );
-    if (RtlPrefixUnicodeString( &system_dir, &path_str, TRUE ))
+    if (!strncmpiW( system_dir, path, strlenW( system_dir )))
     {
-        const WCHAR *p = path + system_dir.Length / sizeof(WCHAR);
+        const WCHAR *p = path + strlenW( system_dir );
         while (*p == '\\' || *p == '/') p++;
         if (!strchrW( p, '\\' ) && !strchrW( p, '/' )) path = p;
     }
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 29d4f58..0f70feb 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1496,4 +1496,3 @@
 # Filesystem
 @ cdecl wine_nt_to_unix_file_name(ptr ptr long long)
 @ cdecl wine_unix_to_nt_file_name(ptr ptr)
-@ cdecl __wine_init_windows_dir(wstr wstr)
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 8a64338..3fbccba 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -113,7 +113,7 @@ extern FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY
                                      FARPROC origfun, DWORD ordinal, const WCHAR *user ) DECLSPEC_HIDDEN;
 extern void RELAY_SetupDLL( HMODULE hmod ) DECLSPEC_HIDDEN;
 extern void SNOOP_SetupDLL( HMODULE hmod ) DECLSPEC_HIDDEN;
-extern UNICODE_STRING system_dir DECLSPEC_HIDDEN;
+extern const WCHAR system_dir[] DECLSPEC_HIDDEN;
 
 typedef LONG (WINAPI *PUNHANDLED_EXCEPTION_FILTER)(PEXCEPTION_POINTERS);
 extern PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter DECLSPEC_HIDDEN;
@@ -155,7 +155,7 @@ extern int get_file_info( const char *path, struct stat *st, ULONG *attr ) DECLS
 extern NTSTATUS fill_file_info( const struct stat *st, ULONG attr, void *ptr,
                                 FILE_INFORMATION_CLASS class ) DECLSPEC_HIDDEN;
 extern NTSTATUS server_get_unix_name( HANDLE handle, ANSI_STRING *unix_name ) DECLSPEC_HIDDEN;
-extern void DIR_init_windows_dir( const WCHAR *windir, const WCHAR *sysdir ) DECLSPEC_HIDDEN;
+extern void init_directories(void) DECLSPEC_HIDDEN;
 extern BOOL DIR_is_hidden_file( const UNICODE_STRING *name ) DECLSPEC_HIDDEN;
 extern NTSTATUS DIR_unmount_device( HANDLE handle ) DECLSPEC_HIDDEN;
 extern NTSTATUS DIR_get_unix_cwd( char **cwd ) DECLSPEC_HIDDEN;
diff --git a/dlls/ntdll/rtlstr.c b/dlls/ntdll/rtlstr.c
index 3013658..190bc01 100644
--- a/dlls/ntdll/rtlstr.c
+++ b/dlls/ntdll/rtlstr.c
@@ -61,6 +61,7 @@ void CDECL __wine_init_codepages( const union cptable *ansi, const union cptable
     oem_table = oem;
     unix_table = ucp;
     NlsAnsiCodePage = ansi->info.codepage;
+    init_directories();
 }
 
 int ntdll_umbstowcs(DWORD flags, const char* src, int srclen, WCHAR* dst, int dstlen)
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index c999d4b..9ec94d6 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -53,6 +53,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(thread);
 #endif
 
 struct _KUSER_SHARED_DATA *user_shared_data = NULL;
+static const WCHAR default_windirW[] = {'C',':','\\','w','i','n','d','o','w','s',0};
 
 PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter = NULL;
 void (WINAPI *kernel32_start_process)(LPTHREAD_START_ROUTINE,void*) = NULL;
@@ -298,6 +299,7 @@ HANDLE thread_init(void)
         exit(1);
     }
     user_shared_data = addr;
+    memcpy( user_shared_data->NtSystemRoot, default_windirW, sizeof(default_windirW) );
 
     /* allocate and initialize the PEB */
 




More information about the wine-cvs mailing list