diff options
Diffstat (limited to 'deps/v8/src/diagnostics/unwinding-info-win64.h')
-rw-r--r-- | deps/v8/src/diagnostics/unwinding-info-win64.h | 105 |
1 files changed, 91 insertions, 14 deletions
diff --git a/deps/v8/src/diagnostics/unwinding-info-win64.h b/deps/v8/src/diagnostics/unwinding-info-win64.h index f6611e7e2e..8f8c9469eb 100644 --- a/deps/v8/src/diagnostics/unwinding-info-win64.h +++ b/deps/v8/src/diagnostics/unwinding-info-win64.h @@ -9,7 +9,7 @@ #include "include/v8config.h" #include "src/common/globals.h" -#if defined(V8_OS_WIN_X64) +#if defined(V8_OS_WIN64) #include "src/base/win32-headers.h" namespace v8 { @@ -21,11 +21,7 @@ namespace win64_unwindinfo { #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; +static const int kOSPageSize = 4096; /** * Returns true if V8 is configured to emit unwinding data for embedded in the @@ -50,15 +46,33 @@ bool CanRegisterUnwindInfoForNonABICompliantCodeRange(); void SetUnhandledExceptionCallback( v8::UnhandledExceptionCallback unhandled_exception_callback); +void RegisterNonABICompliantCodeRange(void* start, size_t size_in_bytes); +void UnregisterNonABICompliantCodeRange(void* start); + /** - * Returns a vector of bytes that contains the Win64 unwind data used for all + * Default count of RUNTIME_FUNCTION needed. For Windows X64, 1 RUNTIME_FUNCTION + * covers 4GB range which is sufficient to cover the whole code range of an + * isolate or WASM module. For Windows ARM64, 1 RUNTIME_FUNCTION covers + * kMaxFunctionLength bytes so multiple RUNTIME_FUNCTION structs could be needed + * to cover the whole code range of an isolate or WASM module. The extra + * RUNTIME_FUNCTIONs are assumed following the first one in the reserved page. + */ +static const uint32_t kDefaultRuntimeFunctionCount = 1; + +#if defined(V8_OS_WIN_X64) + +static const int kPushRbpInstructionLength = 1; +static const int kMovRbpRspInstructionLength = 3; +static const int kRbpPrefixCodes = 2; +static const int kRbpPrefixLength = + kPushRbpInstructionLength + kMovRbpRspInstructionLength; + +/** + * Returns a vector of bytes that contains the Win X64 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) {} @@ -76,7 +90,7 @@ class BuiltinUnwindInfo { class XdataEncoder { public: explicit XdataEncoder(const Assembler& assembler) - : assembler_(assembler), current_push_rbp_offset_(-1) {} + : assembler_(assembler), current_frame_code_offset_(-1) {} void onPushRbp(); void onMovRbpRsp(); @@ -88,14 +102,77 @@ class XdataEncoder { private: const Assembler& assembler_; std::vector<int> fp_offsets_; - int current_push_rbp_offset_; + int current_frame_code_offset_; }; -} // namespace win64_unwindinfo +#elif defined(V8_OS_WIN_ARM64) +/** + * Base on below doc, unwind record has 18 bits (unsigned) to encode function + * length, besides 2 LSB which are always 0. + * https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling#xdata-records + */ +static const int kMaxFunctionLength = ((1 << 18) - 1) << 2; + +/** + * Returns a vector of bytes that contains the Win ARM64 unwind data used for + * all V8 builtin functions. + * + * func_len: length in bytes of current function/region to unwind. + * fp_adjustment: offset of the saved caller's fp based on fp in current frame. + * this is necessary to encode unwind data for Windows stack + * unwinder to find correct caller's fp. + */ +std::vector<uint8_t> GetUnwindInfoForBuiltinFunction(uint32_t func_len, + int32_t fp_adjustment); +class BuiltinUnwindInfo { + public: + BuiltinUnwindInfo() : is_leaf_function_(true) {} + explicit BuiltinUnwindInfo(const std::vector<int>& fp_offsets, + const std::vector<int>& fp_adjustments) + : is_leaf_function_(false), + fp_offsets_(fp_offsets), + fp_adjustments_(fp_adjustments) {} + + const std::vector<int>& fp_adjustments() const { return fp_adjustments_; } + + 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_; + std::vector<int> fp_adjustments_; +}; + +class XdataEncoder { + public: + explicit XdataEncoder(const Assembler& assembler) + : assembler_(assembler), + current_frame_code_offset_(-1), + current_frame_adjustment_(0) {} + + void onSaveFpLr(); + void onFramePointerAdjustment(int bytes); + + BuiltinUnwindInfo unwinding_info() const { + return BuiltinUnwindInfo(fp_offsets_, fp_adjustments_); + } + + private: + const Assembler& assembler_; + std::vector<int> fp_offsets_; + int current_frame_code_offset_; + int current_frame_adjustment_; + std::vector<int> fp_adjustments_; +}; + +#endif + +} // namespace win64_unwindinfo } // namespace internal } // namespace v8 -#endif // defined(V8_OS_WIN_X64) +#endif // V8_OS_WIN64 #endif // V8_DIAGNOSTICS_UNWINDING_INFO_WIN64_H_ |