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

Enable Crashpad integration of V8 x64 stack unwinding

This CL makes sure that Crashpad on Chromium will behave exactly like it did
before we added code to emit unwinding info, even when FLAG_win64_unwinding_info
is not set.
In particular, before merging the Chromium CL:
https://chromium-review.googlesource.com/c/chromium/src/+/1474703/
that modifies Crashpad to use the new function SetUnhandledExceptionCallback(),
we need to make sure that Isolate::Init() will call
win64_unwindinfo::RegisterNonABICompliantCodeRange() even when
FLAG_win64_unwinding_info is false.
In that case RegisterNonABICompliantCodeRange will only register unwind info to
invoke the Crashpad exception handler for unhandled exceptions.
Note that RegisterNonABICompliantCodeRange will be a no-op with the current
Crashpad code that never calls SetUnhandledExceptionCallback().

Bug: v8:8661
Change-Id: I63d845e9dca79ddd5978dfb43b626ace50078e80
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1554119Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Paolo Severini <paolosev@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#60757}
parent 9acf5f41
......@@ -17,12 +17,12 @@ namespace win64_unwindinfo {
bool CanEmitUnwindInfoForBuiltins() { return FLAG_win64_unwinding_info; }
bool CanRegisterUnwindInfoForNonABICompliantCodeRange() {
return !FLAG_jitless && FLAG_win64_unwinding_info;
return !FLAG_jitless;
}
bool RegisterUnwindInfoForExceptionHandlingOnly() {
DCHECK(CanRegisterUnwindInfoForNonABICompliantCodeRange());
return !IsWindows8OrGreater();
return !IsWindows8OrGreater() || !FLAG_win64_unwinding_info;
}
#pragma pack(push, 1)
......@@ -236,6 +236,11 @@ void RegisterNonABICompliantCodeRange(void* start, size_t size_in_bytes) {
CHECK(::RtlAddFunctionTable(&record->runtime_function, 1,
reinterpret_cast<DWORD64>(start)));
// Protect reserved page against modifications.
DWORD old_protect;
CHECK(VirtualProtect(start, sizeof(CodeRangeUnwindingRecord),
PAGE_EXECUTE_READ, &old_protect));
}
} else {
CodeRangeUnwindingRecord* record = new (start) CodeRangeUnwindingRecord();
......@@ -246,12 +251,12 @@ void RegisterNonABICompliantCodeRange(void* start, size_t size_in_bytes) {
reinterpret_cast<DWORD64>(start),
reinterpret_cast<DWORD64>(reinterpret_cast<uint8_t*>(start) +
size_in_bytes)));
}
// Protect reserved page against modifications.
DWORD old_protect;
CHECK(VirtualProtect(start, sizeof(CodeRangeUnwindingRecord),
PAGE_EXECUTE_READ, &old_protect));
}
}
void UnregisterNonABICompliantCodeRange(void* start) {
......
......@@ -438,7 +438,8 @@ NativeModule::NativeModule(WasmEngine* engine, const WasmFeatures& enabled,
// See src/heap/spaces.cc, MemoryAllocator::InitializeCodePageAllocator() and
// https://cs.chromium.org/chromium/src/components/crash/content/app/crashpad_win.cc?rcl=fd680447881449fba2edcf0589320e7253719212&l=204
// for details.
if (win64_unwindinfo::CanRegisterUnwindInfoForNonABICompliantCodeRange()) {
if (win64_unwindinfo::CanRegisterUnwindInfoForNonABICompliantCodeRange() &&
FLAG_win64_unwinding_info) {
AllocateForCode(Heap::GetCodeRangeReservedAreaSize());
}
#endif
......@@ -1237,7 +1238,8 @@ std::shared_ptr<NativeModule> WasmCodeManager::NewNativeModule(
size);
#if defined(V8_OS_WIN_X64)
if (win64_unwindinfo::CanRegisterUnwindInfoForNonABICompliantCodeRange()) {
if (win64_unwindinfo::CanRegisterUnwindInfoForNonABICompliantCodeRange() &&
FLAG_win64_unwinding_info) {
win64_unwindinfo::RegisterNonABICompliantCodeRange(
reinterpret_cast<void*>(start), size);
}
......@@ -1377,7 +1379,8 @@ void WasmCodeManager::FreeNativeModule(NativeModule* native_module) {
code_space.address(), code_space.end(), code_space.size());
#if defined(V8_OS_WIN_X64)
if (win64_unwindinfo::CanRegisterUnwindInfoForNonABICompliantCodeRange()) {
if (win64_unwindinfo::CanRegisterUnwindInfoForNonABICompliantCodeRange() &&
FLAG_win64_unwinding_info) {
win64_unwindinfo::UnregisterNonABICompliantCodeRange(
reinterpret_cast<void*>(code_space.address()));
}
......
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