summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorIvan Zhakov <ivan@apache.org>2019-12-09 10:22:08 +0000
committerIvan Zhakov <ivan@apache.org>2019-12-09 10:22:08 +0000
commitd5f961e6c40af43e0a3e1edf3005a661edb38075 (patch)
tree97e9784bf12f952db6f40a21f3176a6c9ebe01aa /misc
parent14a7f562d6915142b4f870859881725b217a7ef9 (diff)
downloadapr-d5f961e6c40af43e0a3e1edf3005a661edb38075.tar.gz
win32: Try to avoid loading shell32.dll whenever possible:
1. shell32.dll has about 19 dependencies. 2. shell32.dll depends on user32/gdi32.dll and loading them makes the process a "GUI" process: - this slows down process initialization and shutdown [1] - doesn't allow enabling mitigation to block win32k.sys for process using APR. 3. shell32.dll is not available on Windows Nano Server The only used function from shell32.dll is CommandLineToArgW. It is used to parse command-line arguments in apr_app_initialize(). The solution is twofold: 1. Delay loading shell32.dll. 2. Prefer to use api-ms-win-downlevel-shell32-l1-1-0.dll API Set instead of shell32.dll (Windows 8+) * include/arch/win32/apr_arch_misc.h (apr_dlltoken_e): Add DLL_API_MS_WIN_DOWNLEVEL_SHELL32_L1_1_0. (CommandLineToArgvW): Add late late dll func for CommandLineToArgvW. * misc/win32/misc.c (load_dll_callback): Support API Sets. * misc/win32/start.c (apr_app_initialize): Use apr_winapi_CommandLineToArgvW() instead of CommandLineToArgvW(). [1] https://randomascii.wordpress.com/2018/12/03/a-not-called-function-can-cause-a-5x-slowdown/ git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1871082 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r--misc/win32/misc.c27
-rw-r--r--misc/win32/start.c2
2 files changed, 20 insertions, 9 deletions
diff --git a/misc/win32/misc.c b/misc/win32/misc.c
index 910b0b41e..5136b9336 100644
--- a/misc/win32/misc.c
+++ b/misc/win32/misc.c
@@ -136,18 +136,21 @@ apr_status_t apr_get_oslevel(apr_oslevel_e *level)
typedef struct win32_late_dll_t {
INIT_ONCE control;
+ const apr_wchar_t *apiset_name;
const apr_wchar_t *dll_name;
HMODULE dll_handle;
} win32_late_dll_t;
static win32_late_dll_t late_dll[DLL_defined] = {
- {INIT_ONCE_STATIC_INIT, L"kernel32", NULL},
- {INIT_ONCE_STATIC_INIT, L"advapi32", NULL},
- {INIT_ONCE_STATIC_INIT, L"mswsock", NULL},
- {INIT_ONCE_STATIC_INIT, L"ws2_32", NULL},
- {INIT_ONCE_STATIC_INIT, L"shell32", NULL},
- {INIT_ONCE_STATIC_INIT, L"ntdll.dll", NULL},
- {INIT_ONCE_STATIC_INIT, L"Iphplapi", NULL}
+ {INIT_ONCE_STATIC_INIT, NULL, L"kernel32", NULL},
+ {INIT_ONCE_STATIC_INIT, NULL, L"advapi32", NULL},
+ {INIT_ONCE_STATIC_INIT, NULL, L"mswsock", NULL},
+ {INIT_ONCE_STATIC_INIT, NULL, L"ws2_32", NULL},
+ {INIT_ONCE_STATIC_INIT, NULL, L"shell32", NULL},
+ {INIT_ONCE_STATIC_INIT, NULL, L"ntdll.dll", NULL},
+ {INIT_ONCE_STATIC_INIT, NULL, L"Iphplapi", NULL},
+ {INIT_ONCE_STATIC_INIT, L"api-ms-win-downlevel-shell32-l1-1-0.dll",
+ L"shell32", NULL}
};
static BOOL WINAPI load_dll_callback(PINIT_ONCE InitOnce,
@@ -156,7 +159,15 @@ static BOOL WINAPI load_dll_callback(PINIT_ONCE InitOnce,
{
win32_late_dll_t *dll = Parameter;
- dll->dll_handle = LoadLibraryW(dll->dll_name);
+ /* Try api set dll first if defined. */
+ if (dll->apiset_name) {
+ dll->dll_handle = LoadLibraryExW(dll->apiset_name, NULL,
+ LOAD_LIBRARY_SEARCH_SYSTEM32);
+ }
+
+ if (!dll->dll_handle) {
+ dll->dll_handle = LoadLibraryW(dll->dll_name);
+ }
return TRUE;
}
diff --git a/misc/win32/start.c b/misc/win32/start.c
index e84fb876a..df60283e1 100644
--- a/misc/win32/start.c
+++ b/misc/win32/start.c
@@ -124,7 +124,7 @@ APR_DECLARE(apr_status_t) apr_app_initialize(int *argc,
sysstr = GetCommandLineW();
if (sysstr) {
- wstrs = CommandLineToArgvW(sysstr, &wstrc);
+ wstrs = apr_winapi_CommandLineToArgvW(sysstr, &wstrc);
if (wstrs) {
*argc = apr_wastrtoastr(argv, wstrs, wstrc);
LocalFree(wstrs);