git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johannes Sixt <j6t@kdbg.org>
Date
Apr 30, 2018, 19:21 UTC
Message-ID
<2c785509-8e9f-816b-9ab0-3ff2f3e4a3f3@kdbg.org>
In-Reply-To
<20180430142555.23260-1-benpeart@microsoft.com>
Am 30.04.2018 um 16:26 schrieb Ben Peart:
Show 22 quoted lines
> @@ -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.

Show 13 quoted lines
> +	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
Previous: Ben PeartNext: Ben Peart
Message 7 of 9 in “test-drop-caches: simplify delay loading of NtSetSystemInformation”
  1. test-drop-caches: simplify delay loading of NtSetSystemInformationBen Peart, Apr 30, 2018
  2. Duy NguyenApr 30, 2018
  3. Ben PeartApr 30, 2018
  4. Eric SunshineApr 30, 2018
  5. Stefan BellerApr 30, 2018
  6. Ben PeartApr 30, 2018
  7. Johannes SixtApr 30, 2018
  8. test-drop-caches: simplify delay loading of NtSetSystemInformationBen Peart, May 1, 2018
  9. Johannes SchindelinMay 2, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.