Thread (9 messages) 9 messages, 7 authors, 2018-05-02

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

From: Johannes Sixt <hidden>
Date: 2018-04-30 19:21:53

Am 30.04.2018 um 16:26 schrieb Ben Peart:
quoted hunk ↗ jump to hunk
@@ -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);
This is a declaration-after-statement. Even though this is not in 
generic code, it is all too easy to trigger a warning from GCC if a 
corresponding warning is turned on.
quoted hunk ↗ jump to hunk
+	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;
  }
-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help