[PATCH v2] test-drop-caches: simplify delay loading of NtSetSystemInformation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Take advantage of the recent addition of support for lazy loading functions[1]
on Windows to simplify the loading of NtSetSystemInformation.

[1] db2f7c48cb (Win32: simplify loading of DLL functions, 2017-09-25)

Signed-off-by: Ben Peart <benpeart@xxxxxxxxxxxxx>
---

Notes:
    Base Ref: master
    Web-Diff: https://github.com/benpeart/git/commit/3c9974548a
    Checkout: git fetch https://github.com/benpeart/git test-drop-caches-v2 && git checkout 3c9974548a
    
    ### Interdiff (v1..v2):
    
    diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
    index dd41da1a2c..d6bcfddf13 100644
    --- a/t/helper/test-drop-caches.c
    +++ b/t/helper/test-drop-caches.c
    @@ -1,8 +1,8 @@
     #include "test-tool.h"
     #include "git-compat-util.h"
    -#include "lazyload.h"
    
     #if defined(GIT_WINDOWS_NATIVE)
    +#include "lazyload.h"
    
     static int cmd_sync(void)
     {
    @@ -83,6 +83,7 @@ static int cmd_dropcaches(void)
     {
     	HANDLE hProcess = GetCurrentProcess();
     	HANDLE hToken;
    +	DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
     	SYSTEM_MEMORY_LIST_COMMAND command;
     	int status;
    
    @@ -94,7 +95,6 @@ static int cmd_dropcaches(void)
    
     	CloseHandle(hToken);
    
    -	DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
     	if (!INIT_PROC_ADDR(NtSetSystemInformation))
     		return error("Could not find NtSetSystemInformation() function");
    
    ### Patches

 t/helper/test-drop-caches.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
index 838760898b..d6bcfddf13 100644
--- a/t/helper/test-drop-caches.c
+++ b/t/helper/test-drop-caches.c
@@ -2,6 +2,7 @@
 #include "git-compat-util.h"
 
 #if defined(GIT_WINDOWS_NATIVE)
+#include "lazyload.h"
 
 static int cmd_sync(void)
 {
@@ -82,8 +83,7 @@ static int cmd_dropcaches(void)
 {
 	HANDLE hProcess = GetCurrentProcess();
 	HANDLE hToken;
-	HMODULE ntdll;
-	DWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG);
+	DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
 	SYSTEM_MEMORY_LIST_COMMAND command;
 	int status;
 
@@ -95,14 +95,8 @@ static int cmd_dropcaches(void)
 
 	CloseHandle(hToken);
 
-	ntdll = LoadLibrary("ntdll.dll");
-	if (!ntdll)
-		return error("Can't load ntdll.dll, wrong Windows version?");
-
-	NtSetSystemInformation =
-		(DWORD(WINAPI *)(INT, PVOID, ULONG))GetProcAddress(ntdll, "NtSetSystemInformation");
-	if (!NtSetSystemInformation)
-		return error("Can't get function addresses, wrong Windows version?");
+	if (!INIT_PROC_ADDR(NtSetSystemInformation))
+		return error("Could not find NtSetSystemInformation() function");
 
 	command = MemoryPurgeStandbyList;
 	status = NtSetSystemInformation(
@@ -115,8 +109,6 @@ static int cmd_dropcaches(void)
 	else if (status != STATUS_SUCCESS)
 		error("Unable to execute the memory list command %d", status);
 
-	FreeLibrary(ntdll);
-
 	return status;
 }
 

base-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d
-- 
2.17.0.windows.1





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux