-- v2: ntdll: Avoid calling RtlInit(Ansi|Unicode)String on a static constant.
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/ntdll/env.c | 7 ++----- dlls/ntdll/unix/registry.c | 2 +- dlls/ntdll/unix/virtual.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index 6db6cee17cd..ab54a9ec563 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -54,12 +54,9 @@ static inline SIZE_T get_env_length( const WCHAR *env ) */ static void set_wow64_environment( WCHAR **env ) { - static WCHAR archW[] = L"PROCESSOR_ARCHITECTURE"; - static WCHAR arch6432W[] = L"PROCESSOR_ARCHITEW6432"; - WCHAR buf[256]; - UNICODE_STRING arch_strW = { sizeof(archW) - sizeof(WCHAR), sizeof(archW), archW }; - UNICODE_STRING arch6432_strW = { sizeof(arch6432W) - sizeof(WCHAR), sizeof(arch6432W), arch6432W }; + UNICODE_STRING arch_strW = RTL_CONSTANT_STRING( L"PROCESSOR_ARCHITECTURE" ); + UNICODE_STRING arch6432_strW = RTL_CONSTANT_STRING( L"PROCESSOR_ARCHITEW6432" ); UNICODE_STRING valW = { 0, sizeof(buf), buf }; UNICODE_STRING nameW;
diff --git a/dlls/ntdll/unix/registry.c b/dlls/ntdll/unix/registry.c index d183474b53f..a24d6e7c267 100644 --- a/dlls/ntdll/unix/registry.c +++ b/dlls/ntdll/unix/registry.c @@ -826,7 +826,7 @@ NTSTATUS WINAPI NtQueryLicenseValue( const UNICODE_STRING *name, ULONG *type, 'S','o','f','t','w','a','r','e','\', 'W','i','n','e','\','L','i','c','e','n','s','e', 'I','n','f','o','r','m','a','t','i','o','n',0}; - UNICODE_STRING keyW = { sizeof(nameW) - sizeof(WCHAR), sizeof(nameW), (WCHAR *)nameW }; + UNICODE_STRING keyW = RTL_CONSTANT_STRING( nameW ); KEY_VALUE_PARTIAL_INFORMATION *info; NTSTATUS status = STATUS_OBJECT_NAME_NOT_FOUND; DWORD info_length, count; diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 0f66429fc9d..f6e8793396c 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -3192,7 +3192,7 @@ void virtual_map_user_shared_data(void) { static const WCHAR nameW[] = {'\','K','e','r','n','e','l','O','b','j','e','c','t','s', '\','_','_','w','i','n','e','_','u','s','e','r','_','s','h','a','r','e','d','_','d','a','t','a',0}; - UNICODE_STRING name_str = { sizeof(nameW) - sizeof(WCHAR), sizeof(nameW), (WCHAR *)nameW }; + UNICODE_STRING name_str = RTL_CONSTANT_STRING( nameW ); OBJECT_ATTRIBUTES attr = { sizeof(attr), 0, &name_str }; unsigned int status; HANDLE section;
From: Alex Henrie alexhenrie24@gmail.com
--- dlls/ntdll/loader.c | 33 +++++++++++++++------------------ dlls/ntdll/relay.c | 3 +-- 2 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 61aeb25898b..0e4387f8594 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2189,10 +2189,9 @@ static NTSTATUS build_module( LPCWSTR load_path, const UNICODE_STRING *nt_name, */ static void build_ntdll_module( HMODULE module ) { - UNICODE_STRING nt_name; + UNICODE_STRING nt_name = RTL_CONSTANT_STRING( L"\??\C:\windows\system32\ntdll.dll" ); WINE_MODREF *wm;
- RtlInitUnicodeString( &nt_name, L"\??\C:\windows\system32\ntdll.dll" ); wm = alloc_module( module, &nt_name, TRUE ); assert( wm ); wm->ldr.Flags &= ~LDR_DONT_RESOLVE_REFS; @@ -2364,7 +2363,7 @@ static inline WCHAR *append_path( WCHAR *p, const WCHAR *str, int len ) static NTSTATUS get_dll_load_path( LPCWSTR module, LPCWSTR dll_dir, ULONG safe_mode, WCHAR **path ) { const WCHAR *mod_end = module; - UNICODE_STRING name, value; + UNICODE_STRING name = RTL_CONSTANT_STRING( L"PATH" ), value; WCHAR *p, *ret; int len = ARRAY_SIZE(system_path) + 1, path_len = 0;
@@ -2374,7 +2373,6 @@ static NTSTATUS get_dll_load_path( LPCWSTR module, LPCWSTR dll_dir, ULONG safe_m len += (mod_end - module) + 1; }
- RtlInitUnicodeString( &name, L"PATH" ); value.Length = 0; value.MaximumLength = 0; value.Buffer = NULL; @@ -3945,20 +3943,22 @@ static void process_breakpoint(void) static void load_global_options(void) { OBJECT_ATTRIBUTES attr; - UNICODE_STRING name_str, val_str; + UNICODE_STRING bootstrap_mode_str = RTL_CONSTANT_STRING( L"WINEBOOTSTRAPMODE" ); + UNICODE_STRING session_manager_str = + RTL_CONSTANT_STRING( L"\Registry\Machine\System\CurrentControlSet\Control\Session Manager" ); + UNICODE_STRING val_str; HANDLE hkey;
- RtlInitUnicodeString( &name_str, L"WINEBOOTSTRAPMODE" ); val_str.MaximumLength = 0; - is_prefix_bootstrap = RtlQueryEnvironmentVariable_U( NULL, &name_str, &val_str ) != STATUS_VARIABLE_NOT_FOUND; + is_prefix_bootstrap = + RtlQueryEnvironmentVariable_U( NULL, &bootstrap_mode_str, &val_str ) != STATUS_VARIABLE_NOT_FOUND;
attr.Length = sizeof(attr); attr.RootDirectory = 0; - attr.ObjectName = &name_str; + attr.ObjectName = &session_manager_str; attr.Attributes = OBJ_CASE_INSENSITIVE; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; - RtlInitUnicodeString( &name_str, L"\Registry\Machine\System\CurrentControlSet\Control\Session Manager" );
if (!NtOpenKey( &hkey, KEY_QUERY_VALUE, &attr )) { @@ -4013,12 +4013,11 @@ static void map_wow64cpu(void) { SIZE_T size = 0; OBJECT_ATTRIBUTES attr; - UNICODE_STRING string; + UNICODE_STRING string = RTL_CONSTANT_STRING( L"\??\C:\windows\sysnative\wow64cpu.dll" ); HANDLE file, section; IO_STATUS_BLOCK io; NTSTATUS status;
- RtlInitUnicodeString( &string, L"\??\C:\windows\sysnative\wow64cpu.dll" ); InitializeObjectAttributes( &attr, &string, 0, NULL, NULL ); if ((status = NtOpenFile( &file, GENERIC_READ | SYNCHRONIZE, &attr, &io, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE ))) @@ -4108,7 +4107,8 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR if (!imports_fixup_done) { MEMORY_BASIC_INFORMATION meminfo; - ANSI_STRING func_name; + ANSI_STRING base_thread_init_thunk = RTL_CONSTANT_STRING( "BaseThreadInitThunk" ); + ANSI_STRING ctrl_routine = RTL_CONSTANT_STRING( "CtrlRoutine" ); WINE_MODREF *kernel32; PEB *peb = NtCurrentTeb()->Peb;
@@ -4148,15 +4148,13 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR NtTerminateProcess( GetCurrentProcess(), status ); } node_kernel32 = kernel32->ldr.DdagNode; - RtlInitAnsiString( &func_name, "BaseThreadInitThunk" ); - if ((status = LdrGetProcedureAddress( kernel32->ldr.DllBase, &func_name, + if ((status = LdrGetProcedureAddress( kernel32->ldr.DllBase, &base_thread_init_thunk, 0, (void **)&pBaseThreadInitThunk )) != STATUS_SUCCESS) { MESSAGE( "wine: could not find BaseThreadInitThunk in kernel32.dll, status %lx\n", status ); NtTerminateProcess( GetCurrentProcess(), status ); } - RtlInitAnsiString( &func_name, "CtrlRoutine" ); - LdrGetProcedureAddress( kernel32->ldr.DllBase, &func_name, 0, (void **)&pCtrlRoutine ); + LdrGetProcedureAddress( kernel32->ldr.DllBase, &ctrl_routine, 0, (void **)&pCtrlRoutine );
actctx_init(); locale_init(); @@ -4526,9 +4524,8 @@ NTSTATUS WINAPI RtlGetExePath( PCWSTR name, PWSTR *path ) /* same check as NeedCurrentDirectoryForExePathW */ if (!wcschr( name, '\' )) { - UNICODE_STRING name, value = { 0 }; + UNICODE_STRING name = RTL_CONSTANT_STRING( L"NoDefaultCurrentDirectoryInExePath" ), value = { 0 };
- RtlInitUnicodeString( &name, L"NoDefaultCurrentDirectoryInExePath" ); if (RtlQueryEnvironmentVariable_U( NULL, &name, &value ) != STATUS_VARIABLE_NOT_FOUND) dlldir = L""; } diff --git a/dlls/ntdll/relay.c b/dlls/ntdll/relay.c index 7dbff3c0727..afa4085fb33 100644 --- a/dlls/ntdll/relay.c +++ b/dlls/ntdll/relay.c @@ -165,7 +165,7 @@ static const WCHAR **load_list( HKEY hkey, const WCHAR *value ) static DWORD WINAPI init_debug_lists( RTL_RUN_ONCE *once, void *param, void **context ) { OBJECT_ATTRIBUTES attr; - UNICODE_STRING name; + UNICODE_STRING name = RTL_CONSTANT_STRING( L"Software\Wine\Debug" ); HANDLE root, hkey;
RtlOpenCurrentUser( KEY_ALL_ACCESS, &root ); @@ -175,7 +175,6 @@ static DWORD WINAPI init_debug_lists( RTL_RUN_ONCE *once, void *param, void **co attr.Attributes = 0; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; - RtlInitUnicodeString( &name, L"Software\Wine\Debug" );
/* @@ Wine registry key: HKCU\Software\Wine\Debug */ if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) hkey = 0;