[wasm] Use checked casts for builtins where possible.
This makes sure that proper checked casts (i.e. {CAST} instead of the unsafe {UncheckedCast} before) are used for all WebAssembly runtime stubs. This is possible because the corresponding builtins are embedded and hence can use proper assertion mechanisms. R=clemensb@chromium.org BUG=v8:10021 Change-Id: I344ae8ba7dd4c5d3f5dc2467f7d58b93517d9af7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1940264 Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#65236}
This commit is contained in:
parent
5b156c5548
commit
d03802c6d2
@ -18,53 +18,48 @@ class WasmBuiltinsAssembler : public CodeStubAssembler {
|
|||||||
: CodeStubAssembler(state) {}
|
: CodeStubAssembler(state) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TNode<Object> UncheckedParameter(int index) {
|
TNode<WasmInstanceObject> LoadInstanceFromFrame() {
|
||||||
return UncheckedCast<Object>(Parameter(index));
|
return CAST(
|
||||||
}
|
|
||||||
|
|
||||||
TNode<Object> LoadInstanceFromFrame() {
|
|
||||||
return UncheckedCast<Object>(
|
|
||||||
LoadFromParentFrame(WasmCompiledFrameConstants::kWasmInstanceOffset));
|
LoadFromParentFrame(WasmCompiledFrameConstants::kWasmInstanceOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
TNode<Object> LoadContextFromInstance(TNode<Object> instance) {
|
TNode<Context> LoadContextFromInstance(TNode<WasmInstanceObject> instance) {
|
||||||
return UncheckedCast<Object>(
|
return CAST(Load(MachineType::AnyTagged(), instance,
|
||||||
Load(MachineType::AnyTagged(), instance,
|
|
||||||
IntPtrConstant(WasmInstanceObject::kNativeContextOffset -
|
IntPtrConstant(WasmInstanceObject::kNativeContextOffset -
|
||||||
kHeapObjectTag)));
|
kHeapObjectTag)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TF_BUILTIN(WasmStackGuard, WasmBuiltinsAssembler) {
|
TF_BUILTIN(WasmStackGuard, WasmBuiltinsAssembler) {
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
TailCallRuntime(Runtime::kWasmStackGuard, context);
|
TailCallRuntime(Runtime::kWasmStackGuard, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
TF_BUILTIN(WasmStackOverflow, WasmBuiltinsAssembler) {
|
TF_BUILTIN(WasmStackOverflow, WasmBuiltinsAssembler) {
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
TailCallRuntime(Runtime::kThrowWasmStackOverflow, context);
|
TailCallRuntime(Runtime::kThrowWasmStackOverflow, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
TF_BUILTIN(WasmThrow, WasmBuiltinsAssembler) {
|
TF_BUILTIN(WasmThrow, WasmBuiltinsAssembler) {
|
||||||
TNode<Object> exception = UncheckedParameter(Descriptor::kException);
|
TNode<Object> exception = CAST(Parameter(Descriptor::kException));
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
TailCallRuntime(Runtime::kThrow, context, exception);
|
TailCallRuntime(Runtime::kThrow, context, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TF_BUILTIN(WasmRethrow, WasmBuiltinsAssembler) {
|
TF_BUILTIN(WasmRethrow, WasmBuiltinsAssembler) {
|
||||||
TNode<Object> exception = UncheckedParameter(Descriptor::kException);
|
TNode<Object> exception = CAST(Parameter(Descriptor::kException));
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
TailCallRuntime(Runtime::kReThrow, context, exception);
|
TailCallRuntime(Runtime::kReThrow, context, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TF_BUILTIN(WasmTraceMemory, WasmBuiltinsAssembler) {
|
TF_BUILTIN(WasmTraceMemory, WasmBuiltinsAssembler) {
|
||||||
TNode<Object> info = UncheckedParameter(Descriptor::kMemoryTracingInfo);
|
TNode<Smi> info = CAST(Parameter(Descriptor::kMemoryTracingInfo));
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
TailCallRuntime(Runtime::kWasmTraceMemory, context, info);
|
TailCallRuntime(Runtime::kWasmTraceMemory, context, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,14 +68,14 @@ TF_BUILTIN(WasmAtomicNotify, WasmBuiltinsAssembler) {
|
|||||||
UncheckedCast<Uint32T>(Parameter(Descriptor::kAddress));
|
UncheckedCast<Uint32T>(Parameter(Descriptor::kAddress));
|
||||||
TNode<Uint32T> count = UncheckedCast<Uint32T>(Parameter(Descriptor::kCount));
|
TNode<Uint32T> count = UncheckedCast<Uint32T>(Parameter(Descriptor::kCount));
|
||||||
|
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Number> address_number = ChangeUint32ToTagged(address);
|
TNode<Number> address_number = ChangeUint32ToTagged(address);
|
||||||
TNode<Number> count_number = ChangeUint32ToTagged(count);
|
TNode<Number> count_number = ChangeUint32ToTagged(count);
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
|
|
||||||
TNode<Smi> result_smi =
|
TNode<Smi> result_smi =
|
||||||
UncheckedCast<Smi>(CallRuntime(Runtime::kWasmAtomicNotify, context,
|
CAST(CallRuntime(Runtime::kWasmAtomicNotify, context, instance,
|
||||||
instance, address_number, count_number));
|
address_number, count_number));
|
||||||
Return(Unsigned(SmiToInt32(result_smi)));
|
Return(Unsigned(SmiToInt32(result_smi)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,14 +87,14 @@ TF_BUILTIN(WasmI32AtomicWait, WasmBuiltinsAssembler) {
|
|||||||
TNode<Float64T> timeout =
|
TNode<Float64T> timeout =
|
||||||
UncheckedCast<Float64T>(Parameter(Descriptor::kTimeout));
|
UncheckedCast<Float64T>(Parameter(Descriptor::kTimeout));
|
||||||
|
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Number> address_number = ChangeUint32ToTagged(address);
|
TNode<Number> address_number = ChangeUint32ToTagged(address);
|
||||||
TNode<Number> expected_value_number = ChangeInt32ToTagged(expected_value);
|
TNode<Number> expected_value_number = ChangeInt32ToTagged(expected_value);
|
||||||
TNode<Number> timeout_number = ChangeFloat64ToTagged(timeout);
|
TNode<Number> timeout_number = ChangeFloat64ToTagged(timeout);
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
|
|
||||||
TNode<Smi> result_smi = UncheckedCast<Smi>(
|
TNode<Smi> result_smi =
|
||||||
CallRuntime(Runtime::kWasmI32AtomicWait, context, instance,
|
CAST(CallRuntime(Runtime::kWasmI32AtomicWait, context, instance,
|
||||||
address_number, expected_value_number, timeout_number));
|
address_number, expected_value_number, timeout_number));
|
||||||
Return(Unsigned(SmiToInt32(result_smi)));
|
Return(Unsigned(SmiToInt32(result_smi)));
|
||||||
}
|
}
|
||||||
@ -114,16 +109,16 @@ TF_BUILTIN(WasmI64AtomicWait, WasmBuiltinsAssembler) {
|
|||||||
TNode<Float64T> timeout =
|
TNode<Float64T> timeout =
|
||||||
UncheckedCast<Float64T>(Parameter(Descriptor::kTimeout));
|
UncheckedCast<Float64T>(Parameter(Descriptor::kTimeout));
|
||||||
|
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Number> address_number = ChangeUint32ToTagged(address);
|
TNode<Number> address_number = ChangeUint32ToTagged(address);
|
||||||
TNode<Number> expected_value_high_number =
|
TNode<Number> expected_value_high_number =
|
||||||
ChangeUint32ToTagged(expected_value_high);
|
ChangeUint32ToTagged(expected_value_high);
|
||||||
TNode<Number> expected_value_low_number =
|
TNode<Number> expected_value_low_number =
|
||||||
ChangeUint32ToTagged(expected_value_low);
|
ChangeUint32ToTagged(expected_value_low);
|
||||||
TNode<Number> timeout_number = ChangeFloat64ToTagged(timeout);
|
TNode<Number> timeout_number = ChangeFloat64ToTagged(timeout);
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
|
|
||||||
TNode<Smi> result_smi = UncheckedCast<Smi>(CallRuntime(
|
TNode<Smi> result_smi = CAST(CallRuntime(
|
||||||
Runtime::kWasmI64AtomicWait, context, instance, address_number,
|
Runtime::kWasmI64AtomicWait, context, instance, address_number,
|
||||||
expected_value_high_number, expected_value_low_number, timeout_number));
|
expected_value_high_number, expected_value_low_number, timeout_number));
|
||||||
Return(Unsigned(SmiToInt32(result_smi)));
|
Return(Unsigned(SmiToInt32(result_smi)));
|
||||||
@ -139,9 +134,9 @@ TF_BUILTIN(WasmMemoryGrow, WasmBuiltinsAssembler) {
|
|||||||
GotoIfNot(num_pages_fits_in_smi, &num_pages_out_of_range);
|
GotoIfNot(num_pages_fits_in_smi, &num_pages_out_of_range);
|
||||||
|
|
||||||
TNode<Smi> num_pages_smi = SmiFromInt32(num_pages);
|
TNode<Smi> num_pages_smi = SmiFromInt32(num_pages);
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
TNode<Smi> ret_smi = UncheckedCast<Smi>(
|
TNode<Smi> ret_smi = CAST(
|
||||||
CallRuntime(Runtime::kWasmMemoryGrow, context, instance, num_pages_smi));
|
CallRuntime(Runtime::kWasmMemoryGrow, context, instance, num_pages_smi));
|
||||||
Return(SmiToInt32(ret_smi));
|
Return(SmiToInt32(ret_smi));
|
||||||
|
|
||||||
@ -152,8 +147,8 @@ TF_BUILTIN(WasmMemoryGrow, WasmBuiltinsAssembler) {
|
|||||||
TF_BUILTIN(WasmTableGet, WasmBuiltinsAssembler) {
|
TF_BUILTIN(WasmTableGet, WasmBuiltinsAssembler) {
|
||||||
TNode<Int32T> entry_index =
|
TNode<Int32T> entry_index =
|
||||||
UncheckedCast<Int32T>(Parameter(Descriptor::kEntryIndex));
|
UncheckedCast<Int32T>(Parameter(Descriptor::kEntryIndex));
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
Label entry_index_out_of_range(this, Label::kDeferred);
|
Label entry_index_out_of_range(this, Label::kDeferred);
|
||||||
|
|
||||||
TNode<BoolT> entry_index_fits_in_smi =
|
TNode<BoolT> entry_index_fits_in_smi =
|
||||||
@ -161,8 +156,7 @@ TF_BUILTIN(WasmTableGet, WasmBuiltinsAssembler) {
|
|||||||
GotoIfNot(entry_index_fits_in_smi, &entry_index_out_of_range);
|
GotoIfNot(entry_index_fits_in_smi, &entry_index_out_of_range);
|
||||||
|
|
||||||
TNode<Smi> entry_index_smi = SmiFromInt32(entry_index);
|
TNode<Smi> entry_index_smi = SmiFromInt32(entry_index);
|
||||||
TNode<Smi> table_index_smi =
|
TNode<Smi> table_index_smi = CAST(Parameter(Descriptor::kTableIndex));
|
||||||
UncheckedCast<Smi>(Parameter(Descriptor::kTableIndex));
|
|
||||||
|
|
||||||
TailCallRuntime(Runtime::kWasmFunctionTableGet, context, instance,
|
TailCallRuntime(Runtime::kWasmFunctionTableGet, context, instance,
|
||||||
table_index_smi, entry_index_smi);
|
table_index_smi, entry_index_smi);
|
||||||
@ -177,8 +171,8 @@ TF_BUILTIN(WasmTableGet, WasmBuiltinsAssembler) {
|
|||||||
TF_BUILTIN(WasmTableSet, WasmBuiltinsAssembler) {
|
TF_BUILTIN(WasmTableSet, WasmBuiltinsAssembler) {
|
||||||
TNode<Int32T> entry_index =
|
TNode<Int32T> entry_index =
|
||||||
UncheckedCast<Int32T>(Parameter(Descriptor::kEntryIndex));
|
UncheckedCast<Int32T>(Parameter(Descriptor::kEntryIndex));
|
||||||
TNode<Object> instance = LoadInstanceFromFrame();
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
|
||||||
TNode<Object> context = LoadContextFromInstance(instance);
|
TNode<Context> context = LoadContextFromInstance(instance);
|
||||||
Label entry_index_out_of_range(this, Label::kDeferred);
|
Label entry_index_out_of_range(this, Label::kDeferred);
|
||||||
|
|
||||||
TNode<BoolT> entry_index_fits_in_smi =
|
TNode<BoolT> entry_index_fits_in_smi =
|
||||||
@ -186,9 +180,8 @@ TF_BUILTIN(WasmTableSet, WasmBuiltinsAssembler) {
|
|||||||
GotoIfNot(entry_index_fits_in_smi, &entry_index_out_of_range);
|
GotoIfNot(entry_index_fits_in_smi, &entry_index_out_of_range);
|
||||||
|
|
||||||
TNode<Smi> entry_index_smi = SmiFromInt32(entry_index);
|
TNode<Smi> entry_index_smi = SmiFromInt32(entry_index);
|
||||||
TNode<Smi> table_index_smi =
|
TNode<Smi> table_index_smi = CAST(Parameter(Descriptor::kTableIndex));
|
||||||
UncheckedCast<Smi>(Parameter(Descriptor::kTableIndex));
|
TNode<Object> value = CAST(Parameter(Descriptor::kValue));
|
||||||
TNode<Object> value = UncheckedCast<Object>(Parameter(Descriptor::kValue));
|
|
||||||
TailCallRuntime(Runtime::kWasmFunctionTableSet, context, instance,
|
TailCallRuntime(Runtime::kWasmFunctionTableSet, context, instance,
|
||||||
table_index_smi, entry_index_smi, value);
|
table_index_smi, entry_index_smi, value);
|
||||||
|
|
||||||
@ -199,17 +192,17 @@ TF_BUILTIN(WasmTableSet, WasmBuiltinsAssembler) {
|
|||||||
SmiConstant(static_cast<int>(message_id)));
|
SmiConstant(static_cast<int>(message_id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DECLARE_ENUM(name) \
|
#define DECLARE_THROW_RUNTIME_FN(name) \
|
||||||
TF_BUILTIN(ThrowWasm##name, WasmBuiltinsAssembler) { \
|
TF_BUILTIN(ThrowWasm##name, WasmBuiltinsAssembler) { \
|
||||||
TNode<Object> instance = LoadInstanceFromFrame(); \
|
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame(); \
|
||||||
TNode<Object> context = LoadContextFromInstance(instance); \
|
TNode<Context> context = LoadContextFromInstance(instance); \
|
||||||
MessageTemplate message_id = \
|
MessageTemplate message_id = \
|
||||||
wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \
|
wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \
|
||||||
TailCallRuntime(Runtime::kThrowWasmError, context, \
|
TailCallRuntime(Runtime::kThrowWasmError, context, \
|
||||||
SmiConstant(static_cast<int>(message_id))); \
|
SmiConstant(static_cast<int>(message_id))); \
|
||||||
}
|
}
|
||||||
FOREACH_WASM_TRAPREASON(DECLARE_ENUM)
|
FOREACH_WASM_TRAPREASON(DECLARE_THROW_RUNTIME_FN)
|
||||||
#undef DECLARE_ENUM
|
#undef DECLARE_THROW_RUNTIME_FN
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace v8
|
} // namespace v8
|
||||||
|
Loading…
Reference in New Issue
Block a user