From 74390cead33b9394c004c83f008ca13ed14213a0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 19 Mar 2021 11:24:46 +0100 Subject: [PATCH] ntdll: Add a global constant for the system directory. Signed-off-by: Alexandre Julliard --- dlls/ntdll/unix/env.c | 14 +++++++------- dlls/ntdll/unix/loadorder.c | 6 ++---- dlls/ntdll/unix/process.c | 5 ++--- dlls/ntdll/unix/unix_private.h | 1 + 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 2051ad33888..e1fb4c99544 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -76,6 +76,10 @@ static LANGID user_ui_language, system_ui_language; static char system_locale[LOCALE_NAME_MAX_LENGTH]; static char user_locale[LOCALE_NAME_MAX_LENGTH]; +/* 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 struct { USHORT *data; @@ -149,8 +153,6 @@ static void *read_nls_file( ULONG type, ULONG id ) static NTSTATUS open_nls_data_file( ULONG type, ULONG id, HANDLE *file ) { - static const WCHAR systemdirW[] = {'\\','?','?','\\','C',':','\\','w','i','n','d','o','w','s','\\', - 's','y','s','t','e','m','3','2','\\',0}; static const WCHAR sortdirW[] = {'\\','?','?','\\','C',':','\\','w','i','n','d','o','w','s','\\', 'g','l','o','b','a','l','i','z','a','t','i','o','n','\\', 's','o','r','t','i','n','g','\\',0}; @@ -165,7 +167,7 @@ static NTSTATUS open_nls_data_file( ULONG type, ULONG id, HANDLE *file ) if (!path) return STATUS_OBJECT_NAME_NOT_FOUND; /* try to open file in system dir */ - wcscpy( buffer, type == NLS_SECTION_SORTKEYS ? sortdirW : systemdirW ); + wcscpy( buffer, type == NLS_SECTION_SORTKEYS ? sortdirW : system_dir ); p = strrchr( path, '/' ) + 1; ascii_to_unicode( buffer + wcslen(buffer), p, strlen(p) + 1 ); init_unicode_string( &valueW, buffer ); @@ -1609,8 +1611,6 @@ static void run_wineboot( WCHAR *env, SIZE_T size ) static const WCHAR cmdlineW[] = {'"','C',':','\\','w','i','n','d','o','w','s','\\', 's','y','s','t','e','m','3','2','\\','w','i','n','e','b','o','o','t','.','e','x','e','"', ' ','-','-','i','n','i','t',0}; - static const WCHAR sysdirW[] = {'C',':','\\','w','i','n','d','o','w','s', - '\\','s','y','s','t','e','m','3','2',0}; RTL_USER_PROCESS_PARAMETERS params = { sizeof(params), sizeof(params) }; PS_ATTRIBUTE_LIST ps_attr; PS_CREATE_INFO create_info; @@ -1635,8 +1635,8 @@ static void run_wineboot( WCHAR *env, SIZE_T size ) params.Flags = PROCESS_PARAMS_FLAG_NORMALIZED; params.Environment = env; params.EnvironmentSize = size; - init_unicode_string( ¶ms.CurrentDirectory.DosPath, sysdirW ); - init_unicode_string( ¶ms.DllPath, sysdirW ); + init_unicode_string( ¶ms.CurrentDirectory.DosPath, system_dir + 4 ); + init_unicode_string( ¶ms.DllPath, system_dir + 4 ); init_unicode_string( ¶ms.ImagePathName, appnameW + 4 ); init_unicode_string( ¶ms.CommandLine, cmdlineW ); init_unicode_string( ¶ms.WindowTitle, appnameW + 4 ); diff --git a/dlls/ntdll/unix/loadorder.c b/dlls/ntdll/unix/loadorder.c index 0097fd73e80..f7360bdf7e1 100644 --- a/dlls/ntdll/unix/loadorder.c +++ b/dlls/ntdll/unix/loadorder.c @@ -381,8 +381,6 @@ static enum loadorder get_load_order_value( HANDLE std_key, HANDLE app_key, WCHA enum loadorder CDECL get_load_order( const WCHAR *app_name, const UNICODE_STRING *nt_name ) { static const WCHAR prefixW[] = {'\\','?','?','\\'}; - static const WCHAR system_dir[] = {'C',':','\\','w','i','n','d','o','w','s', - '\\','s','y','s','t','e','m','3','2'}; enum loadorder ret = LO_INVALID; HANDLE std_key, app_key = 0; const WCHAR *path = nt_name->Buffer; @@ -398,9 +396,9 @@ enum loadorder CDECL get_load_order( const WCHAR *app_name, const UNICODE_STRING /* Strip path information if the module resides in the system directory */ - if (!wcsnicmp( system_dir, path, ARRAY_SIZE( system_dir ))) + if (!wcsnicmp( system_dir + 4, path, wcslen(system_dir) - 4 )) { - const WCHAR *p = path + ARRAY_SIZE( system_dir ); + const WCHAR *p = path + wcslen( system_dir ) - 4; while (*p == '\\' || *p == '/') p++; if (!wcschr( p, '\\' ) && !wcschr( p, '/' )) path = p; } diff --git a/dlls/ntdll/unix/process.c b/dlls/ntdll/unix/process.c index 441b34ee9c4..d6dc893fba5 100644 --- a/dlls/ntdll/unix/process.c +++ b/dlls/ntdll/unix/process.c @@ -281,13 +281,12 @@ static startup_info_t *create_startup_info( const RTL_USER_PROCESS_PARAMETERS *p */ static BOOL is_builtin_path( UNICODE_STRING *path, BOOL *is_64bit ) { - static const WCHAR systemW[] = {'\\','?','?','\\','c',':','\\','w','i','n','d','o','w','s','\\', - 's','y','s','t','e','m','3','2','\\'}; static const WCHAR wow64W[] = {'\\','?','?','\\','c',':','\\','w','i','n','d','o','w','s','\\', 's','y','s','w','o','w','6','4'}; *is_64bit = is_win64; - if (path->Length > sizeof(systemW) && !wcsnicmp( path->Buffer, systemW, ARRAY_SIZE(systemW) )) + if (path->Length > wcslen(system_dir) * sizeof(WCHAR) && + !wcsnicmp( path->Buffer, system_dir, wcslen(system_dir) )) { #ifndef _WIN64 if (NtCurrentTeb64() && NtCurrentTeb64()->TlsSlots[WOW64_TLS_FILESYSREDIR]) *is_64bit = TRUE; diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index 7e31710af70..c00a6ee6aa8 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -122,6 +122,7 @@ extern int main_argc DECLSPEC_HIDDEN; extern char **main_argv DECLSPEC_HIDDEN; extern char **main_envp DECLSPEC_HIDDEN; extern WCHAR **main_wargv DECLSPEC_HIDDEN; +extern const WCHAR system_dir[] DECLSPEC_HIDDEN; extern unsigned int server_cpus DECLSPEC_HIDDEN; extern BOOL is_wow64 DECLSPEC_HIDDEN; extern BOOL process_exiting DECLSPEC_HIDDEN;