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

// Copyright 2021 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 <cinttypes>
#include <type_traits>

#include "include/v8-wasm.h"
#include "src/base/memory.h"
#include "src/base/platform/mutex.h"
#include "src/builtins/builtins-inl.h"
#include "src/execution/arguments-inl.h"
#include "src/execution/frames-inl.h"
#include "src/heap/heap-inl.h"
#include "src/objects/property-descriptor.h"
#include "src/objects/smi.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/fuzzing/random-module-generation.h"
#include "src/wasm/memory-tracing.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-result.h"
#include "src/wasm/wasm-serialization.h"

namespace v8::internal {

namespace {
V8_WARN_UNUSED_RESULT Tagged<Object> CrashUnlessFuzzing(Isolate* isolate) {}

struct WasmCompileControls {};
using WasmCompileControlsMap = std::map<v8::Isolate*, WasmCompileControls>;

// We need per-isolate controls, because we sometimes run tests in multiple
// isolates concurrently. Methods need to hold the accompanying mutex on access.
// To avoid upsetting the static initializer count, we lazy initialize this.
DEFINE_LAZY_LEAKY_OBJECT_GETTER()
base::LazyMutex g_PerIsolateWasmControlsMutex = LAZY_MUTEX_INITIALIZER;

bool IsWasmCompileAllowed(v8::Isolate* isolate, v8::Local<v8::Value> value,
                          bool is_async) {}

// Use the compile controls for instantiation, too
bool IsWasmInstantiateAllowed(v8::Isolate* isolate,
                              v8::Local<v8::Value> module_or_bytes,
                              bool is_async) {}

v8::Local<v8::Value> NewRangeException(v8::Isolate* isolate,
                                       const char* message) {}

void ThrowRangeException(v8::Isolate* isolate, const char* message) {}

bool WasmModuleOverride(const v8::FunctionCallbackInfo<v8::Value>& info) {}

bool WasmInstanceOverride(const v8::FunctionCallbackInfo<v8::Value>& info) {}

}  // namespace

// Returns a callable object. The object returns the difference of its two
// parameters when it is called.
RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) {}

RUNTIME_FUNCTION(Runtime_SetWasmInstantiateControls) {}

namespace {

void PrintIndentation(int stack_size) {}

int WasmStackSize(Isolate* isolate) {}

}  // namespace

RUNTIME_FUNCTION(Runtime_CountUnoptimizedWasmToJSWrapper) {}

RUNTIME_FUNCTION(Runtime_HasUnoptimizedWasmToJSWrapper) {}

RUNTIME_FUNCTION(Runtime_HasUnoptimizedJSToJSWrapper) {}

RUNTIME_FUNCTION(Runtime_WasmTraceEnter) {}

RUNTIME_FUNCTION(Runtime_WasmTraceExit) {}

RUNTIME_FUNCTION(Runtime_IsAsmWasmCode) {}

namespace {

bool DisallowWasmCodegenFromStringsCallback(v8::Local<v8::Context> context,
                                            v8::Local<v8::String> source) {}

}  // namespace

RUNTIME_FUNCTION(Runtime_DisallowWasmCodegen) {}

RUNTIME_FUNCTION(Runtime_IsWasmCode) {}

RUNTIME_FUNCTION(Runtime_IsWasmTrapHandlerEnabled) {}

RUNTIME_FUNCTION(Runtime_IsWasmPartialOOBWriteNoop) {}

RUNTIME_FUNCTION(Runtime_IsThreadInWasm) {}

RUNTIME_FUNCTION(Runtime_GetWasmRecoveredTrapCount) {}

RUNTIME_FUNCTION(Runtime_GetWasmExceptionTagId) {}

RUNTIME_FUNCTION(Runtime_GetWasmExceptionValues) {}

RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {}

// Take an array buffer and attempt to reconstruct a compiled wasm module.
// Return undefined if unsuccessful.
RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) {}

RUNTIME_FUNCTION(Runtime_WasmGetNumberOfInstances) {}

RUNTIME_FUNCTION(Runtime_WasmNumCodeSpaces) {}

namespace {

template <typename T1, typename T2 = T1>
void PrintRep(Address address, const char* str) {}

}  // namespace

RUNTIME_FUNCTION(Runtime_WasmTraceMemory) {}

RUNTIME_FUNCTION(Runtime_WasmTierUpFunction) {}

RUNTIME_FUNCTION(Runtime_WasmNull) {}

static Tagged<Object> CreateWasmObject(
    Isolate* isolate, base::Vector<const uint8_t> module_bytes) {}

// Creates a new wasm struct with one i64 (value 0x7AADF00DBAADF00D).
RUNTIME_FUNCTION(Runtime_WasmStruct) {}

// Creates a new wasm array of type i32 with two elements (2x 0xBAADF00D).
RUNTIME_FUNCTION(Runtime_WasmArray) {}

RUNTIME_FUNCTION(Runtime_WasmEnterDebugging) {}

RUNTIME_FUNCTION(Runtime_WasmLeaveDebugging) {}

RUNTIME_FUNCTION(Runtime_IsWasmDebugFunction) {}

RUNTIME_FUNCTION(Runtime_IsLiftoffFunction) {}

RUNTIME_FUNCTION(Runtime_IsTurboFanFunction) {}

RUNTIME_FUNCTION(Runtime_IsUncompiledWasmFunction) {}

RUNTIME_FUNCTION(Runtime_FreezeWasmLazyCompilation) {}

// This runtime function enables WebAssembly imported strings through an
// embedder callback and thereby bypasses the value in v8_flags.
RUNTIME_FUNCTION(Runtime_SetWasmImportedStringsEnabled) {}

RUNTIME_FUNCTION(Runtime_FlushLiftoffCode) {}

RUNTIME_FUNCTION(Runtime_EstimateCurrentMemoryConsumption) {}

RUNTIME_FUNCTION(Runtime_WasmCompiledExportWrappersCount) {}

RUNTIME_FUNCTION(Runtime_WasmDeoptsExecutedCount) {}

RUNTIME_FUNCTION(Runtime_WasmDeoptsExecutedForFunction) {}

RUNTIME_FUNCTION(Runtime_WasmSwitchToTheCentralStackCount) {}

RUNTIME_FUNCTION() {

// The GenerateRandomWasmModule function is only implemented in non-official
// builds (to save binary size). Hence also skip the runtime function in
// official builds.
#ifndef OFFICIAL_BUILD
RUNTIME_FUNCTION(Runtime_WasmGenerateRandomModule) {}
#endif  // OFFICIAL_BUILD

}  // namespace v8::internal