[wasm] Move protected instruction handling to native module.
R=clemensh@chromium.org Change-Id: Ibe6c203aa3ebdbbd8d3ca1f9f0ddfa7f89d79c71 Reviewed-on: https://chromium-review.googlesource.com/997835 Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#52397}
This commit is contained in:
parent
17bb05f54d
commit
1b07fffc5c
@ -1806,7 +1806,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
|
||||
// Unpack and notify signal handler of protected instructions.
|
||||
//--------------------------------------------------------------------------
|
||||
if (use_trap_handler()) {
|
||||
UnpackAndRegisterProtectedInstructions(isolate_, native_module);
|
||||
native_module->UnpackAndRegisterProtectedInstructions();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
@ -866,6 +866,40 @@ WasmCode* NativeModule::CloneCode(const WasmCode* original_code,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NativeModule::UnpackAndRegisterProtectedInstructions() {
|
||||
for (uint32_t i = num_imported_functions(), e = FunctionCount(); i < e; ++i) {
|
||||
WasmCode* code = GetCode(i);
|
||||
|
||||
if (code == nullptr) continue;
|
||||
if (code->kind() != wasm::WasmCode::kFunction) continue;
|
||||
if (code->HasTrapHandlerIndex()) continue;
|
||||
|
||||
Address base = code->instructions().start();
|
||||
|
||||
size_t size = code->instructions().size();
|
||||
const int index =
|
||||
RegisterHandlerData(base, size, code->protected_instructions().size(),
|
||||
code->protected_instructions().data());
|
||||
|
||||
// TODO(eholk): if index is negative, fail.
|
||||
CHECK_LE(0, index);
|
||||
code->set_trap_handler_index(static_cast<size_t>(index));
|
||||
}
|
||||
}
|
||||
|
||||
void NativeModule::ReleaseProtectedInstructions() {
|
||||
for (uint32_t i = num_imported_functions(), e = FunctionCount(); i < e; ++i) {
|
||||
WasmCode* wasm_code = GetCode(i);
|
||||
if (wasm_code->HasTrapHandlerIndex()) {
|
||||
CHECK_LT(wasm_code->trap_handler_index(),
|
||||
static_cast<size_t>(std::numeric_limits<int>::max()));
|
||||
trap_handler::ReleaseHandlerData(
|
||||
static_cast<int>(wasm_code->trap_handler_index()));
|
||||
wasm_code->ResetTrapHandlerIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NativeModule::~NativeModule() {
|
||||
TRACE_HEAP("Deleting native module: %p\n", reinterpret_cast<void*>(this));
|
||||
// Clear the handle at the beginning of destructor to make it robust against
|
||||
|
@ -124,6 +124,8 @@ class V8_EXPORT_PRIVATE WasmCode final {
|
||||
uint32_t stack_slots() const { return stack_slots_; }
|
||||
bool is_liftoff() const { return tier_ == kLiftoff; }
|
||||
|
||||
// TODO(mstarzinger): Make the next four methods private once wasm-to-wasm
|
||||
// wrappers are gone. All uses are in {NativeModule} by now.
|
||||
size_t trap_handler_index() const;
|
||||
void set_trap_handler_index(size_t);
|
||||
bool HasTrapHandlerIndex() const;
|
||||
@ -259,6 +261,11 @@ class V8_EXPORT_PRIVATE NativeModule final {
|
||||
uint32_t FunctionCount() const;
|
||||
WasmCode* GetCode(uint32_t index) const;
|
||||
|
||||
// Register/release the protected instructions in all code objects with the
|
||||
// global trap handler for this process.
|
||||
void UnpackAndRegisterProtectedInstructions();
|
||||
void ReleaseProtectedInstructions();
|
||||
|
||||
// We special-case lazy cloning because we currently rely on making copies
|
||||
// of the lazy builtin, to be able to identify, in the runtime, which function
|
||||
// the lazy builtin is a placeholder of. If we used trampolines, we would call
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "src/property-descriptor.h"
|
||||
#include "src/simulator.h"
|
||||
#include "src/snapshot/snapshot.h"
|
||||
#include "src/trap-handler/trap-handler.h"
|
||||
#include "src/v8.h"
|
||||
#include "src/wasm/compilation-manager.h"
|
||||
#include "src/wasm/module-decoder.h"
|
||||
@ -39,34 +38,6 @@ constexpr const char* WasmException::kRuntimeIdStr;
|
||||
// static
|
||||
constexpr const char* WasmException::kRuntimeValuesStr;
|
||||
|
||||
void UnpackAndRegisterProtectedInstructions(
|
||||
Isolate* isolate, const wasm::NativeModule* native_module) {
|
||||
DisallowHeapAllocation no_gc;
|
||||
|
||||
for (uint32_t i = native_module->num_imported_functions(),
|
||||
e = native_module->FunctionCount();
|
||||
i < e; ++i) {
|
||||
wasm::WasmCode* code = native_module->GetCode(i);
|
||||
|
||||
if (code == nullptr || code->kind() != wasm::WasmCode::kFunction) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code->HasTrapHandlerIndex()) continue;
|
||||
|
||||
Address base = code->instructions().start();
|
||||
|
||||
size_t size = code->instructions().size();
|
||||
const int index =
|
||||
RegisterHandlerData(base, size, code->protected_instructions().size(),
|
||||
code->protected_instructions().data());
|
||||
|
||||
// TODO(eholk): if index is negative, fail.
|
||||
CHECK_LE(0, index);
|
||||
code->set_trap_handler_index(static_cast<size_t>(index));
|
||||
}
|
||||
}
|
||||
|
||||
WireBytesRef WasmModule::LookupName(const ModuleWireBytes* wire_bytes,
|
||||
uint32_t function_index) const {
|
||||
if (!names_) {
|
||||
|
@ -262,9 +262,6 @@ V8_EXPORT_PRIVATE Handle<JSArray> GetCustomSections(
|
||||
// function index, the inner one by the local index.
|
||||
Handle<FixedArray> DecodeLocalNames(Isolate*, Handle<WasmSharedModuleData>);
|
||||
|
||||
void UnpackAndRegisterProtectedInstructions(
|
||||
Isolate* isolate, const wasm::NativeModule* native_module);
|
||||
|
||||
// TruncatedUserString makes it easy to output names up to a certain length, and
|
||||
// output a truncation followed by '...' if they exceed a limit.
|
||||
// Use like this:
|
||||
|
@ -1341,18 +1341,7 @@ void WasmCompiledModule::Reset(Isolate* isolate,
|
||||
|
||||
TRACE("Resetting %zu\n", native_module->instance_id);
|
||||
if (compiled_module->use_trap_handler()) {
|
||||
for (uint32_t i = native_module->num_imported_functions(),
|
||||
e = native_module->FunctionCount();
|
||||
i < e; ++i) {
|
||||
wasm::WasmCode* wasm_code = native_module->GetCode(i);
|
||||
if (wasm_code->HasTrapHandlerIndex()) {
|
||||
CHECK_LT(wasm_code->trap_handler_index(),
|
||||
static_cast<size_t>(std::numeric_limits<int>::max()));
|
||||
trap_handler::ReleaseHandlerData(
|
||||
static_cast<int>(wasm_code->trap_handler_index()));
|
||||
wasm_code->ResetTrapHandlerIndex();
|
||||
}
|
||||
}
|
||||
native_module->ReleaseProtectedInstructions();
|
||||
}
|
||||
|
||||
// Patch code to update memory references, global references, and function
|
||||
|
@ -462,7 +462,7 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
|
||||
}
|
||||
CHECK(!thrower.error());
|
||||
if (trap_handler::IsTrapHandlerEnabled()) {
|
||||
UnpackAndRegisterProtectedInstructions(isolate(), native_module);
|
||||
native_module->UnpackAndRegisterProtectedInstructions();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user