{"thread":{"id":"48385","subject":"[PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation","startedAt":"2018-04-30T14:26:16Z","lastAt":"2018-05-02T06:55:57Z","messageCount":9,"participants":["Ben Peart","Duy Nguyen","Eric Sunshine","Stefan Beller","Johannes Sixt","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"346148","messageId":"20180430142555.23260-1-benpeart@microsoft.com","threadId":"48385","inReplyTo":null,"subject":"[PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Ben Peart","fromEmail":"ben.peart@microsoft.com","sentAt":"2018-04-30T14:26:11Z","receivedAt":"2018-04-30T14:26:16Z","isPatch":true,"sender":{"key":"benpeart@microsoft.com","avatar":"https://avatars.githubusercontent.com/u/15252029?v=4"},"body":"Take advantage of the recent addition of support for lazy loading functions\non Windows to simplfy the loading of NtSetSystemInformation.\n\nSigned-off-by: Ben Peart <benpeart@microsoft.com>\n---\n\nNotes:\n    Base Ref: master\n    Web-Diff: https://github.com/benpeart/git/commit/6e6ce4a788\n    Checkout: git fetch https://github.com/benpeart/git test-drop-caches-v1 && git checkout 6e6ce4a788\n\n t/helper/test-drop-caches.c | 16 ++++------------\n 1 file changed, 4 insertions(+), 12 deletions(-)\n\ndiff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c\nindex 838760898b..dd41da1a2c 100644\n--- a/t/helper/test-drop-caches.c\n+++ b/t/helper/test-drop-caches.c\n@@ -1,5 +1,6 @@\n #include \"test-tool.h\"\n #include \"git-compat-util.h\"\n+#include \"lazyload.h\"\n \n #if defined(GIT_WINDOWS_NATIVE)\n \n@@ -82,8 +83,6 @@ static int cmd_dropcaches(void)\n {\n \tHANDLE hProcess = GetCurrentProcess();\n \tHANDLE hToken;\n-\tHMODULE ntdll;\n-\tDWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG);\n \tSYSTEM_MEMORY_LIST_COMMAND command;\n \tint status;\n \n@@ -95,14 +94,9 @@ static int cmd_dropcaches(void)\n \n \tCloseHandle(hToken);\n \n-\tntdll = LoadLibrary(\"ntdll.dll\");\n-\tif (!ntdll)\n-\t\treturn error(\"Can't load ntdll.dll, wrong Windows version?\");\n-\n-\tNtSetSystemInformation =\n-\t\t(DWORD(WINAPI *)(INT, PVOID, ULONG))GetProcAddress(ntdll, \"NtSetSystemInformation\");\n-\tif (!NtSetSystemInformation)\n-\t\treturn error(\"Can't get function addresses, wrong Windows version?\");\n+\tDECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);\n+\tif (!INIT_PROC_ADDR(NtSetSystemInformation))\n+\t\treturn error(\"Could not find NtSetSystemInformation() function\");\n \n \tcommand = MemoryPurgeStandbyList;\n \tstatus = NtSetSystemInformation(\n@@ -115,8 +109,6 @@ static int cmd_dropcaches(void)\n \telse if (status != STATUS_SUCCESS)\n \t\terror(\"Unable to execute the memory list command %d\", status);\n \n-\tFreeLibrary(ntdll);\n-\n \treturn status;\n }\n \n\nbase-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d\n-- \n2.17.0.windows.1\n\n"},{"id":"346151","messageId":"CACsJy8CY1fNY9OPq9nisDC3X93QXjntre-vFgQ0OeuO=B0YV=Q@mail.gmail.com","threadId":"48385","inReplyTo":"20180430142555.23260-1-benpeart@microsoft.com","subject":"Re: [PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-04-30T14:57:04Z","receivedAt":"2018-04-30T14:57:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Apr 30, 2018 at 4:26 PM, Ben Peart <Ben.Peart@microsoft.com> wrote:\n> Take advantage of the recent addition of support for lazy loading functions\n> on Windows to simplfy the loading of NtSetSystemInformation.\n>\n> Signed-off-by: Ben Peart <benpeart@microsoft.com>\n> ---\n>\n> Notes:\n>     Base Ref: master\n>     Web-Diff: https://github.com/benpeart/git/commit/6e6ce4a788\n>     Checkout: git fetch https://github.com/benpeart/git test-drop-caches-v1 && git checkout 6e6ce4a788\n>\n>  t/helper/test-drop-caches.c | 16 ++++------------\n>  1 file changed, 4 insertions(+), 12 deletions(-)\n>\n> diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c\n> index 838760898b..dd41da1a2c 100644\n> --- a/t/helper/test-drop-caches.c\n> +++ b/t/helper/test-drop-caches.c\n> @@ -1,5 +1,6 @@\n>  #include \"test-tool.h\"\n>  #include \"git-compat-util.h\"\n> +#include \"lazyload.h\"\n\nThis is in compat/win32, should it be inside the \"if defined\n(GIT_WINDOWS_NATIVE)\" block instead of here?\n\n>\n>  #if defined(GIT_WINDOWS_NATIVE)\n>\n> @@ -82,8 +83,6 @@ static int cmd_dropcaches(void)\n>  {\n>         HANDLE hProcess = GetCurrentProcess();\n>         HANDLE hToken;\n> -       HMODULE ntdll;\n> -       DWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG);\n>         SYSTEM_MEMORY_LIST_COMMAND command;\n>         int status;\n>\n> @@ -95,14 +94,9 @@ static int cmd_dropcaches(void)\n>\n>         CloseHandle(hToken);\n>\n> -       ntdll = LoadLibrary(\"ntdll.dll\");\n> -       if (!ntdll)\n> -               return error(\"Can't load ntdll.dll, wrong Windows version?\");\n> -\n> -       NtSetSystemInformation =\n> -               (DWORD(WINAPI *)(INT, PVOID, ULONG))GetProcAddress(ntdll, \"NtSetSystemInformation\");\n> -       if (!NtSetSystemInformation)\n> -               return error(\"Can't get function addresses, wrong Windows version?\");\n> +       DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);\n> +       if (!INIT_PROC_ADDR(NtSetSystemInformation))\n> +               return error(\"Could not find NtSetSystemInformation() function\");\n>\n>         command = MemoryPurgeStandbyList;\n>         status = NtSetSystemInformation(\n> @@ -115,8 +109,6 @@ static int cmd_dropcaches(void)\n>         else if (status != STATUS_SUCCESS)\n>                 error(\"Unable to execute the memory list command %d\", status);\n>\n> -       FreeLibrary(ntdll);\n> -\n>         return status;\n>  }\n>\n>\n> base-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d\n> --\n> 2.17.0.windows.1\n>\n\n\n\n-- \nDuy\n"},{"id":"346153","messageId":"c05d652d-3275-4b04-c350-452e1c409493@gmail.com","threadId":"48385","inReplyTo":"CACsJy8CY1fNY9OPq9nisDC3X93QXjntre-vFgQ0OeuO=B0YV=Q@mail.gmail.com","subject":"Re: [PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Ben Peart","fromEmail":"peartben@gmail.com","sentAt":"2018-04-30T15:17:53Z","receivedAt":"2018-04-30T15:17:57Z","isPatch":true,"sender":{"key":"benpeart@microsoft.com","avatar":"https://avatars.githubusercontent.com/u/15252029?v=4"},"body":"\n\nOn 4/30/2018 10:57 AM, Duy Nguyen wrote:\n> On Mon, Apr 30, 2018 at 4:26 PM, Ben Peart <Ben.Peart@microsoft.com> wrote:\n>> Take advantage of the recent addition of support for lazy loading functions\n>> on Windows to simplfy the loading of NtSetSystemInformation.\n>>\n>> Signed-off-by: Ben Peart <benpeart@microsoft.com>\n>> ---\n>>\n>> Notes:\n>>      Base Ref: master\n>>      Web-Diff: https://github.com/benpeart/git/commit/6e6ce4a788\n>>      Checkout: git fetch https://github.com/benpeart/git test-drop-caches-v1 && git checkout 6e6ce4a788\n>>\n>>   t/helper/test-drop-caches.c | 16 ++++------------\n>>   1 file changed, 4 insertions(+), 12 deletions(-)\n>>\n>> diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c\n>> index 838760898b..dd41da1a2c 100644\n>> --- a/t/helper/test-drop-caches.c\n>> +++ b/t/helper/test-drop-caches.c\n>> @@ -1,5 +1,6 @@\n>>   #include \"test-tool.h\"\n>>   #include \"git-compat-util.h\"\n>> +#include \"lazyload.h\"\n> \n> This is in compat/win32, should it be inside the \"if defined\n> (GIT_WINDOWS_NATIVE)\" block instead of here?\n> \n\nYes, that does make sense.  No other platform will need/want it.  I'll \nwait to see if there is any other feedback and will submit an updated \npatch.  Thanks for the catch.\n"},{"id":"346179","messageId":"CAPig+cQPk9hj2JqOqFiZmb=Xcdi9P4dy7WUeJaj4AaUUMs10HQ@mail.gmail.com","threadId":"48385","inReplyTo":"20180430142555.23260-1-benpeart@microsoft.com","subject":"Re: [PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-30T17:05:16Z","receivedAt":"2018-04-30T17:05:20Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Apr 30, 2018 at 10:26 AM, Ben Peart <Ben.Peart@microsoft.com> wrote:\n> Take advantage of the recent addition of support for lazy loading functions\n> on Windows to simplfy the loading of NtSetSystemInformation.\n\ns/simplfy/simplify/\n\n> Signed-off-by: Ben Peart <benpeart@microsoft.com>\n"},{"id":"346183","messageId":"CAGZ79kZvyFTKadjY11Xu+KcV9OUe-4hbjgPzBDcD52X2nZKCzg@mail.gmail.com","threadId":"48385","inReplyTo":"20180430142555.23260-1-benpeart@microsoft.com","subject":"Re: [PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-04-30T18:12:13Z","receivedAt":"2018-04-30T18:12:18Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Apr 30, 2018 at 7:26 AM, Ben Peart <Ben.Peart@microsoft.com> wrote:\n> Take advantage of the recent addition of support for lazy loading functions\n\nCare to specify \"recent additions\"? Are these in Git code or somewhere else?\n\nI find this alias handy, as then I can describe commits\nin commit messages via \"git gcs <commitish>\n\n  alias.gcs=show --date=short -s --pretty='format:%h (%s, %ad)'\n\nThanks,\nStefan\n"},{"id":"346185","messageId":"92ff364a-b46c-2274-a3fd-0b68eaa4159e@gmail.com","threadId":"48385","inReplyTo":"CAGZ79kZvyFTKadjY11Xu+KcV9OUe-4hbjgPzBDcD52X2nZKCzg@mail.gmail.com","subject":"Re: [PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Ben Peart","fromEmail":"peartben@gmail.com","sentAt":"2018-04-30T18:43:31Z","receivedAt":"2018-04-30T18:43:35Z","isPatch":true,"sender":{"key":"benpeart@microsoft.com","avatar":"https://avatars.githubusercontent.com/u/15252029?v=4"},"body":"\n\nOn 4/30/2018 2:12 PM, Stefan Beller wrote:\n> On Mon, Apr 30, 2018 at 7:26 AM, Ben Peart <Ben.Peart@microsoft.com> wrote:\n>> Take advantage of the recent addition of support for lazy loading functions\n> \n> Care to specify \"recent additions\"? Are these in Git code or somewhere else?\n> \n> I find this alias handy, as then I can describe commits\n> in commit messages via \"git gcs <commitish>\n> \n>    alias.gcs=show --date=short -s --pretty='format:%h (%s, %ad)'\n> \n> Thanks,\n> Stefan\n> \n\nI guess \"recent\" is relative. :)\n\ndb2f7c48cb (Win32: simplify loading of DLL functions, 2017-09-25)\n"},{"id":"346187","messageId":"2c785509-8e9f-816b-9ab0-3ff2f3e4a3f3@kdbg.org","threadId":"48385","inReplyTo":"20180430142555.23260-1-benpeart@microsoft.com","subject":"Re: [PATCH v1] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2018-04-30T19:21:48Z","receivedAt":"2018-04-30T19:21:53Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 30.04.2018 um 16:26 schrieb Ben Peart:\n> @@ -82,8 +83,6 @@ static int cmd_dropcaches(void)\n>   {\n>   \tHANDLE hProcess = GetCurrentProcess();\n>   \tHANDLE hToken;\n> -\tHMODULE ntdll;\n> -\tDWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG);\n>   \tSYSTEM_MEMORY_LIST_COMMAND command;\n>   \tint status;\n>   \n> @@ -95,14 +94,9 @@ static int cmd_dropcaches(void)\n>   \n>   \tCloseHandle(hToken);\n>   \n> -\tntdll = LoadLibrary(\"ntdll.dll\");\n> -\tif (!ntdll)\n> -\t\treturn error(\"Can't load ntdll.dll, wrong Windows version?\");\n> -\n> -\tNtSetSystemInformation =\n> -\t\t(DWORD(WINAPI *)(INT, PVOID, ULONG))GetProcAddress(ntdll, \"NtSetSystemInformation\");\n> -\tif (!NtSetSystemInformation)\n> -\t\treturn error(\"Can't get function addresses, wrong Windows version?\");\n> +\tDECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);\n\nThis is a declaration-after-statement. Even though this is not in \ngeneric code, it is all too easy to trigger a warning from GCC if a \ncorresponding warning is turned on.\n\n> +\tif (!INIT_PROC_ADDR(NtSetSystemInformation))\n> +\t\treturn error(\"Could not find NtSetSystemInformation() function\");\n>   \n>   \tcommand = MemoryPurgeStandbyList;\n>   \tstatus = NtSetSystemInformation(\n> @@ -115,8 +109,6 @@ static int cmd_dropcaches(void)\n>   \telse if (status != STATUS_SUCCESS)\n>   \t\terror(\"Unable to execute the memory list command %d\", status);\n>   \n> -\tFreeLibrary(ntdll);\n> -\n>   \treturn status;\n>   }\n\n-- Hannes\n"},{"id":"346270","messageId":"20180501124603.21896-1-benpeart@microsoft.com","threadId":"48385","inReplyTo":"20180430142555.23260-1-benpeart@microsoft.com","subject":"[PATCH v2] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Ben Peart","fromEmail":"ben.peart@microsoft.com","sentAt":"2018-05-01T12:46:22Z","receivedAt":"2018-05-01T12:46:28Z","isPatch":true,"sender":{"key":"benpeart@microsoft.com","avatar":"https://avatars.githubusercontent.com/u/15252029?v=4"},"body":"Take advantage of the recent addition of support for lazy loading functions[1]\non Windows to simplify the loading of NtSetSystemInformation.\n\n[1] db2f7c48cb (Win32: simplify loading of DLL functions, 2017-09-25)\n\nSigned-off-by: Ben Peart <benpeart@microsoft.com>\n---\n\nNotes:\n    Base Ref: master\n    Web-Diff: https://github.com/benpeart/git/commit/3c9974548a\n    Checkout: git fetch https://github.com/benpeart/git test-drop-caches-v2 && git checkout 3c9974548a\n    \n    ### Interdiff (v1..v2):\n    \n    diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c\n    index dd41da1a2c..d6bcfddf13 100644\n    --- a/t/helper/test-drop-caches.c\n    +++ b/t/helper/test-drop-caches.c\n    @@ -1,8 +1,8 @@\n     #include \"test-tool.h\"\n     #include \"git-compat-util.h\"\n    -#include \"lazyload.h\"\n    \n     #if defined(GIT_WINDOWS_NATIVE)\n    +#include \"lazyload.h\"\n    \n     static int cmd_sync(void)\n     {\n    @@ -83,6 +83,7 @@ static int cmd_dropcaches(void)\n     {\n     \tHANDLE hProcess = GetCurrentProcess();\n     \tHANDLE hToken;\n    +\tDECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);\n     \tSYSTEM_MEMORY_LIST_COMMAND command;\n     \tint status;\n    \n    @@ -94,7 +95,6 @@ static int cmd_dropcaches(void)\n    \n     \tCloseHandle(hToken);\n    \n    -\tDECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);\n     \tif (!INIT_PROC_ADDR(NtSetSystemInformation))\n     \t\treturn error(\"Could not find NtSetSystemInformation() function\");\n    \n    ### Patches\n\n t/helper/test-drop-caches.c | 16 ++++------------\n 1 file changed, 4 insertions(+), 12 deletions(-)\n\ndiff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c\nindex 838760898b..d6bcfddf13 100644\n--- a/t/helper/test-drop-caches.c\n+++ b/t/helper/test-drop-caches.c\n@@ -2,6 +2,7 @@\n #include \"git-compat-util.h\"\n \n #if defined(GIT_WINDOWS_NATIVE)\n+#include \"lazyload.h\"\n \n static int cmd_sync(void)\n {\n@@ -82,8 +83,7 @@ static int cmd_dropcaches(void)\n {\n \tHANDLE hProcess = GetCurrentProcess();\n \tHANDLE hToken;\n-\tHMODULE ntdll;\n-\tDWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG);\n+\tDECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);\n \tSYSTEM_MEMORY_LIST_COMMAND command;\n \tint status;\n \n@@ -95,14 +95,8 @@ static int cmd_dropcaches(void)\n \n \tCloseHandle(hToken);\n \n-\tntdll = LoadLibrary(\"ntdll.dll\");\n-\tif (!ntdll)\n-\t\treturn error(\"Can't load ntdll.dll, wrong Windows version?\");\n-\n-\tNtSetSystemInformation =\n-\t\t(DWORD(WINAPI *)(INT, PVOID, ULONG))GetProcAddress(ntdll, \"NtSetSystemInformation\");\n-\tif (!NtSetSystemInformation)\n-\t\treturn error(\"Can't get function addresses, wrong Windows version?\");\n+\tif (!INIT_PROC_ADDR(NtSetSystemInformation))\n+\t\treturn error(\"Could not find NtSetSystemInformation() function\");\n \n \tcommand = MemoryPurgeStandbyList;\n \tstatus = NtSetSystemInformation(\n@@ -115,8 +109,6 @@ static int cmd_dropcaches(void)\n \telse if (status != STATUS_SUCCESS)\n \t\terror(\"Unable to execute the memory list command %d\", status);\n \n-\tFreeLibrary(ntdll);\n-\n \treturn status;\n }\n \n\nbase-commit: 1f1cddd558b54bb0ce19c8ace353fd07b758510d\n-- \n2.17.0.windows.1\n\n"},{"id":"346431","messageId":"nycvar.QRO.7.76.6.1805020854550.73@tvgsbejvaqbjf.bet","threadId":"48385","inReplyTo":"20180501124603.21896-1-benpeart@microsoft.com","subject":"Re: [PATCH v2] test-drop-caches: simplify delay loading of NtSetSystemInformation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-05-02T06:55:38Z","receivedAt":"2018-05-02T06:55:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ben,\n\nOn Tue, 1 May 2018, Ben Peart wrote:\n\n> Take advantage of the recent addition of support for lazy loading functions[1]\n> on Windows to simplify the loading of NtSetSystemInformation.\n> \n> [1] db2f7c48cb (Win32: simplify loading of DLL functions, 2017-09-25)\n> \n> Signed-off-by: Ben Peart <benpeart@microsoft.com>\n> ---\n\nThank you for your diligence. I read over the code, and it is still good,\nso you can add an Acked-by: or Reviewed-by: (or Junio can).\n\nThanks,\nJohannes\n"}]}