diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c index 1ef4a20daea..e729bca87ef 100644 --- a/dlls/kernel32/tests/process.c +++ b/dlls/kernel32/tests/process.c @@ -3384,7 +3384,7 @@ static void test_SuspendProcessState(void) ULONG pipe_magic, numb; BOOL ret; void *user_thread_start, *start_ptr, *entry_ptr, *peb_ptr; - PEB child_peb; + PEB child_peb, *peb = NtCurrentTeb()->Peb; exit_process_ptr = GetProcAddress(hkernel32, "ExitProcess"); ok(exit_process_ptr != NULL, "GetProcAddress ExitProcess failed\n"); @@ -3515,9 +3515,19 @@ static void test_SuspendProcessState(void) ok( !child_peb.ProcessHeap, "ProcessHeap set %p\n", child_peb.ProcessHeap ); ok( !child_peb.CSDVersion.Buffer, "CSDVersion set %s\n", debugstr_w(child_peb.CSDVersion.Buffer) ); - ok( child_peb.OSMajorVersion, "OSMajorVersion not set %u\n", child_peb.OSMajorVersion ); - ok( child_peb.OSPlatformId == VER_PLATFORM_WIN32_NT, "OSPlatformId not set %u\n", child_peb.OSPlatformId ); - ok( child_peb.SessionId == 1, "SessionId not set %u\n", child_peb.SessionId ); + ok( child_peb.OSMajorVersion == peb->OSMajorVersion, "OSMajorVersion not set %u\n", child_peb.OSMajorVersion ); + ok( child_peb.OSPlatformId == peb->OSPlatformId, "OSPlatformId not set %u\n", child_peb.OSPlatformId ); + ok( child_peb.SessionId == peb->SessionId, "SessionId not set %u\n", child_peb.SessionId ); + ok( child_peb.CriticalSectionTimeout.QuadPart, "CriticalSectionTimeout not set %s\n", + wine_dbgstr_longlong(child_peb.CriticalSectionTimeout.QuadPart) ); + ok( child_peb.HeapSegmentReserve == peb->HeapSegmentReserve, + "HeapSegmentReserve not set %lu\n", child_peb.HeapSegmentReserve ); + ok( child_peb.HeapSegmentCommit == peb->HeapSegmentCommit, + "HeapSegmentCommit not set %lu\n", child_peb.HeapSegmentCommit ); + ok( child_peb.HeapDeCommitTotalFreeThreshold == peb->HeapDeCommitTotalFreeThreshold, + "HeapDeCommitTotalFreeThreshold not set %lu\n", child_peb.HeapDeCommitTotalFreeThreshold ); + ok( child_peb.HeapDeCommitFreeBlockThreshold == peb->HeapDeCommitFreeBlockThreshold, + "HeapDeCommitFreeBlockThreshold not set %lu\n", child_peb.HeapDeCommitFreeBlockThreshold ); if (pNtQueryInformationThread) { diff --git a/dlls/ntdll/heap.c b/dlls/ntdll/heap.c index cae41cba0d9..346bcf3c10c 100644 --- a/dlls/ntdll/heap.c +++ b/dlls/ntdll/heap.c @@ -1440,7 +1440,7 @@ static BOOL validate_block_pointer( HEAP *heap, SUBHEAP **ret_subheap, const ARE /*********************************************************************** * heap_set_debug_flags */ -void heap_set_debug_flags( HANDLE handle ) +static void heap_set_debug_flags( HANDLE handle ) { HEAP *heap = HEAP_GetPtr( handle ); ULONG global_flags = RtlGetNtGlobalFlags(); @@ -1508,7 +1508,7 @@ void heap_set_debug_flags( HANDLE handle ) if ((heap->flags & HEAP_GROWABLE) && !heap->pending_free && ((flags & HEAP_FREE_CHECKING_ENABLED) || RUNNING_ON_VALGRIND)) { - heap->pending_free = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, + heap->pending_free = RtlAllocateHeap( handle, HEAP_ZERO_MEMORY, MAX_FREE_PENDING * sizeof(*heap->pending_free) ); heap->pending_pos = 0; } diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index c8ea2452e66..9f126249c01 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -3662,7 +3662,6 @@ static void load_global_options(void) OBJECT_ATTRIBUTES attr; UNICODE_STRING name_str, val_str; HANDLE hkey; - ULONG value; RtlInitUnicodeString( &name_str, L"WINEBOOTSTRAPMODE" ); val_str.MaximumLength = 0; @@ -3678,31 +3677,10 @@ static void load_global_options(void) if (!NtOpenKey( &hkey, KEY_QUERY_VALUE, &attr )) { - query_dword_option( hkey, L"GlobalFlag", &NtCurrentTeb()->Peb->NtGlobalFlag ); query_dword_option( hkey, L"SafeProcessSearchMode", &path_safe_mode ); query_dword_option( hkey, L"SafeDllSearchMode", &dll_safe_mode ); - - if (!query_dword_option( hkey, L"CriticalSectionTimeout", &value )) - NtCurrentTeb()->Peb->CriticalSectionTimeout.QuadPart = (ULONGLONG)value * -10000000; - - if (!query_dword_option( hkey, L"HeapSegmentReserve", &value )) - NtCurrentTeb()->Peb->HeapSegmentReserve = value; - - if (!query_dword_option( hkey, L"HeapSegmentCommit", &value )) - NtCurrentTeb()->Peb->HeapSegmentCommit = value; - - if (!query_dword_option( hkey, L"HeapDeCommitTotalFreeThreshold", &value )) - NtCurrentTeb()->Peb->HeapDeCommitTotalFreeThreshold = value; - - if (!query_dword_option( hkey, L"HeapDeCommitFreeBlockThreshold", &value )) - NtCurrentTeb()->Peb->HeapDeCommitFreeBlockThreshold = value; - NtClose( hkey ); } - LdrQueryImageFileExecutionOptions( &NtCurrentTeb()->Peb->ProcessParameters->ImagePathName, - L"GlobalFlag", REG_DWORD, &NtCurrentTeb()->Peb->NtGlobalFlag, - sizeof(DWORD), NULL ); - heap_set_debug_flags( GetProcessHeap() ); } diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index acb927a9171..1e93692fe12 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -64,7 +64,6 @@ extern const char *debugstr_exception_code( DWORD code ) DECLSPEC_HIDDEN; extern void version_init(void) DECLSPEC_HIDDEN; extern void debug_init(void) DECLSPEC_HIDDEN; extern void actctx_init(void) DECLSPEC_HIDDEN; -extern void heap_set_debug_flags( HANDLE handle ) DECLSPEC_HIDDEN; extern void init_user_process_params(void) DECLSPEC_HIDDEN; extern void CDECL DECLSPEC_NORETURN signal_start_thread( CONTEXT *ctx ) DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index e90bfbf171e..a30db6dda8b 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -1930,6 +1930,76 @@ static inline void dup_unicode_string( const UNICODE_STRING *src, WCHAR **dst, U } +/************************************************************************* + * get_dword_option + */ +static ULONG get_dword_option( HANDLE key, const WCHAR *name, ULONG defval ) +{ + UNICODE_STRING str; + ULONG size; + WCHAR buffer[64]; + KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer; + + init_unicode_string( &str, name ); + size = sizeof(buffer) - sizeof(WCHAR); + if (NtQueryValueKey( key, &str, KeyValuePartialInformation, buffer, size, &size )) return defval; + if (info->Type != REG_DWORD) return defval; + return *(ULONG *)info->Data; +} + + +/************************************************************************* + * load_global_options + */ +static void load_global_options( const UNICODE_STRING *image ) +{ + 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',0}; + 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}; + static const WCHAR critsectionW[] = {'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 heapreserveW[] = {'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 heapdecommittotalW[] = {'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 heapdecommitblockW[] = {'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 nameW; + HANDLE key; + ULONG i; + + InitializeObjectAttributes( &attr, &nameW, OBJ_CASE_INSENSITIVE, 0, NULL ); + init_unicode_string( &nameW, sessionW ); + if (!NtOpenKey( &key, KEY_QUERY_VALUE, &attr )) + { + peb->NtGlobalFlag = get_dword_option( key, globalflagW, 0 ); + peb->CriticalSectionTimeout.QuadPart = get_dword_option( key, critsectionW, 30 * 24 * 60 * 60 ) * (ULONGLONG)-10000000; + peb->HeapSegmentReserve = get_dword_option( key, heapreserveW, 0x100000 ); + peb->HeapSegmentCommit = get_dword_option( key, heapcommitW, 0x10000 ); + peb->HeapDeCommitTotalFreeThreshold = get_dword_option( key, heapdecommittotalW, 0x10000 ); + peb->HeapDeCommitFreeBlockThreshold = get_dword_option( key, heapdecommitblockW, 0x1000 ); + NtClose( key ); + } + init_unicode_string( &nameW, optionsW ); + if (!NtOpenKey( &key, KEY_QUERY_VALUE, &attr )) + { + attr.RootDirectory = key; + for (i = image->Length / sizeof(WCHAR); i; i--) if (image->Buffer[i - 1] == '\\') break; + nameW.Buffer = image->Buffer + i; + nameW.Length = image->Length - i * sizeof(WCHAR); + if (!NtOpenKey( &key, KEY_QUERY_VALUE, &attr )) + { + peb->NtGlobalFlag = get_dword_option( key, globalflagW, peb->NtGlobalFlag ); + NtClose( key ); + } + NtClose( attr.RootDirectory ); + } +} + + /************************************************************************* * build_wow64_parameters */ @@ -2008,6 +2078,8 @@ static void init_peb( RTL_USER_PROCESS_PARAMETERS *params, void *module ) peb->ImageSubSystemMajorVersion = main_image_info.MajorSubsystemVersion; peb->ImageSubSystemMinorVersion = main_image_info.MinorSubsystemVersion; + load_global_options( ¶ms->ImagePathName ); + if (NtCurrentTeb()->WowTebOffset) { void *wow64_params = build_wow64_parameters( params ); @@ -2016,17 +2088,23 @@ static void init_peb( RTL_USER_PROCESS_PARAMETERS *params, void *module ) #else PEB64 *wow64_peb = (PEB64 *)((char *)peb - page_size); #endif - wow64_peb->ImageBaseAddress = PtrToUlong( peb->ImageBaseAddress ); - wow64_peb->ProcessParameters = PtrToUlong( wow64_params ); - wow64_peb->NumberOfProcessors = peb->NumberOfProcessors; - wow64_peb->OSMajorVersion = peb->OSMajorVersion; - wow64_peb->OSMinorVersion = peb->OSMinorVersion; - wow64_peb->OSBuildNumber = peb->OSBuildNumber; - wow64_peb->OSPlatformId = peb->OSPlatformId; - wow64_peb->ImageSubSystem = peb->ImageSubSystem; - wow64_peb->ImageSubSystemMajorVersion = peb->ImageSubSystemMajorVersion; - wow64_peb->ImageSubSystemMinorVersion = peb->ImageSubSystemMinorVersion; - wow64_peb->SessionId = peb->SessionId; + wow64_peb->ImageBaseAddress = PtrToUlong( peb->ImageBaseAddress ); + wow64_peb->ProcessParameters = PtrToUlong( wow64_params ); + wow64_peb->NumberOfProcessors = peb->NumberOfProcessors; + wow64_peb->NtGlobalFlag = peb->NtGlobalFlag; + wow64_peb->CriticalSectionTimeout.QuadPart = peb->CriticalSectionTimeout.QuadPart; + wow64_peb->HeapSegmentReserve = peb->HeapSegmentReserve; + wow64_peb->HeapSegmentCommit = peb->HeapSegmentCommit; + wow64_peb->HeapDeCommitTotalFreeThreshold = peb->HeapDeCommitTotalFreeThreshold; + wow64_peb->HeapDeCommitFreeBlockThreshold = peb->HeapDeCommitFreeBlockThreshold; + wow64_peb->OSMajorVersion = peb->OSMajorVersion; + wow64_peb->OSMinorVersion = peb->OSMinorVersion; + wow64_peb->OSBuildNumber = peb->OSBuildNumber; + wow64_peb->OSPlatformId = peb->OSPlatformId; + wow64_peb->ImageSubSystem = peb->ImageSubSystem; + wow64_peb->ImageSubSystemMajorVersion = peb->ImageSubSystemMajorVersion; + wow64_peb->ImageSubSystemMinorVersion = peb->ImageSubSystemMinorVersion; + wow64_peb->SessionId = peb->SessionId; } }