chromium/v8/src/wasm/wasm-limits.h

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

#if !V8_ENABLE_WEBASSEMBLY
#error This header should only be included if WebAssembly is enabled.
#endif  // !V8_ENABLE_WEBASSEMBLY

#ifndef V8_WASM_WASM_LIMITS_H_
#define V8_WASM_WASM_LIMITS_H_

#include <cstddef>
#include <cstdint>
#include <limits>

#include "src/base/macros.h"
#include "src/wasm/wasm-constants.h"

namespace v8::internal::wasm {

// These constants limit the amount of *declared* memory. At runtime, memory can
// only grow up to kV8MaxWasmMemory{32,64}Pages.
constexpr size_t kSpecMaxMemory32Pages =;  // 4GB
// TODO(clemensb): Adapt once the spec defines a limit here. For now, use 16GB.
constexpr size_t kSpecMaxMemory64Pages =;  // 16GB

// The following limits are imposed by V8 on WebAssembly modules.
// The limits are agreed upon with other engines for consistency.
constexpr size_t kV8MaxWasmTypes =;
constexpr size_t kV8MaxWasmDefinedFunctions =;
constexpr size_t kV8MaxWasmImports =;
constexpr size_t kV8MaxWasmExports =;
constexpr size_t kV8MaxWasmGlobals =;
constexpr size_t kV8MaxWasmTags =;
constexpr size_t kV8MaxWasmExceptionTypes =;
constexpr size_t kV8MaxWasmDataSegments =;
// This indicates the maximum memory size our implementation supports.
// Do not use this limit directly; use {max_mem{32,64}_pages()} instead to take
// the spec'ed limit as well as command line flag into account.
// Also, do not use this limit to validate declared memory, use
// kSpecMaxMemory{32,64}Pages for that.
constexpr size_t kV8MaxWasmMemory32Pages =;  // = 4 GiB
constexpr size_t kV8MaxWasmMemory64Pages =;  // = 16 GiB
constexpr size_t kV8MaxWasmStringSize =;
constexpr size_t kV8MaxWasmModuleSize =;  // = 1 GiB
constexpr size_t kV8MaxWasmFunctionSize =;
constexpr size_t kV8MaxWasmFunctionLocals =;
constexpr size_t kV8MaxWasmFunctionParams =;
constexpr size_t kV8MaxWasmFunctionReturns =;
constexpr size_t kV8MaxWasmFunctionBrTableSize =;
// Don't use this limit directly, but use the value of
// v8_flags.wasm_max_table_size.
constexpr size_t kV8MaxWasmTableSize =;
constexpr size_t kV8MaxWasmTableInitEntries =;
constexpr size_t kV8MaxWasmTables =;
constexpr size_t kV8MaxWasmMemories =;

// GC proposal.
constexpr size_t kV8MaxWasmStructFields =;
constexpr uint32_t kV8MaxRttSubtypingDepth =;
constexpr size_t kV8MaxWasmArrayNewFixedLength =;

// Stringref proposal. This limit is not standardized yet.
constexpr size_t kV8MaxWasmStringLiterals =;

static_assert;
static_assert;

constexpr uint64_t kWasmMaxHeapOffset =;    // maximum index value

// This limit is a result of the limits for defined functions and the maximum of
// imported functions.
constexpr size_t kV8MaxWasmTotalFunctions =;

// The following functions are defined in wasm-engine.cc.

// Maximum number of pages we can allocate, for memory32 and memory64. This
// might be lower than the number of pages that can be declared (e.g. as
// maximum): kSpecMaxMemory{32,64}Pages.
// Even for 64-bit memory, the number of pages is still a 32-bit number for now,
// which allows for up to 128 TB memories (2**31 * 64k).
static_assert;
V8_EXPORT_PRIVATE uint32_t max_mem32_pages();
V8_EXPORT_PRIVATE uint32_t max_mem64_pages();

inline uint64_t max_mem32_bytes() {}

inline uint64_t max_mem64_bytes() {}

V8_EXPORT_PRIVATE uint32_t max_table_init_entries();
V8_EXPORT_PRIVATE size_t max_module_size();

}  // namespace v8::internal::wasm

#endif  // V8_WASM_WASM_LIMITS_H_