Skip to content

Commit 447ed83

Browse files
Ben Peartgitster
authored andcommitted
test-drop-caches: simplify delay loading of NtSetSystemInformation
Take advantage of the recent addition of support for lazy loading functions[1] on Windows to simplify the loading of NtSetSystemInformation. [1] db2f7c4 (Win32: simplify loading of DLL functions, 2017-09-25) Signed-off-by: Ben Peart <[email protected]> Reviewed-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f1cddd commit 447ed83

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

t/helper/test-drop-caches.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "git-compat-util.h"
33

44
#if defined(GIT_WINDOWS_NATIVE)
5+
#include "lazyload.h"
56

67
static int cmd_sync(void)
78
{
@@ -82,8 +83,7 @@ static int cmd_dropcaches(void)
8283
{
8384
HANDLE hProcess = GetCurrentProcess();
8485
HANDLE hToken;
85-
HMODULE ntdll;
86-
DWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG);
86+
DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
8787
SYSTEM_MEMORY_LIST_COMMAND command;
8888
int status;
8989

@@ -95,14 +95,8 @@ static int cmd_dropcaches(void)
9595

9696
CloseHandle(hToken);
9797

98-
ntdll = LoadLibrary("ntdll.dll");
99-
if (!ntdll)
100-
return error("Can't load ntdll.dll, wrong Windows version?");
101-
102-
NtSetSystemInformation =
103-
(DWORD(WINAPI *)(INT, PVOID, ULONG))GetProcAddress(ntdll, "NtSetSystemInformation");
104-
if (!NtSetSystemInformation)
105-
return error("Can't get function addresses, wrong Windows version?");
98+
if (!INIT_PROC_ADDR(NtSetSystemInformation))
99+
return error("Could not find NtSetSystemInformation() function");
106100

107101
command = MemoryPurgeStandbyList;
108102
status = NtSetSystemInformation(
@@ -115,8 +109,6 @@ static int cmd_dropcaches(void)
115109
else if (status != STATUS_SUCCESS)
116110
error("Unable to execute the memory list command %d", status);
117111

118-
FreeLibrary(ntdll);
119-
120112
return status;
121113
}
122114

0 commit comments

Comments
 (0)