Commit 725654b3 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm][turbofan] Always define an instance node

The runtime function 'WasmIsValidRefValue' can be called from C-API and
JS wrappers and needs to be passed an instance. Therefore, we always
have to define an instance node, even when it is just undefined.
See also https://chromium-review.googlesource.com/c/v8/v8/+/3236719.

Bug: v8:11510, chromium:1266080
Change-Id: Ib9712fe3a3880db8656ee4882bec0ae7635cc60f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3257708Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77677}
parent 548c40ed
...@@ -518,6 +518,9 @@ void WasmGraphBuilder::Start(unsigned params) { ...@@ -518,6 +518,9 @@ void WasmGraphBuilder::Start(unsigned params) {
Param(Linkage::kJSCallClosureParamIndex, "%closure"))); Param(Linkage::kJSCallClosureParamIndex, "%closure")));
break; break;
case kWasmApiFunctionRefMode: case kWasmApiFunctionRefMode:
// We need an instance node anyway, because FromJS() needs to pass it to
// the WasmIsValidRefValue runtime function.
instance_node_ = UndefinedValue();
break; break;
} }
graph()->SetEnd(graph()->NewNode(mcgraph()->common()->End(0))); graph()->SetEnd(graph()->NewNode(mcgraph()->common()->End(0)));
...@@ -648,10 +651,7 @@ Node* WasmGraphBuilder::NoContextConstant() { ...@@ -648,10 +651,7 @@ Node* WasmGraphBuilder::NoContextConstant() {
return mcgraph()->IntPtrConstant(0); return mcgraph()->IntPtrConstant(0);
} }
Node* WasmGraphBuilder::GetInstance() { Node* WasmGraphBuilder::GetInstance() { return instance_node_.get(); }
DCHECK_NE(parameter_mode_, kWasmApiFunctionRefMode);
return instance_node_.get();
}
Node* WasmGraphBuilder::BuildLoadIsolateRoot() { Node* WasmGraphBuilder::BuildLoadIsolateRoot() {
switch (parameter_mode_) { switch (parameter_mode_) {
...@@ -676,6 +676,10 @@ Node* WasmGraphBuilder::Int64Constant(int64_t value) { ...@@ -676,6 +676,10 @@ Node* WasmGraphBuilder::Int64Constant(int64_t value) {
return mcgraph()->Int64Constant(value); return mcgraph()->Int64Constant(value);
} }
Node* WasmGraphBuilder::UndefinedValue() {
return LOAD_ROOT(UndefinedValue, undefined_value);
}
void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) { void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) {
DCHECK_NOT_NULL(env_); // Wrappers don't get stack checks. DCHECK_NOT_NULL(env_); // Wrappers don't get stack checks.
if (!FLAG_wasm_stack_checks || !env_->runtime_exception_support) { if (!FLAG_wasm_stack_checks || !env_->runtime_exception_support) {
...@@ -6207,8 +6211,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6207,8 +6211,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
: gasm_->GetBuiltinPointerTarget(builtin); : gasm_->GetBuiltinPointerTarget(builtin);
} }
Node* UndefinedValue() { return LOAD_ROOT(UndefinedValue, undefined_value); }
Node* BuildChangeInt32ToNumber(Node* value) { Node* BuildChangeInt32ToNumber(Node* value) {
// We expect most integers at runtime to be Smis, so it is important for // We expect most integers at runtime to be Smis, so it is important for
// wrapper performance that Smi conversion be inlined. // wrapper performance that Smi conversion be inlined.
...@@ -6486,6 +6488,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6486,6 +6488,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
wasm::ValueType type) { wasm::ValueType type) {
// Make sure ValueType fits in a Smi. // Make sure ValueType fits in a Smi.
STATIC_ASSERT(wasm::ValueType::kLastUsedBit + 1 <= kSmiValueSize); STATIC_ASSERT(wasm::ValueType::kLastUsedBit + 1 <= kSmiValueSize);
// The instance node is always defined: if an instance is not available, it
// is the undefined value.
Node* inputs[] = {GetInstance(), input, Node* inputs[] = {GetInstance(), input,
mcgraph()->IntPtrConstant( mcgraph()->IntPtrConstant(
IntToSmi(static_cast<int>(type.raw_bit_field())))}; IntToSmi(static_cast<int>(type.raw_bit_field())))};
......
...@@ -548,6 +548,7 @@ class WasmGraphBuilder { ...@@ -548,6 +548,7 @@ class WasmGraphBuilder {
Node* GetInstance(); Node* GetInstance();
Node* BuildLoadIsolateRoot(); Node* BuildLoadIsolateRoot();
Node* UndefinedValue();
// MemBuffer is only called with valid offsets (after bounds checking), so the // MemBuffer is only called with valid offsets (after bounds checking), so the
// offset fits in a platform-dependent uintptr_t. // offset fits in a platform-dependent uintptr_t.
......
...@@ -100,17 +100,23 @@ RUNTIME_FUNCTION(Runtime_WasmIsValidRefValue) { ...@@ -100,17 +100,23 @@ RUNTIME_FUNCTION(Runtime_WasmIsValidRefValue) {
!trap_handler::IsThreadInWasm()); !trap_handler::IsThreadInWasm());
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(3, args.length()); DCHECK_EQ(3, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmInstanceObject, instance, 0) // 'raw_instance' can be either a WasmInstanceObject or undefined.
CONVERT_ARG_HANDLE_CHECKED(Object, raw_instance, 0)
CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
// Make sure ValueType fits properly in a Smi. // Make sure ValueType fits properly in a Smi.
STATIC_ASSERT(wasm::ValueType::kLastUsedBit + 1 <= kSmiValueSize); STATIC_ASSERT(wasm::ValueType::kLastUsedBit + 1 <= kSmiValueSize);
CONVERT_SMI_ARG_CHECKED(raw_type, 2); CONVERT_SMI_ARG_CHECKED(raw_type, 2);
const wasm::WasmModule* module =
raw_instance->IsWasmInstanceObject()
? Handle<WasmInstanceObject>::cast(raw_instance)->module()
: nullptr;
wasm::ValueType type = wasm::ValueType::FromRawBitField(raw_type); wasm::ValueType type = wasm::ValueType::FromRawBitField(raw_type);
const char* error_message; const char* error_message;
bool result = internal::wasm::TypecheckJSObject(isolate, instance->module(), bool result = internal::wasm::TypecheckJSObject(isolate, module, value, type,
value, type, &error_message); &error_message);
return Smi::FromInt(result); return Smi::FromInt(result);
} }
......
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