969cb0c7a5
This is a reland of 3cda21de77
Original change's description:
> V8 x64 backend doesn't emit ABI compliant stack frames
>
> On 64 bit Windows, the OS stack walking does not work because the V8 x64
> backend doesn't emit unwinding info and also because it doesn't emit ABI
> compliant stack frames. See
> https://docs.google.com/document/d/1-wf50jFlii0c_Pr52lm2ZU-49m220nhYMrHDi3vXnh0/edit
> for more details.
>
> This problem can be fixed by observing that V8 frames usually all have the same
> prolog and epilog:
>
> push rbp,
> mov rbp, rsp
> ...
> pop rbp
> ret N
>
> and that it is possible to define XDATA (UNWIND_CODEs) that specify how Windows
> should walk through V8 frames. Furthermore, since V8 Code objects are all
> allocated in the same code-range for an Isolate, it is possible to register a
> single PDATA/XDATA entry to cover stack walking for all the code generated
> inside that code-range.
>
> This PR contains changes required to enable stack walking on Win64:
>
> EmbeddedFileWriter now adds assembler directives to the builtins
> snapshot source file (embedded.cc) to emit additional entries in the .pdata and
> in the .xdata section of the V8 executable. This takes care of stack walking
> for embedded builtins. (The case of non-embedded builtins is not supported).
> The x64 Assembler has been modified to collect the information required to emit
> this unwind info for builtins.
>
> Stack walking for jitted code is handled is Isolate.cpp, by registering
> dynamically PDATA/XDATA for the whole code-range address space every time a new
> Isolate is initialized, and by unregistering them when the Isolate is
> destroyed.
>
> Stack walking for WASM jitted code is handled is the same way in
> wasm::NativeModule (wasm/wasm-code-manager.cpp).
>
> It is important to note that Crashpad and Breakpad are already registering
> PDATA/XDATA to manage and report unhandled exceptions (but not for embedded
> builtins). Since it is not possible to register multiple PDATA entries for the
> same address range, a new function is added to the V8 API:
> SetUnhandledExceptionCallback() can be used by an embedder to register its own
> unhandled exception handler for exceptions that arise in v8-generated code.
> V8 embedders should be modified accordingly (code for this is in a separate PR
> in the Chromium repository:
> https://chromium-review.googlesource.com/c/chromium/src/+/1474703).
>
> All these changes are experimental, behind:
>
> the 'v8_win64_unwinding_info' build flag, and
> the '--win64-unwinding-info' runtime flag.
>
> Bug: v8:3598
> Change-Id: Iea455ab6d0e2bf1c556aa1cf870841d44ab6e4b1
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1469329
> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Commit-Queue: Paolo Severini <paolosev@microsoft.com>
> Cr-Commit-Position: refs/heads/master@{#60330}
Bug: v8:3598
Change-Id: If988baf7d3e4af165b919d6e54c1ad985f8e25e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1534618
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Paolo Severini <paolosev@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#60581}
102 lines
3.0 KiB
C++
102 lines
3.0 KiB
C++
// Copyright 2019 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef V8_UNWINDING_INFO_WIN64_H_
|
|
#define V8_UNWINDING_INFO_WIN64_H_
|
|
|
|
#include "include/v8config.h"
|
|
|
|
#if defined(V8_OS_WIN_X64)
|
|
#include "include/v8.h"
|
|
#include "src/base/win32-headers.h"
|
|
#include "src/globals.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
namespace win64_unwindinfo {
|
|
|
|
#define CRASH_HANDLER_FUNCTION_NAME CrashForExceptionInNonABICompliantCodeRange
|
|
#define CRASH_HANDLER_FUNCTION_NAME_STRING \
|
|
"CrashForExceptionInNonABICompliantCodeRange"
|
|
|
|
static const int kPushRbpInstructionLength = 1;
|
|
static const int kMovRbpRspInstructionLength = 3;
|
|
static const int kRbpPrefixCodes = 2;
|
|
static const int kRbpPrefixLength =
|
|
kPushRbpInstructionLength + kMovRbpRspInstructionLength;
|
|
|
|
/**
|
|
* Returns true if V8 is configured to emit unwinding data for embedded in the
|
|
* pdata/xdata sections of the executable. Currently, this happens when V8 is
|
|
* built with "v8_win64_unwinding_info = true".
|
|
*/
|
|
bool CanEmitUnwindInfoForBuiltins();
|
|
|
|
/**
|
|
* Returns true if V8 if we can register unwinding data for the whole code range
|
|
* of an isolate or WASM module. The first page of the code range is reserved
|
|
* and writable, to be used to store unwind data, as documented in:
|
|
* https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64.
|
|
* In jitless mode V8 does not allocate any executable memory itself so the only
|
|
* non-abi-compliant code range is in the embedded blob.
|
|
*/
|
|
bool CanRegisterUnwindInfoForNonABICompliantCodeRange();
|
|
|
|
/**
|
|
* Registers a custom exception handler for exceptions in V8-generated code.
|
|
*/
|
|
void SetUnhandledExceptionCallback(
|
|
v8::UnhandledExceptionCallback unhandled_exception_callback);
|
|
|
|
/**
|
|
* Returns a vector of bytes that contains the Win64 unwind data used for all
|
|
* V8 builtin functions.
|
|
*/
|
|
std::vector<uint8_t> GetUnwindInfoForBuiltinFunctions();
|
|
|
|
void RegisterNonABICompliantCodeRange(void* start, size_t size_in_bytes);
|
|
void UnregisterNonABICompliantCodeRange(void* start);
|
|
|
|
class BuiltinUnwindInfo {
|
|
public:
|
|
BuiltinUnwindInfo() : is_leaf_function_(true) {}
|
|
explicit BuiltinUnwindInfo(const std::vector<int>& fp_offsets)
|
|
: is_leaf_function_(false), fp_offsets_(fp_offsets) {}
|
|
|
|
bool is_leaf_function() const { return is_leaf_function_; }
|
|
const std::vector<int>& fp_offsets() const { return fp_offsets_; }
|
|
|
|
private:
|
|
bool is_leaf_function_;
|
|
std::vector<int> fp_offsets_;
|
|
};
|
|
|
|
class XdataEncoder {
|
|
public:
|
|
explicit XdataEncoder(const Assembler& assembler)
|
|
: assembler_(assembler), current_push_rbp_offset_(-1) {}
|
|
|
|
void onPushRbp();
|
|
void onMovRbpRsp();
|
|
|
|
BuiltinUnwindInfo unwinding_info() const {
|
|
return BuiltinUnwindInfo(fp_offsets_);
|
|
}
|
|
|
|
private:
|
|
const Assembler& assembler_;
|
|
std::vector<int> fp_offsets_;
|
|
int current_push_rbp_offset_;
|
|
};
|
|
|
|
} // namespace win64_unwindinfo
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|
|
|
|
#endif // defined(V8_OS_WIN_X64)
|
|
|
|
#endif // V8_UNWINDING_INFO_WIN64_H_
|