From b89f79a4455e0a7f8abdfca41378f6f439d64a3b Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Mon, 13 May 2019 06:29:38 +0000 Subject: Use API constant instead of magic number. * threadproc/win32/threadpriv.c (apr_threadkey_private_create): Use TLS_OUT_OF_INDEXES instead of hardcoded 0xFFFFFFFF. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859171 13f79535-47bb-0310-9956-ffa450edef68 --- threadproc/win32/threadpriv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threadproc/win32/threadpriv.c b/threadproc/win32/threadpriv.c index 787c142c4..1cce0c667 100644 --- a/threadproc/win32/threadpriv.c +++ b/threadproc/win32/threadpriv.c @@ -32,7 +32,7 @@ APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key, (*key)->pool = pool; - if (((*key)->key = TlsAlloc()) != 0xFFFFFFFF) { + if (((*key)->key = TlsAlloc()) != TLS_OUT_OF_INDEXES) { return APR_SUCCESS; } return apr_get_os_error(); -- cgit v1.2.1 From 177221333ef3ce3a52dfc4a6d4ece933d024996f Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Mon, 13 May 2019 07:09:18 +0000 Subject: apr_dir_read: Do not request short file names on Windows 7 and later. This significantly improves directory listing performance on volumes with 8.3 filenames enabled (default for system volume). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859174 13f79535-47bb-0310-9956-ffa450edef68 --- file_io/win32/dir.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/file_io/win32/dir.c b/file_io/win32/dir.c index 8c8b74546..e4e3f7c73 100644 --- a/file_io/win32/dir.c +++ b/file_io/win32/dir.c @@ -128,6 +128,8 @@ APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted, if (thedir->dirhand == INVALID_HANDLE_VALUE) { apr_status_t rv; + FINDEX_INFO_LEVELS info_level; + if ((rv = utf8_to_unicode_path(wdirname, sizeof(wdirname) / sizeof(apr_wchar_t), thedir->dirname))) { @@ -136,7 +138,19 @@ APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted, eos = wcschr(wdirname, '\0'); eos[0] = '*'; eos[1] = '\0'; - thedir->dirhand = FindFirstFileW(wdirname, thedir->w.entry); + + /* Do not request short file names on Windows 7 and later. */ + if (apr_os_level >= APR_WIN_7) { + info_level = FindExInfoBasic; + } + else { + info_level = FindExInfoStandard; + } + + thedir->dirhand = FindFirstFileExW(wdirname, info_level, + thedir->w.entry, + FindExSearchNameMatch, NULL, + 0); eos[0] = '\0'; if (thedir->dirhand == INVALID_HANDLE_VALUE) { return apr_get_os_error(); -- cgit v1.2.1 From b90a57527bbbd2432d04b6644d81866d42194fb1 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Wed, 15 May 2019 06:00:13 +0000 Subject: win32: Use LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR flag for LoadLibraryExW in apr_dso() instead of calling SetDllDirectory(). SetDllDirectory() changes global state and using it may lead to security issues on race conditions. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859265 13f79535-47bb-0310-9956-ffa450edef68 --- dso/win32/dso.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/dso/win32/dso.c b/dso/win32/dso.c index 89885e5fa..a2ed9a419 100644 --- a/dso/win32/dso.c +++ b/dso/win32/dso.c @@ -79,17 +79,11 @@ APR_DECLARE(apr_status_t) apr_dso_load(struct apr_dso_handle_t **res_handle, os_handle = LoadLibraryExW(wpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (!os_handle) { #ifndef _WIN32_WCE - apr_wchar_t *ignored; - apr_wchar_t fpath[APR_PATH_MAX]; rv = apr_get_os_error(); - if (GetFullPathNameW(wpath, sizeof(fpath) / sizeof(apr_wchar_t), fpath, &ignored)) { - if (SetDllDirectoryW(fpath)) { - os_handle = LoadLibraryExW(wpath, NULL, 0); - if (!os_handle) - os_handle = LoadLibraryExW(wpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); - if (os_handle) - rv = APR_SUCCESS; - } + + os_handle = LoadLibraryExW(wpath, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); + if (os_handle) { + rv = APR_SUCCESS; } #else rv = apr_get_os_error(); -- cgit v1.2.1 From 09593ea30b69057e6d4fd1f89ece6dd802610c0e Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Wed, 15 May 2019 08:12:08 +0000 Subject: win32: Fix handle leak apr_shm_create() implementation. * shmem/win32/shm.c (can_create_global_maps): Close thread/process token after checking for privilege. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859270 13f79535-47bb-0310-9956-ffa450edef68 --- shmem/win32/shm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/shmem/win32/shm.c b/shmem/win32/shm.c index b01411ebd..0ca8247f9 100644 --- a/shmem/win32/shm.c +++ b/shmem/win32/shm.c @@ -87,10 +87,12 @@ static int can_create_global_maps(void) ok = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken); } - if (ok) { - ok = LookupPrivilegeValue(NULL, SE_CREATE_GLOBAL_NAME, &priv_id); + if (!ok) { + return 0; } + ok = LookupPrivilegeValue(NULL, SE_CREATE_GLOBAL_NAME, &priv_id); + if (ok) { privs.PrivilegeCount = 1; privs.Control = PRIVILEGE_SET_ALL_NECESSARY; @@ -99,6 +101,8 @@ static int can_create_global_maps(void) ok = PrivilegeCheck(hToken, &privs, &has_priv); } + CloseHandle(hToken); + if (ok && !has_priv) { return 0; } -- cgit v1.2.1 From e2af2e67aa91f4f22b9d5a1f6808c8de828c12fc Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Thu, 16 May 2019 08:15:34 +0000 Subject: win32: Check return value from apr_generate_random_bytes() in file_pipe_create(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859356 13f79535-47bb-0310-9956-ffa450edef68 --- file_io/win32/pipe.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/file_io/win32/pipe.c b/file_io/win32/pipe.c index 601458258..b13507a91 100644 --- a/file_io/win32/pipe.c +++ b/file_io/win32/pipe.c @@ -120,6 +120,7 @@ static apr_status_t file_pipe_create(apr_file_t **in, (void) apr_pollset_create(&(*out)->pollset, 1, p, 0); #endif if (apr_os_level >= APR_WIN_NT) { + apr_status_t rv; char rand[8]; int pid = getpid(); #define FMT_PIPE_NAME "\\\\.\\pipe\\apr-pipe-%x.%lx." @@ -150,7 +151,12 @@ static apr_status_t file_pipe_create(apr_file_t **in, } dwPipeMode = 0; - apr_generate_random_bytes(rand, sizeof rand); + rv = apr_generate_random_bytes(rand, sizeof rand); + if (rv != APR_SUCCESS) { + file_cleanup(*in); + return rv; + } + pos = apr_snprintf(name, sizeof name, FMT_PIPE_NAME, pid, id++); apr_escape_hex(name + pos, rand, sizeof rand, 0, NULL); @@ -163,7 +169,7 @@ static apr_status_t file_pipe_create(apr_file_t **in, 1, /* nDefaultTimeOut, */ &sa); if ((*in)->filehand == INVALID_HANDLE_VALUE) { - apr_status_t rv = apr_get_os_error(); + rv = apr_get_os_error(); file_cleanup(*in); return rv; } -- cgit v1.2.1 From 39c1e22fe535ab0ee0134539c3fcc6b08529e2a6 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Thu, 16 May 2019 16:25:15 +0000 Subject: * test/testbuckest.c (flatten_match): Fix error message (thanks to gcc warning). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859391 13f79535-47bb-0310-9956-ffa450edef68 --- test/testbuckets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testbuckets.c b/test/testbuckets.c index 077a13936..31bed0c1b 100644 --- a/test/testbuckets.c +++ b/test/testbuckets.c @@ -105,7 +105,7 @@ static void flatten_match(abts_case *tc, const char *ctx, sprintf(msg, "%s: length match (%ld not %ld)", ctx, (long)len, (long)elen); ABTS_ASSERT(tc, msg, len == elen); - sprintf(msg, "%s: result match", msg); + sprintf(msg, "%s: result match", ctx); ABTS_STR_NEQUAL(tc, expect, buf, len); free(buf); } -- cgit v1.2.1 From 861d816d08dae076b26ff875031fcbc3326e4493 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Thu, 16 May 2019 18:11:27 +0000 Subject: Fix issue 61109: Use LocalFree() instead of GlobalFree() to free result of CommandLineToArgvW(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859402 13f79535-47bb-0310-9956-ffa450edef68 --- misc/win32/start.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/win32/start.c b/misc/win32/start.c index 2d7b5ff8f..ea8b964ac 100644 --- a/misc/win32/start.c +++ b/misc/win32/start.c @@ -127,7 +127,7 @@ APR_DECLARE(apr_status_t) apr_app_initialize(int *argc, wstrs = CommandLineToArgvW(sysstr, &wstrc); if (wstrs) { *argc = apr_wastrtoastr(argv, wstrs, wstrc); - GlobalFree(wstrs); + LocalFree(wstrs); } } -- cgit v1.2.1 From 47738d0dfd83b8be3f05e309e18216cdbbccd966 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Thu, 16 May 2019 19:01:28 +0000 Subject: Refactoring: Combine lateDllName and lateDllHandle arrays to one array of structures. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859404 13f79535-47bb-0310-9956-ffa450edef68 --- misc/win32/misc.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/misc/win32/misc.c b/misc/win32/misc.c index 7a80f4fe9..88d9ab381 100644 --- a/misc/win32/misc.c +++ b/misc/win32/misc.c @@ -138,32 +138,40 @@ apr_status_t apr_get_oslevel(apr_oslevel_e *level) * missing from one or more releases of the Win32 API */ -static const char* const lateDllName[DLL_defined] = { - "kernel32", "advapi32", "mswsock", "ws2_32", "shell32", "ntdll.dll", - "Iphplapi" }; -static HMODULE lateDllHandle[DLL_defined] = { - NULL, NULL, NULL, NULL, NULL, NULL, - NULL }; +typedef struct win32_late_dll_t { + const char *dll_name; + HMODULE dll_handle; +} win32_late_dll_t; + +static win32_late_dll_t late_dll[DLL_defined] = { + {"kernel32", NULL}, + {"advapi32", NULL}, + {"mswsock", NULL}, + {"ws2_32", NULL}, + {"shell32", NULL}, + {"ntdll.dll", NULL}, + {"Iphplapi", NULL} +}; FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char* fnName, int ordinal) { - if (!lateDllHandle[fnLib]) { - lateDllHandle[fnLib] = LoadLibraryA(lateDllName[fnLib]); - if (!lateDllHandle[fnLib]) + if (!late_dll[fnLib].dll_handle) { + late_dll[fnLib].dll_handle = LoadLibraryA(late_dll[fnLib].dll_name); + if (!late_dll[fnLib].dll_handle) return NULL; } #if defined(_WIN32_WCE) if (ordinal) - return GetProcAddressA(lateDllHandle[fnLib], (const char *) - (apr_ssize_t)ordinal); + return GetProcAddressA(late_dll[fnLib].dll_handle, + (const char *) (apr_ssize_t)ordinal); else - return GetProcAddressA(lateDllHandle[fnLib], fnName); + return GetProcAddressA(late_dll[fnLib].dll_handle, fnName); #else if (ordinal) - return GetProcAddress(lateDllHandle[fnLib], (const char *) - (apr_ssize_t)ordinal); + return GetProcAddress(late_dll[fnLib].dll_handle, + (const char *) (apr_ssize_t)ordinal); else - return GetProcAddress(lateDllHandle[fnLib], fnName); + return GetProcAddress(late_dll[fnLib].dll_handle, fnName); #endif } -- cgit v1.2.1 From 2abbb4ca13ba8de44d06e40eddad1b4c1c3f8a49 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Thu, 16 May 2019 19:03:58 +0000 Subject: win32: Use LoadLibraryW() instead of LoadLibraryA() to late load libraries. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859405 13f79535-47bb-0310-9956-ffa450edef68 --- misc/win32/misc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/misc/win32/misc.c b/misc/win32/misc.c index 88d9ab381..ff9c076ab 100644 --- a/misc/win32/misc.c +++ b/misc/win32/misc.c @@ -139,24 +139,24 @@ apr_status_t apr_get_oslevel(apr_oslevel_e *level) */ typedef struct win32_late_dll_t { - const char *dll_name; + const apr_wchar_t *dll_name; HMODULE dll_handle; } win32_late_dll_t; static win32_late_dll_t late_dll[DLL_defined] = { - {"kernel32", NULL}, - {"advapi32", NULL}, - {"mswsock", NULL}, - {"ws2_32", NULL}, - {"shell32", NULL}, - {"ntdll.dll", NULL}, - {"Iphplapi", NULL} + {L"kernel32", NULL}, + {L"advapi32", NULL}, + {L"mswsock", NULL}, + {L"ws2_32", NULL}, + {L"shell32", NULL}, + {L"ntdll.dll", NULL}, + {L"Iphplapi", NULL} }; FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char* fnName, int ordinal) { if (!late_dll[fnLib].dll_handle) { - late_dll[fnLib].dll_handle = LoadLibraryA(late_dll[fnLib].dll_name); + late_dll[fnLib].dll_handle = LoadLibraryW(late_dll[fnLib].dll_name); if (!late_dll[fnLib].dll_handle) return NULL; } -- cgit v1.2.1 From 51ffaca14d1439e028e76e03c58982111fb9a887 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sat, 18 May 2019 19:31:24 +0000 Subject: win32: Use SetFilePointerEx() instead of SetFilePointer(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859473 13f79535-47bb-0310-9956-ffa450edef68 --- file_io/win32/seek.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/file_io/win32/seek.c b/file_io/win32/seek.c index dfef57716..34b47b5eb 100644 --- a/file_io/win32/seek.c +++ b/file_io/win32/seek.c @@ -23,7 +23,6 @@ static apr_status_t setptr(apr_file_t *thefile, apr_off_t pos ) { apr_off_t newbufpos; apr_status_t rv; - DWORD rc; if (thefile->direction == 1) { /* XXX: flush here is not mutex protected */ @@ -43,19 +42,15 @@ static apr_status_t setptr(apr_file_t *thefile, apr_off_t pos ) thefile->bufpos = (apr_size_t)newbufpos; rv = APR_SUCCESS; } else { - DWORD offlo = (DWORD)pos; - LONG offhi = (LONG)(pos >> 32); - rc = SetFilePointer(thefile->filehand, offlo, &offhi, FILE_BEGIN); - - if (rc == (DWORD)-1) - /* A legal value, perhaps? MSDN implies prior SetLastError isn't - * needed, googling for SetLastError SetFilePointer seems - * to confirm this. INVALID_SET_FILE_POINTER is too recently - * added for us to rely on it as a constant. - */ + LARGE_INTEGER li; + li.QuadPart = pos; + + if (!SetFilePointerEx(thefile->filehand, li, NULL, FILE_BEGIN)) { rv = apr_get_os_error(); - else + } + else { rv = APR_SUCCESS; + } if (rv == APR_SUCCESS) { rv = APR_SUCCESS; @@ -127,8 +122,8 @@ APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t wh } else { DWORD howmove; - DWORD offlo = (DWORD)*offset; - DWORD offhi = (DWORD)(*offset >> 32); + LARGE_INTEGER li; + li.QuadPart = offset; switch(where) { case APR_SET: @@ -140,15 +135,17 @@ APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t wh default: return APR_EINVAL; } - offlo = SetFilePointer(thefile->filehand, (LONG)offlo, - (LONG*)&offhi, howmove); - if (offlo == 0xFFFFFFFF) + + if (!SetFilePointerEx(thefile->filehand, li, &li, howmove)) { rc = apr_get_os_error(); - else + } + else { rc = APR_SUCCESS; + } + /* Since we can land at 0xffffffff we will measure our APR_SUCCESS */ if (rc == APR_SUCCESS) - *offset = ((apr_off_t)offhi << 32) | offlo; + *offset = li.QuadPart; return rc; } } @@ -157,9 +154,7 @@ APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t wh APR_DECLARE(apr_status_t) apr_file_trunc(apr_file_t *thefile, apr_off_t offset) { apr_status_t rv; - DWORD offlo = (DWORD)offset; - LONG offhi = (LONG)(offset >> 32); - DWORD rc; + LARGE_INTEGER li; if (thefile->buffered) { if (thefile->direction == 1) { @@ -188,10 +183,10 @@ APR_DECLARE(apr_status_t) apr_file_trunc(apr_file_t *thefile, apr_off_t offset) } } - rc = SetFilePointer(thefile->filehand, offlo, &offhi, FILE_BEGIN); - if (rc == 0xFFFFFFFF) - if ((rv = apr_get_os_error()) != APR_SUCCESS) - return rv; + li.QuadPart = offset; + if (!SetFilePointerEx(thefile->filehand, li, NULL, FILE_BEGIN)) + return apr_get_os_error(); + thefile->filePtr = offset; /* Don't report EOF until the next read. */ thefile->eof_hit = 0; -- cgit v1.2.1 From db1fee72187395c87b5a70372a47243d508ec1e2 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sat, 18 May 2019 19:36:29 +0000 Subject: The minimum supported Windows OS versions are now Windows 7 / Windows Server 2008 R2. See also: https://lists.apache.org/thread.html/de5af5247324db3e0636a654f2c23d3ff3a94a91f9d35adf5402b927@%3Cdev.apr.apache.org%3E git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859474 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index 18dc42dec..743938bd9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes for APR 2.0.0 + *) Windows platform: Remove support for Windows 2000, XP, Vista. The minimum + supported OS versions are now Windows 7 / Windows Server 2008 R2. + *) apr_file_info: [Win32 only] Treat only "name surrogate" reparse points as symlinks, and not other reparse tag types. PR47630 [Oleg Liatte ] -- cgit v1.2.1 From bba7ae5db7525970b4d24edab977606ba268b9af Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sat, 18 May 2019 19:39:12 +0000 Subject: win32: Do not use delay load for GetCompressedFileSize() and SetDllDirectoryW() since there always available on all supported platforms. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859475 13f79535-47bb-0310-9956-ffa450edef68 --- include/arch/win32/apr_arch_misc.h | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/include/arch/win32/apr_arch_misc.h b/include/arch/win32/apr_arch_misc.h index b872b6ce5..2cf1c6545 100644 --- a/include/arch/win32/apr_arch_misc.h +++ b/include/arch/win32/apr_arch_misc.h @@ -230,27 +230,6 @@ FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char *fnName, int ordinal); * these we must always look up */ -#ifdef GetCompressedFileSizeA -#undef GetCompressedFileSizeA -#endif -APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, DWORD, WINAPI, GetCompressedFileSizeA, 0, ( - IN LPCSTR lpFileName, - OUT LPDWORD lpFileSizeHigh), - (lpFileName, lpFileSizeHigh)); -#define GetCompressedFileSizeA apr_winapi_GetCompressedFileSizeA -#undef GetCompressedFileSize -#define GetCompressedFileSize apr_winapi_GetCompressedFileSizeA - -#ifdef GetCompressedFileSizeW -#undef GetCompressedFileSizeW -#endif -APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, DWORD, WINAPI, GetCompressedFileSizeW, 0, ( - IN LPCWSTR lpFileName, - OUT LPDWORD lpFileSizeHigh), - (lpFileName, lpFileSizeHigh)); -#define GetCompressedFileSizeW apr_winapi_GetCompressedFileSizeW - - APR_DECLARE_LATE_DLL_FUNC(DLL_NTDLL, LONG, WINAPI, NtQueryTimerResolution, 0, ( ULONG *pMaxRes, /* Minimum NS Resolution */ ULONG *pMinRes, /* Maximum NS Resolution */ @@ -353,14 +332,6 @@ APR_DECLARE_LATE_DLL_FUNC(DLL_WINSOCK2API, int, WSAAPI, WSAPoll, 0, ( #define WSAPoll apr_winapi_WSAPoll #define HAVE_POLL 1 -#ifdef SetDllDirectoryW -#undef SetDllDirectoryW -#endif -APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, SetDllDirectoryW, 0, ( - IN LPCWSTR lpPathName), - (lpPathName)); -#define SetDllDirectoryW apr_winapi_SetDllDirectoryW - #ifdef if_nametoindex #undef if_nametoindex #endif -- cgit v1.2.1 From 01eaac5ec9a01e290ac9ff4061197587a0121309 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sat, 18 May 2019 19:51:18 +0000 Subject: Follow-up to r1859473: Fix stupid typo: use *OFFSET instead of OFFSET in apr_file_seek() on Windows. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859476 13f79535-47bb-0310-9956-ffa450edef68 --- file_io/win32/seek.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file_io/win32/seek.c b/file_io/win32/seek.c index 34b47b5eb..673c6f578 100644 --- a/file_io/win32/seek.c +++ b/file_io/win32/seek.c @@ -123,7 +123,7 @@ APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t wh else { DWORD howmove; LARGE_INTEGER li; - li.QuadPart = offset; + li.QuadPart = *offset; switch(where) { case APR_SET: -- cgit v1.2.1 From 61b8d28c1e008c11fc99004af97e74b9c6123889 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sat, 18 May 2019 19:58:02 +0000 Subject: win32: Use INIT_ONCE to prevent loading delayed libraries multiple times. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859477 13f79535-47bb-0310-9956-ffa450edef68 --- misc/win32/misc.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/misc/win32/misc.c b/misc/win32/misc.c index ff9c076ab..b6ee202b0 100644 --- a/misc/win32/misc.c +++ b/misc/win32/misc.c @@ -139,39 +139,52 @@ apr_status_t apr_get_oslevel(apr_oslevel_e *level) */ typedef struct win32_late_dll_t { + INIT_ONCE control; const apr_wchar_t *dll_name; HMODULE dll_handle; } win32_late_dll_t; static win32_late_dll_t late_dll[DLL_defined] = { - {L"kernel32", NULL}, - {L"advapi32", NULL}, - {L"mswsock", NULL}, - {L"ws2_32", NULL}, - {L"shell32", NULL}, - {L"ntdll.dll", NULL}, - {L"Iphplapi", NULL} + {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} }; +static BOOL WINAPI load_dll_callback(PINIT_ONCE InitOnce, + PVOID Parameter, + PVOID *Context) +{ + win32_late_dll_t *dll = Parameter; + + dll->dll_handle = LoadLibraryW(dll->dll_name); + + return TRUE; +} + FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char* fnName, int ordinal) { - if (!late_dll[fnLib].dll_handle) { - late_dll[fnLib].dll_handle = LoadLibraryW(late_dll[fnLib].dll_name); - if (!late_dll[fnLib].dll_handle) - return NULL; - } + win32_late_dll_t *dll = &late_dll[fnLib]; + + InitOnceExecuteOnce(&dll->control, load_dll_callback, dll, NULL); + if (!dll->dll_handle) + return NULL; + #if defined(_WIN32_WCE) if (ordinal) - return GetProcAddressA(late_dll[fnLib].dll_handle, + return GetProcAddressA(dll->dll_handle, (const char *) (apr_ssize_t)ordinal); else - return GetProcAddressA(late_dll[fnLib].dll_handle, fnName); + return GetProcAddressA(dll->dll_handle, fnName); #else if (ordinal) - return GetProcAddress(late_dll[fnLib].dll_handle, + return GetProcAddress(dll->dll_handle, (const char *) (apr_ssize_t)ordinal); else - return GetProcAddress(late_dll[fnLib].dll_handle, fnName); + return GetProcAddress(dll->dll_handle, fnName); #endif } -- cgit v1.2.1 From 662bb2544cc78ab849a9e9cb6132bde72db7403b Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sun, 19 May 2019 17:12:33 +0000 Subject: * include/apr.hw: Define _WIN32_WINNT to 0x0601 by default, since Windows 7 is minimum supported Windows version. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859513 13f79535-47bb-0310-9956-ffa450edef68 --- include/apr.hw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/apr.hw b/include/apr.hw index 4d74d2f91..838335400 100644 --- a/include/apr.hw +++ b/include/apr.hw @@ -191,7 +191,7 @@ #endif #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 +#define _WIN32_WINNT 0x0601 #endif #ifndef NOUSER -- cgit v1.2.1 From 00b4bbf286255269d4eaf01018bdd14959f873fd Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sun, 19 May 2019 17:13:49 +0000 Subject: * CMakeLists.txt: Define _WIN32_WINNT to 0x0601 by default, since Windows 7 is minimum supported Windows version. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859514 13f79535-47bb-0310-9956-ffa450edef68 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b424814e3..3609d6cb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,7 @@ ELSE() ENDIF() IF("${MIN_WINDOWS_VER}" STREQUAL "") - SET(win32_winnt_str "0x0600") + SET(win32_winnt_str "0x0601") ELSEIF(${MIN_WINDOWS_VER} STREQUAL "Vista") SET(win32_winnt_str "0x0600") ELSEIF(${MIN_WINDOWS_VER} STREQUAL "Windows7") -- cgit v1.2.1 From 05975de4da961c810e0bf9d0b3552d1b3e69364f Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sun, 19 May 2019 17:16:11 +0000 Subject: * CMakeLists.txt: Set MIN_WINDOWS_VER to Windows 7 by default. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859515 13f79535-47bb-0310-9956-ffa450edef68 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3609d6cb8..b8caa1479 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ OPTION(APR_HAVE_IPV6 "IPv6 support" ON) OPTION(INSTALL_PDB "Install .pdb files (if generated)" ON) OPTION(APR_BUILD_TESTAPR "Build the test suite" OFF) OPTION(TEST_STATIC_LIBS "Test programs use APR static libraries instead of shared libraries?" OFF) -SET(MIN_WINDOWS_VER "Vista" +SET(MIN_WINDOWS_VER "Windows7" CACHE STRING "Minimum Windows version") SET(LIBXML2_ICONV_INCLUDE_DIR "" CACHE STRING "Directory with iconv include files for libxml2") -- cgit v1.2.1 From f72b4a217f23b77ace61209a9b1f4ed97664f377 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sun, 19 May 2019 17:16:34 +0000 Subject: * CMakeLists.txt: Error if MIN_WINDOWS_VER set to Vista. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859516 13f79535-47bb-0310-9956-ffa450edef68 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8caa1479..37e3c4359 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,7 +87,7 @@ ENDIF() IF("${MIN_WINDOWS_VER}" STREQUAL "") SET(win32_winnt_str "0x0601") ELSEIF(${MIN_WINDOWS_VER} STREQUAL "Vista") - SET(win32_winnt_str "0x0600") + MESSAGE(FATAL_ERROR "Minimum supported Windows version is Windows 7/Windows Server 2008 R2") ELSEIF(${MIN_WINDOWS_VER} STREQUAL "Windows7") SET(win32_winnt_str "0x0601") ELSE() -- cgit v1.2.1 From 3d69b20b8d05dff833cb192002066df6acfdd7c3 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sun, 19 May 2019 17:23:14 +0000 Subject: Use native one-time initialization [1] to implement apr_thread_once_t on Windows. This also fixes problem that apr_thread_once() may return before the other read completes initialization on Windows. [1] https://docs.microsoft.com/en-gb/windows/desktop/Sync/one-time-initialization git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859517 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ include/arch/win32/apr_arch_threadproc.h | 2 +- threadproc/win32/thread.c | 28 ++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 743938bd9..0ba7700de 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes for APR 2.0.0 + *) apr_thread_once: Fix problem that apr_thread_once can return before + the other thread completes initialization on Windows. + *) Windows platform: Remove support for Windows 2000, XP, Vista. The minimum supported OS versions are now Windows 7 / Windows Server 2008 R2. diff --git a/include/arch/win32/apr_arch_threadproc.h b/include/arch/win32/apr_arch_threadproc.h index d3ce9c518..9aee660fd 100644 --- a/include/arch/win32/apr_arch_threadproc.h +++ b/include/arch/win32/apr_arch_threadproc.h @@ -65,7 +65,7 @@ struct apr_procattr_t { }; struct apr_thread_once_t { - long value; + INIT_ONCE once; }; extern apr_status_t apr_threadproc_init(apr_pool_t *pool); diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c index c713e1444..3204a1c2c 100644 --- a/threadproc/win32/thread.c +++ b/threadproc/win32/thread.c @@ -257,19 +257,39 @@ APR_DECLARE(apr_status_t) apr_os_thread_put(apr_thread_t **thd, return APR_SUCCESS; } -APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control, +APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control_p, apr_pool_t *p) { - (*control) = apr_pcalloc(p, sizeof(**control)); + apr_thread_once_t *control = apr_pcalloc(p, sizeof(*control)); + + InitOnceInitialize(&control->once); + + *control_p = control; + return APR_SUCCESS; } +static BOOL WINAPI init_once_callback(PINIT_ONCE InitOnce, + PVOID Parameter, + PVOID *Context) +{ + void (*func)(void) = Parameter; + + func(); + + return TRUE; +} + APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control, void (*func)(void)) { - if (!InterlockedExchange(&control->value, 1)) { - func(); + PVOID lpContext; + + if (!InitOnceExecuteOnce(&control->once, init_once_callback, func, + &lpContext)) { + return apr_get_os_error(); } + return APR_SUCCESS; } -- cgit v1.2.1 From 993fde7fb1425220a3c4346a4dc05e783edd6691 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sun, 19 May 2019 17:31:16 +0000 Subject: win32: Remove non-unicode codepath from apr_dso_load(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859518 13f79535-47bb-0310-9956-ffa450edef68 --- dso/win32/dso.c | 73 +++++++++++++++++---------------------------------------- 1 file changed, 21 insertions(+), 52 deletions(-) diff --git a/dso/win32/dso.c b/dso/win32/dso.c index a2ed9a419..3433c7e31 100644 --- a/dso/win32/dso.c +++ b/dso/win32/dso.c @@ -60,65 +60,34 @@ APR_DECLARE(apr_status_t) apr_dso_load(struct apr_dso_handle_t **res_handle, UINT em; #endif -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wpath[APR_PATH_MAX]; - if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) - / sizeof(apr_wchar_t), path)) - != APR_SUCCESS) { - *res_handle = apr_pcalloc(ctx, sizeof(**res_handle)); - return ((*res_handle)->load_error = rv); - } - /* Prevent ugly popups from killing our app */ + apr_wchar_t wpath[APR_PATH_MAX]; + if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) + / sizeof(apr_wchar_t), path)) + != APR_SUCCESS) { + *res_handle = apr_pcalloc(ctx, sizeof(**res_handle)); + return ((*res_handle)->load_error = rv); + } + /* Prevent ugly popups from killing our app */ #ifndef _WIN32_WCE - em = SetErrorMode(SEM_FAILCRITICALERRORS); + em = SetErrorMode(SEM_FAILCRITICALERRORS); #endif - os_handle = LoadLibraryExW(wpath, NULL, 0); - if (!os_handle) - os_handle = LoadLibraryExW(wpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); - if (!os_handle) { + os_handle = LoadLibraryExW(wpath, NULL, 0); + if (!os_handle) + os_handle = LoadLibraryExW(wpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + if (!os_handle) { #ifndef _WIN32_WCE - rv = apr_get_os_error(); + rv = apr_get_os_error(); - os_handle = LoadLibraryExW(wpath, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); - if (os_handle) { - rv = APR_SUCCESS; - } -#else - rv = apr_get_os_error(); -#endif + os_handle = LoadLibraryExW(wpath, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); + if (os_handle) { + rv = APR_SUCCESS; } -#ifndef _WIN32_WCE - SetErrorMode(em); +#else + rv = apr_get_os_error(); #endif } -#endif /* APR_HAS_UNICODE_FS */ -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - char fspec[APR_PATH_MAX], *p = fspec; - /* Must convert path from / to \ notation. - * Per PR2555, the LoadLibraryEx function is very picky about slashes. - * Debugging on NT 4 SP 6a reveals First Chance Exception within NTDLL. - * LoadLibrary in the MS PSDK also reveals that it -explicitly- states - * that backslashes must be used for the LoadLibrary family of calls. - */ - apr_cpystrn(fspec, path, sizeof(fspec)); - while ((p = strchr(p, '/')) != NULL) - *p = '\\'; - - /* Prevent ugly popups from killing our app */ - em = SetErrorMode(SEM_FAILCRITICALERRORS); - os_handle = LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); - if (!os_handle) - os_handle = LoadLibraryEx(path, NULL, 0); - if (!os_handle) - rv = apr_get_os_error(); - else - rv = APR_SUCCESS; - SetErrorMode(em); - } +#ifndef _WIN32_WCE + SetErrorMode(em); #endif *res_handle = apr_pcalloc(ctx, sizeof(**res_handle)); -- cgit v1.2.1 From 9ef9d1331dbf386604e89bac81505ad0116467ff Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sun, 19 May 2019 17:34:34 +0000 Subject: * dso/win32/dso.c (apr_dso_load): Use SetThreadErrorMode() instead of SetErrorMode(), because SetErrorMode() is not thread-safe. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1859519 13f79535-47bb-0310-9956-ffa450edef68 --- dso/win32/dso.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dso/win32/dso.c b/dso/win32/dso.c index 3433c7e31..9681d91b5 100644 --- a/dso/win32/dso.c +++ b/dso/win32/dso.c @@ -69,7 +69,10 @@ APR_DECLARE(apr_status_t) apr_dso_load(struct apr_dso_handle_t **res_handle, } /* Prevent ugly popups from killing our app */ #ifndef _WIN32_WCE - em = SetErrorMode(SEM_FAILCRITICALERRORS); + if (!SetThreadErrorMode(SEM_FAILCRITICALERRORS, &em)) { + *res_handle = apr_pcalloc(ctx, sizeof(**res_handle)); + return ((*res_handle)->load_error = apr_get_os_error()); + } #endif os_handle = LoadLibraryExW(wpath, NULL, 0); if (!os_handle) @@ -87,7 +90,7 @@ APR_DECLARE(apr_status_t) apr_dso_load(struct apr_dso_handle_t **res_handle, #endif } #ifndef _WIN32_WCE - SetErrorMode(em); + SetThreadErrorMode(em, NULL); #endif *res_handle = apr_pcalloc(ctx, sizeof(**res_handle)); -- cgit v1.2.1