git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation
@ 2018-04-30 14:26 Ben Peart
  2018-04-30 14:57 ` Duy Nguyen
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Ben Peart @ 2018-04-30 14:26 UTC (permalink / raw)
  To: git@vger.kernel.org
  Cc: pclouds@gmail.com, johannes.schindelin@gmx.de, Ben Peart

Take advantage of the recent addition of support for lazy loading functions
on Windows to simplfy the loading of NtSetSystemInformation.

Signed-off-by: Ben Peart <benpeart@microsoft.com>
---

Notes:
    Base Ref: master
    Web-Diff: https://github.com/benpeart/git/commit/6e6ce4a788
    Checkout: git fetch https://github.com/benpeart/git test-drop-caches-v1 && git checkout 6e6ce4a788

 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..dd41da1a2c 100644
--- a/t/helper/test-drop-caches.c
+++ b/t/helper/test-drop-caches.c
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "git-compat-util.h"
+#include "lazyload.h"
 
 #if defined(GIT_WINDOWS_NATIVE)
 
@@ -82,8 +83,6 @@ static int cmd_dropcaches(void)
 {
 	HANDLE hProcess = GetCurrentProcess();
 	HANDLE hToken;
-	HMODULE ntdll;
-	DWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG);
 	SYSTEM_MEMORY_LIST_COMMAND command;
 	int status;
 
@@ -95,14 +94,9 @@ 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?");
+	DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
+	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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-05-02  6:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-30 14:26 [PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation Ben Peart
2018-04-30 14:57 ` Duy Nguyen
2018-04-30 15:17   ` Ben Peart
2018-04-30 17:05 ` Eric Sunshine
2018-04-30 18:12 ` Stefan Beller
2018-04-30 18:43   ` Ben Peart
2018-04-30 19:21 ` Johannes Sixt
2018-05-01 12:46 ` [PATCH v2] " Ben Peart
2018-05-02  6:55   ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).