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