1 /* 2 * PROJECT: ReactOS API tests 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: LOAD_CONFIG validation / registration 5 * COPYRIGHT: Copyright 2020 Mark Jansen (mark.jansen@reactos.org) 6 */ 7 8 #include "loadconfig.h" 9 10 11 // Tell the linker we want a LOAD_CONFIG 12 const IMAGE_LOAD_CONFIG_DIRECTORY _load_config_used = 13 { 14 sizeof(IMAGE_LOAD_CONFIG_DIRECTORY), 15 0, // TimeDateStamp 16 0, // MajorVersion 17 0, // MinorVersion 18 0, // GlobalFlagsClear 19 FLG_USER_STACK_TRACE_DB, // GlobalFlagsSet 20 0, // CriticalSectionDefaultTimeout 21 0, // DeCommitFreeBlockThreshold 22 0, // DeCommitTotalFreeThreshold 23 0, // LockPrefixTable 24 0, // MaximumAllocationSize 25 0, // VirtualMemoryThreshold 26 0, // ProcessHeapFlags 27 0, // ProcessAffinityMask 28 0, // CSDVersion 29 0, // Reserved1 30 0, // EditList 31 0, // SecurityCookie 32 }; 33 34 35 BOOL check_loadconfig() 36 { 37 BOOL Result; 38 PPEB Peb = NtCurrentPeb(); 39 ULONG ConfigSize = 0; 40 ULONG MinimalSize; 41 PIMAGE_LOAD_CONFIG_DIRECTORY LoadConfig; 42 43 // Validate the required flag for the 'stacktrace' test 44 ok(Peb->NtGlobalFlag & FLG_USER_STACK_TRACE_DB, "NtGlobalFlag: 0x%lx\n", Peb->NtGlobalFlag); 45 Result = (Peb->NtGlobalFlag & FLG_USER_STACK_TRACE_DB) != 0; 46 47 // Now validate our LOAD_CONFIG entry 48 LoadConfig = (PIMAGE_LOAD_CONFIG_DIRECTORY)RtlImageDirectoryEntryToData(Peb->ImageBaseAddress, 49 TRUE, 50 IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, 51 &ConfigSize); 52 53 MinimalSize = FIELD_OFFSET(IMAGE_LOAD_CONFIG_DIRECTORY, SecurityCookie) + sizeof(LoadConfig->SecurityCookie); 54 if (!LoadConfig || ConfigSize < MinimalSize) 55 { 56 ok(0, "Invalid IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG: %p, %lu (%lu)\n", 57 LoadConfig, ConfigSize, MinimalSize); 58 } 59 else 60 { 61 ok(LoadConfig->GlobalFlagsSet & FLG_USER_STACK_TRACE_DB, 62 "Invalid GlobalFlagsSet: %lx\n", LoadConfig->GlobalFlagsSet); 63 ok(!(LoadConfig->GlobalFlagsClear & FLG_USER_STACK_TRACE_DB), 64 "Invalid GlobalFlagsClear: %lx\n", LoadConfig->GlobalFlagsClear); 65 ok(LoadConfig->Size == sizeof(IMAGE_LOAD_CONFIG_DIRECTORY), 66 "Unexpected size difference: %lu vs %u\n", LoadConfig->Size, sizeof(IMAGE_LOAD_CONFIG_DIRECTORY)); 67 } 68 69 return Result; 70 } 71