From 7cd394ef31f2bd4eb7cea08ee2b7b8a61396bd9b Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 8 Aug 2022 15:26:58 -0700 Subject: [PATCH 1/2] Avoid in filesystem.cpp. --- stl/src/filesystem.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/stl/src/filesystem.cpp b/stl/src/filesystem.cpp index b28d057f904..f49893e418a 100644 --- a/stl/src/filesystem.cpp +++ b/stl/src/filesystem.cpp @@ -9,7 +9,6 @@ // Do not include or define anything else here. // In particular, basic_string must not be included here. -#include #include #include #include @@ -796,20 +795,11 @@ namespace { _Stl_GetTempPath2W(_In_ DWORD nBufferLength, _Out_writes_to_opt_(nBufferLength, return +1) LPWSTR lpBuffer) { using _Fun_ptr = decltype(&::GetTempPath2W); - _Fun_ptr _PfGetTempPath2W; - { - static _STD atomic<_Fun_ptr> _Static{nullptr}; - - _PfGetTempPath2W = _Static.load(_STD memory_order_relaxed); - if (!_PfGetTempPath2W) { - const auto _Kernel32 = ::GetModuleHandleW(L"kernel32.dll"); - _Analysis_assume_(_Kernel32); - _PfGetTempPath2W = reinterpret_cast<_Fun_ptr>(::GetProcAddress(_Kernel32, "GetTempPath2W")); - if (!_PfGetTempPath2W) { - _PfGetTempPath2W = &::GetTempPathW; - } - _Static.store(_PfGetTempPath2W, _STD memory_order_relaxed); // overwriting with the same value is okay - } + const auto _Kernel32 = ::GetModuleHandleW(L"kernel32.dll"); + _Analysis_assume_(_Kernel32); + _Fun_ptr _PfGetTempPath2W = reinterpret_cast<_Fun_ptr>(::GetProcAddress(_Kernel32, "GetTempPath2W")); + if (!_PfGetTempPath2W) { + _PfGetTempPath2W = &::GetTempPathW; } return _PfGetTempPath2W(nBufferLength, lpBuffer); From 14ec91b9ea9d94256fc6c958efe7e4d01bddb4db Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 8 Aug 2022 16:42:36 -0700 Subject: [PATCH 2/2] Add comments. --- stl/src/filesystem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stl/src/filesystem.cpp b/stl/src/filesystem.cpp index f49893e418a..915cf0dfab4 100644 --- a/stl/src/filesystem.cpp +++ b/stl/src/filesystem.cpp @@ -793,6 +793,8 @@ _Success_(return == __std_win_error::_Success) __std_win_error namespace { _Success_(return > 0 && return < nBufferLength) DWORD WINAPI _Stl_GetTempPath2W(_In_ DWORD nBufferLength, _Out_writes_to_opt_(nBufferLength, return +1) LPWSTR lpBuffer) { + // See GH-3011: This is intentionally not attempting to cache the function pointer. + // TRANSITION, ABI: This should use __crtGetTempPath2W after this code is moved into the STL's DLL. using _Fun_ptr = decltype(&::GetTempPath2W); const auto _Kernel32 = ::GetModuleHandleW(L"kernel32.dll");