OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include <windows.h> | |
6 | |
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 // as well it but this one will be used if present. | |
brucedawson
2015/05/13 17:50:46
Missing word 'it': "it as well"...
| |
10 // | |
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. | |
15 // | |
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. | |
brucedawson
2015/05/13 17:50:46
I also wrote a tool (85 lines of PE parsing) that
| |
19 | |
20 #if defined(_WIN64) | |
21 typedef struct { | |
22 DWORD Size; | |
23 DWORD TimeDateStamp; | |
24 WORD MajorVersion; | |
25 WORD MinorVersion; | |
26 DWORD GlobalFlagsClear; | |
27 DWORD GlobalFlagsSet; | |
28 DWORD CriticalSectionDefaultTimeout; | |
29 ULONGLONG DeCommitFreeBlockThreshold; | |
30 ULONGLONG DeCommitTotalFreeThreshold; | |
31 ULONGLONG LockPrefixTable; | |
32 ULONGLONG MaximumAllocationSize; | |
33 ULONGLONG VirtualMemoryThreshold; | |
34 ULONGLONG ProcessAffinityMask; | |
35 DWORD ProcessHeapFlags; | |
36 WORD CSDVersion; | |
37 WORD Reserved1; | |
38 ULONGLONG EditList; | |
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; | |
44 #else | |
45 typedef struct { | |
46 DWORD Size; | |
47 DWORD TimeDateStamp; | |
48 WORD MajorVersion; | |
49 WORD MinorVersion; | |
50 DWORD GlobalFlagsClear; | |
51 DWORD GlobalFlagsSet; | |
52 DWORD CriticalSectionDefaultTimeout; | |
53 DWORD DeCommitFreeBlockThreshold; | |
54 DWORD DeCommitTotalFreeThreshold; | |
55 DWORD LockPrefixTable; | |
56 DWORD MaximumAllocationSize; | |
57 DWORD VirtualMemoryThreshold; | |
58 DWORD ProcessHeapFlags; | |
59 DWORD ProcessAffinityMask; | |
60 WORD CSDVersion; | |
61 WORD Reserved1; | |
62 DWORD EditList; | |
63 PUINT_PTR SecurityCookie; | |
64 PVOID *SEHandlerTable; | |
65 DWORD SEHandlerCount; | |
66 } IMAGE_LOAD_CONFIG_DIRECTORY32_2; | |
67 typedef IMAGE_LOAD_CONFIG_DIRECTORY32_2 IMAGE_LOAD_CONFIG_DIRECTORY_2; | |
68 #endif | |
69 | |
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; | |
78 | |
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". | |
83 // | |
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. | |
87 | |
88 extern "C" | |
89 const IMAGE_LOAD_CONFIG_DIRECTORY_2 _load_config_used = { | |
90 sizeof(IMAGE_LOAD_CONFIG_DIRECTORY_2), | |
91 0, // TimeDateStamp. | |
92 0, // MajorVersion. | |
93 0, // MinorVersion. | |
94 0, // GlobalFlagsClear. | |
95 0, // GlobalFlagsSet. | |
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. | |
104 0, // CSDVersion. | |
105 0, // Reserved1. | |
106 0 , // EditList. | |
107 #ifdef _WIN64 | |
108 (ULONGLONG)&__security_cookie, | |
109 #else | |
110 &__security_cookie, | |
111 __safe_se_handler_table, | |
112 (DWORD)(DWORD_PTR)&__safe_se_handler_count | |
113 #endif | |
114 }; | |
OLD | NEW |