1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 // The whole object of this file is to define |_load_config_used| which
8 // is a weakly-linked symbol that the linker knows about. The crt defines
9 // it as well it but this one will be used if present.
11 // The _load_config_used appears in the exe as a special member of the PE
12 // image format: the load config directory. This structure controls
13 // global parameters which are hard or impossible to set otherwise. This
14 // MSDN page https://goo.gl/zsGeVY documents some of the members.
16 // When making a changes to this stucture the only practical way to make
17 // sure they are honored is to run dumpbin.exe <exe-file> /loadconfig
18 // and inspect the results.
26 DWORD GlobalFlagsClear
;
28 DWORD CriticalSectionDefaultTimeout
;
29 ULONGLONG DeCommitFreeBlockThreshold
;
30 ULONGLONG DeCommitTotalFreeThreshold
;
31 ULONGLONG LockPrefixTable
;
32 ULONGLONG MaximumAllocationSize
;
33 ULONGLONG VirtualMemoryThreshold
;
34 ULONGLONG ProcessAffinityMask
;
35 DWORD ProcessHeapFlags
;
39 ULONGLONG SecurityCookie
;
40 ULONGLONG SEHandlerTable
;
41 ULONGLONG SEHandlerCount
;
42 } IMAGE_LOAD_CONFIG_DIRECTORY64_2
;
43 typedef IMAGE_LOAD_CONFIG_DIRECTORY64_2 IMAGE_LOAD_CONFIG_DIRECTORY_2
;
50 DWORD GlobalFlagsClear
;
52 DWORD CriticalSectionDefaultTimeout
;
53 DWORD DeCommitFreeBlockThreshold
;
54 DWORD DeCommitTotalFreeThreshold
;
55 DWORD LockPrefixTable
;
56 DWORD MaximumAllocationSize
;
57 DWORD VirtualMemoryThreshold
;
58 DWORD ProcessHeapFlags
;
59 DWORD ProcessAffinityMask
;
63 PUINT_PTR SecurityCookie
;
64 PVOID
*SEHandlerTable
;
66 } IMAGE_LOAD_CONFIG_DIRECTORY32_2
;
67 typedef IMAGE_LOAD_CONFIG_DIRECTORY32_2 IMAGE_LOAD_CONFIG_DIRECTORY_2
;
70 // What follows, except as indicated is verbatim (including casts) from
71 // <visual studio path>\VC\crt\src\intel\loadcfg.c. The default values
72 // are all 0 except for the last 3 members. See
73 // https://msdn.microsoft.com/en-us/library/9a89h429.aspx for an
74 // explanation of these members.
75 extern "C" UINT_PTR __security_cookie
;
76 extern "C" PVOID __safe_se_handler_table
[];
77 extern "C" BYTE __safe_se_handler_count
;
79 // DeCommitTotalFreeThreshold: increase the decomit free threshold for
80 // the process heap, which is documented as "The size of the minimum
81 // total memory that must be freed in the process heap before it is
82 // freed (de-committed) in bytes".
84 // Set at 2 MiB what this does is prevent a lot of VirtualFree plus the
85 // following VirtualAlloc because the default value makes the heap too
86 // conservative on the ammount of memory it keeps for future allocations.
89 const IMAGE_LOAD_CONFIG_DIRECTORY_2 _load_config_used
= {
90 sizeof(IMAGE_LOAD_CONFIG_DIRECTORY_2
),
94 0, // GlobalFlagsClear.
96 0, // CriticalSectionDefaultTimeout.
97 0, // DeCommitFreeBlockThreshold.
98 2 * 1024 * 1024, // DeCommitTotalFreeThreshold.
99 0, // LockPrefixTable.
100 0, // MaximumAllocationSize.
101 0, // VirtualMemoryThreshold.
102 0, // ProcessHeapFlags.
103 0, // ProcessAffinityMask.
108 (ULONGLONG
)&__security_cookie
,
111 __safe_se_handler_table
,
112 (DWORD
)(DWORD_PTR
)&__safe_se_handler_count