Commit c6bf94fa authored by Paolo Severini's avatar Paolo Severini Committed by Commit Bot

Fix a race condition in win64_unwindinfo::RegisterNonABICompliantCodeRange

Function win64_unwindinfo::RegisterNonABICompliantCodeRange() calls
LoadNtdllUnwindingFunctions() to dynamically load from ntdll a couple of
functions that are not available on Windows 7. Unfortunately there is a
race condition in LoadNtdllUnwindingFunctions() that can cause a crash
when multiple isolates are initialized concurrently.
This can be fixed using base::CallOnce().

Bug: v8:9204
Change-Id: I5c57708ab5f16e9ef9f897efce1ccdf591e2f828
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1623592Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Paolo Severini <paolosev@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#61757}
parent aaecb433
...@@ -127,36 +127,33 @@ struct ExceptionHandlerRecord { ...@@ -127,36 +127,33 @@ struct ExceptionHandlerRecord {
uint8_t exception_thunk[kMaxExceptionThunkSize]; uint8_t exception_thunk[kMaxExceptionThunkSize];
}; };
namespace {
V8_DECLARE_ONCE(load_ntdll_unwinding_functions_once);
static decltype( static decltype(
&::RtlAddGrowableFunctionTable) add_growable_function_table_func = nullptr; &::RtlAddGrowableFunctionTable) add_growable_function_table_func = nullptr;
static decltype( static decltype(
&::RtlDeleteGrowableFunctionTable) delete_growable_function_table_func = &::RtlDeleteGrowableFunctionTable) delete_growable_function_table_func =
nullptr; nullptr;
namespace {
void LoadNtdllUnwindingFunctions() { void LoadNtdllUnwindingFunctions() {
static bool loaded = false; base::CallOnce(&load_ntdll_unwinding_functions_once, []() {
if (loaded) { // Load functions from the ntdll.dll module.
return; HMODULE ntdll_module =
} LoadLibraryEx(L"ntdll.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
loaded = true; DCHECK_NOT_NULL(ntdll_module);
// Load functions from the ntdll.dll module. // This fails on Windows 7.
HMODULE ntdll_module = add_growable_function_table_func =
LoadLibraryEx(L"ntdll.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); reinterpret_cast<decltype(&::RtlAddGrowableFunctionTable)>(
DCHECK_NOT_NULL(ntdll_module); ::GetProcAddress(ntdll_module, "RtlAddGrowableFunctionTable"));
DCHECK_IMPLIES(IsWindows8OrGreater(), add_growable_function_table_func);
// This fails on Windows 7.
add_growable_function_table_func = delete_growable_function_table_func =
reinterpret_cast<decltype(&::RtlAddGrowableFunctionTable)>( reinterpret_cast<decltype(&::RtlDeleteGrowableFunctionTable)>(
::GetProcAddress(ntdll_module, "RtlAddGrowableFunctionTable")); ::GetProcAddress(ntdll_module, "RtlDeleteGrowableFunctionTable"));
DCHECK_IMPLIES(IsWindows8OrGreater(), add_growable_function_table_func); DCHECK_IMPLIES(IsWindows8OrGreater(), delete_growable_function_table_func);
});
delete_growable_function_table_func =
reinterpret_cast<decltype(&::RtlDeleteGrowableFunctionTable)>(
::GetProcAddress(ntdll_module, "RtlDeleteGrowableFunctionTable"));
DCHECK_IMPLIES(IsWindows8OrGreater(), delete_growable_function_table_func);
} }
bool AddGrowableFunctionTable(PVOID* DynamicTable, bool AddGrowableFunctionTable(PVOID* DynamicTable,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment