chromium/v8/src/runtime/runtime-wasm.cc

// Copyright 2016 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.

#include <optional>

#include "src/builtins/builtins-inl.h"
#include "src/builtins/data-view-ops.h"
#include "src/common/assert-scope.h"
#include "src/common/message-template.h"
#include "src/compiler/wasm-compiler.h"
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/execution/arguments-inl.h"
#include "src/execution/frames.h"
#include "src/heap/factory.h"
#include "src/numbers/conversions.h"
#include "src/objects/objects-inl.h"
#include "src/strings/unicode-inl.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/compilation-environment-inl.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/serialized-signature-inl.h"
#include "src/wasm/value-type.h"
#include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-constants.h"
#include "src/wasm/wasm-debug.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-opcodes-inl.h"
#include "src/wasm/wasm-subtyping.h"
#include "src/wasm/wasm-value.h"

#if V8_ENABLE_WEBASSEMBLY && V8_ENABLE_DRUMBRAKE
#include "src/wasm/interpreter/wasm-interpreter.h"
#endif  // V8_ENABLE_WEBASSEMBLY && V8_ENABLE_DRUMBRAKE

namespace v8::internal {

// TODO(13036): See if we can find a way to have the stack walker visit
// tagged values being passed from Wasm to runtime functions. In the meantime,
// disallow access to safe-looking-but-actually-unsafe stack-backed handles
// and thereby force manual creation of safe handles (backed by HandleScope).
class RuntimeArgumentsWithoutHandles : public RuntimeArguments {};

#define RuntimeArguments

// (End of TODO(13036)-related hackery.)

namespace {

template <typename FrameType>
class FrameFinder {};

Tagged<WasmTrustedInstanceData> GetWasmInstanceDataOnStackTop(
    Isolate* isolate) {}

Tagged<Context> GetNativeContextFromWasmInstanceOnStackTop(Isolate* isolate) {}

class V8_NODISCARD ClearThreadInWasmScope {};

Tagged<Object> ThrowWasmError(
    Isolate* isolate, MessageTemplate message,
    std::initializer_list<DirectHandle<Object>> args = {}
}  // namespace

RUNTIME_FUNCTION(Runtime_WasmGenericWasmToJSObject) {}

// Takes a JS object and a wasm type as Smi. Type checks the object against the
// type; if the check succeeds, returns the object in its wasm representation;
// otherwise throws a type error.
RUNTIME_FUNCTION(Runtime_WasmGenericJSToWasmObject) {}

// Parameters:
// args[0]: the object, any JS value.
// args[1]: the expected ValueType, Smi-tagged.
// args[2]: the expected canonical type index, Smi-tagged, if the type is
//          an indexed reftype.
// Type checks the object against the type; if the check succeeds, returns the
// object in its wasm representation; otherwise throws a type error.
RUNTIME_FUNCTION(Runtime_WasmJSToWasmObject) {}

RUNTIME_FUNCTION(Runtime_WasmMemoryGrow) {}

RUNTIME_FUNCTION(Runtime_TrapHandlerThrowWasmError) {}

RUNTIME_FUNCTION(Runtime_ThrowWasmError) {}

RUNTIME_FUNCTION(Runtime_ThrowWasmStackOverflow) {}

RUNTIME_FUNCTION(Runtime_WasmThrowJSTypeError) {}

// This error is thrown from a wasm-to-JS wrapper, so unlike
// Runtime_ThrowWasmError, this function does not check or unset the
// thread-in-wasm flag.
RUNTIME_FUNCTION(Runtime_ThrowBadSuspenderError) {}

RUNTIME_FUNCTION(Runtime_WasmThrowRangeError) {}

RUNTIME_FUNCTION(Runtime_WasmThrowDataViewTypeError) {}

RUNTIME_FUNCTION(Runtime_WasmThrowDataViewDetachedError) {}

RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) {}

RUNTIME_FUNCTION(Runtime_WasmThrow) {}

RUNTIME_FUNCTION(Runtime_WasmReThrow) {}

RUNTIME_FUNCTION(Runtime_WasmStackGuard) {}

RUNTIME_FUNCTION(Runtime_WasmCompileLazy) {}

namespace {
Tagged<FixedArray> AllocateFeedbackVector(
    Isolate* isolate,
    DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
    int declared_func_index) {}
}  // namespace

RUNTIME_FUNCTION(Runtime_WasmAllocateFeedbackVector) {}

RUNTIME_FUNCTION(Runtime_WasmLiftoffDeoptFinish) {}

namespace {
void ReplaceJSToWasmWrapper(
    Isolate* isolate,
    DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
    int function_index, DirectHandle<Code> wrapper_code) {}
}  // namespace

RUNTIME_FUNCTION(Runtime_TierUpJSToWasmWrapper) {}

RUNTIME_FUNCTION() {

RUNTIME_FUNCTION(Runtime_TierUpWasmToJSWrapper) {}

RUNTIME_FUNCTION(Runtime_WasmTriggerTierUp) {}

RUNTIME_FUNCTION(Runtime_WasmI32AtomicWait) {}

RUNTIME_FUNCTION(Runtime_WasmI64AtomicWait) {}

namespace {
Tagged<Object> ThrowTableOutOfBounds(
    Isolate* isolate,
    DirectHandle<WasmTrustedInstanceData> trusted_instance_data) {}
}  // namespace

RUNTIME_FUNCTION(Runtime_WasmRefFunc) {}

RUNTIME_FUNCTION(Runtime_WasmInternalFunctionCreateExternal) {}

RUNTIME_FUNCTION(Runtime_WasmFunctionTableGet) {}

RUNTIME_FUNCTION(Runtime_WasmFunctionTableSet) {}

RUNTIME_FUNCTION(Runtime_WasmTableInit) {}

RUNTIME_FUNCTION(Runtime_WasmTableCopy) {}

RUNTIME_FUNCTION(Runtime_WasmTableGrow) {}

RUNTIME_FUNCTION(Runtime_WasmTableFill) {}

namespace {
// Returns true if any breakpoint was hit, false otherwise.
bool ExecuteWasmDebugBreaks(
    Isolate* isolate,
    DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
    WasmFrame* frame) {}
}  // namespace

RUNTIME_FUNCTION(Runtime_WasmDebugBreak) {}

// Assumes copy ranges are in-bounds and copy length > 0.
// TODO(manoskouk): Unify part of this with the implementation in
// wasm-extern-refs.cc
RUNTIME_FUNCTION(Runtime_WasmArrayCopy) {}

RUNTIME_FUNCTION(Runtime_WasmArrayNewSegment) {}

RUNTIME_FUNCTION(Runtime_WasmArrayInitSegment) {}

// Allocate a new suspender, and prepare for stack switching by updating the
// active continuation, active suspender and stack limit.
RUNTIME_FUNCTION(Runtime_WasmAllocateSuspender) {}

#define RETURN_RESULT_OR_TRAP(call)

// "Special" because the type must be in a recgroup of its own.
// Used by "JS String Builtins".
RUNTIME_FUNCTION(Runtime_WasmCastToSpecialPrimitiveArray) {}

// Returns the new string if the operation succeeds.  Otherwise throws an
// exception and returns an empty result.
RUNTIME_FUNCTION(Runtime_WasmStringNewWtf8) {}

RUNTIME_FUNCTION(Runtime_WasmStringNewWtf8Array) {}

RUNTIME_FUNCTION(Runtime_WasmStringNewWtf16) {}

RUNTIME_FUNCTION(Runtime_WasmStringNewWtf16Array) {}

RUNTIME_FUNCTION(Runtime_WasmSubstring) {}

// Returns the new string if the operation succeeds.  Otherwise traps.
RUNTIME_FUNCTION(Runtime_WasmStringConst) {}

RUNTIME_FUNCTION(Runtime_WasmStringNewSegmentWtf8) {}

namespace {
// TODO(12868): Consider unifying with api.cc:String::Utf8Length.
template <typename T>
int MeasureWtf8(base::Vector<const T> wtf16) {}
int MeasureWtf8(Isolate* isolate, Handle<String> string) {}
size_t MaxEncodedSize(base::Vector<const uint8_t> wtf16) {}
size_t MaxEncodedSize(base::Vector<const base::uc16> wtf16) {}
bool HasUnpairedSurrogate(base::Vector<const uint8_t> wtf16) {}
bool HasUnpairedSurrogate(base::Vector<const base::uc16> wtf16) {}
// TODO(12868): Consider unifying with api.cc:String::WriteUtf8.
template <typename T>
int EncodeWtf8(base::Vector<char> bytes, size_t offset,
               base::Vector<const T> wtf16, unibrow::Utf8Variant variant,
               MessageTemplate* message, MessageTemplate out_of_bounds) {}
template <typename GetWritableBytes>
Tagged<Object> EncodeWtf8(Isolate* isolate, unibrow::Utf8Variant variant,
                          Handle<String> string,
                          GetWritableBytes get_writable_bytes, size_t offset,
                          MessageTemplate out_of_bounds_message) {}
}  // namespace

// Used for storing the name of a string-constants imports module off the heap.
// Defined here to be able to make use of the helper functions above.
void ToUtf8Lossy(Isolate* isolate, Handle<String> string, std::string& out) {}

RUNTIME_FUNCTION(Runtime_WasmStringMeasureUtf8) {}

RUNTIME_FUNCTION(Runtime_WasmStringMeasureWtf8) {}

RUNTIME_FUNCTION(Runtime_WasmStringEncodeWtf8) {}

RUNTIME_FUNCTION(Runtime_WasmStringEncodeWtf8Array) {}

RUNTIME_FUNCTION(Runtime_WasmStringToUtf8Array) {}

RUNTIME_FUNCTION(Runtime_WasmStringEncodeWtf16) {}

RUNTIME_FUNCTION(Runtime_WasmStringAsWtf8) {}

RUNTIME_FUNCTION(Runtime_WasmStringViewWtf8Encode) {}

RUNTIME_FUNCTION(Runtime_WasmStringViewWtf8Slice) {}

#ifdef V8_ENABLE_DRUMBRAKE
RUNTIME_FUNCTION(Runtime_WasmTraceBeginExecution) {
  DCHECK(v8_flags.slow_histograms && !v8_flags.wasm_jitless &&
         v8_flags.wasm_enable_exec_time_histograms);
  DCHECK_EQ(0, args.length());
  HandleScope scope(isolate);

  wasm::WasmExecutionTimer* timer = isolate->wasm_execution_timer();
  timer->Start();

  return ReadOnlyRoots(isolate).undefined_value();
}

RUNTIME_FUNCTION(Runtime_WasmTraceEndExecution) {
  DCHECK(v8_flags.slow_histograms && !v8_flags.wasm_jitless &&
         v8_flags.wasm_enable_exec_time_histograms);
  DCHECK_EQ(0, args.length());
  HandleScope scope(isolate);

  wasm::WasmExecutionTimer* timer = isolate->wasm_execution_timer();
  timer->Stop();

  return ReadOnlyRoots(isolate).undefined_value();
}
#endif  // V8_ENABLE_DRUMBRAKE

RUNTIME_FUNCTION(Runtime_WasmStringFromCodePoint) {}

RUNTIME_FUNCTION(Runtime_WasmStringHash) {}

}  // namespace v8::internal