summaryrefslogtreecommitdiffstats
path: root/osdep/main-fn-win.c
diff options
context:
space:
mode:
Diffstat (limited to 'osdep/main-fn-win.c')
-rw-r--r--osdep/main-fn-win.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/osdep/main-fn-win.c b/osdep/main-fn-win.c
index 0d138f9c00..cf2df57289 100644
--- a/osdep/main-fn-win.c
+++ b/osdep/main-fn-win.c
@@ -1,16 +1,27 @@
#include <windows.h>
+#include <shellapi.h>
#ifndef BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE
#define BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE (0x0001)
#endif
-#include "config.h"
-
#include "common/common.h"
#include "osdep/io.h"
#include "osdep/terminal.h"
#include "osdep/main-fn.h"
+#ifndef HEAP_OPTIMIZE_RESOURCES_CURRENT_VERSION
+
+#define HEAP_OPTIMIZE_RESOURCES_CURRENT_VERSION 1
+#define HeapOptimizeResources ((HEAP_INFORMATION_CLASS)3)
+
+struct HEAP_OPTIMIZE_RESOURCES_INFORMATION {
+ DWORD Version;
+ DWORD Flags;
+};
+
+#endif
+
static bool is_valid_handle(HANDLE h)
{
return h != INVALID_HANDLE_VALUE && h != NULL &&
@@ -32,15 +43,18 @@ static void microsoft_nonsense(void)
// Enable heap corruption detection
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
- HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll");
- WINBOOL (WINAPI *pSetSearchPathMode)(DWORD Flags) =
- (WINBOOL (WINAPI *)(DWORD))GetProcAddress(kernel32, "SetSearchPathMode");
+ // Allow heap cache optimization and memory decommit
+ struct HEAP_OPTIMIZE_RESOURCES_INFORMATION heap_info = {
+ .Version = HEAP_OPTIMIZE_RESOURCES_CURRENT_VERSION
+ };
+ HeapSetInformation(NULL, HeapOptimizeResources, &heap_info,
+ sizeof(heap_info));
// Always use safe search paths for DLLs and other files, ie. never use the
// current directory
SetDllDirectoryW(L"");
- if (pSetSearchPathMode)
- pSetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE);
+ SetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE |
+ BASE_SEARCH_PATH_PERMANENT);
}
int main(int argc_, char **argv_)