v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-limits.h
Go to the documentation of this file.
1// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_WASM_WASM_LIMITS_H_
6#define V8_WASM_WASM_LIMITS_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
12#include <cstddef>
13#include <cstdint>
14#include <limits>
15
16#include "src/base/macros.h"
18
19namespace v8::internal::wasm {
20
21// These constants limit the amount of *declared* memory. At runtime, memory can
22// only grow up to kV8MaxWasmMemory{32,64}Pages.
23// The spec limits are defined in
24// https://webassembly.github.io/spec/js-api/index.html#limits.
25constexpr size_t kSpecMaxMemory32Pages = 65'536; // 4GB
26constexpr size_t kSpecMaxMemory64Pages = 262'144; // 16GB
27
28// The following limits are imposed by V8 on WebAssembly modules.
29// The limits are agreed upon with other engines for consistency.
30constexpr size_t kV8MaxWasmTypes = 1'000'000;
31constexpr size_t kV8MaxWasmDefinedFunctions = 1'000'000;
32constexpr size_t kV8MaxWasmImports = 1'000'000;
33constexpr size_t kV8MaxWasmExports = 1'000'000;
34constexpr size_t kV8MaxWasmGlobals = 1'000'000;
35constexpr size_t kV8MaxWasmTags = 1'000'000;
36constexpr size_t kV8MaxWasmExceptionTypes = 1'000'000;
37constexpr size_t kV8MaxWasmDataSegments = 100'000;
38// This indicates the maximum memory size our implementation supports.
39// Do not use this limit directly; use {max_mem{32,64}_pages()} instead to take
40// the spec'ed limit as well as command line flag into account.
41// Also, do not use this limit to validate declared memory, use
42// kSpecMaxMemory{32,64}Pages for that.
44 ? 32'767 // = 2 GiB - 64Kib
45 : 65'536; // = 4 GiB
47 ? 32'767 // = 2 GiB - 64Kib
48 : 262'144; // = 16 GiB
49constexpr size_t kV8MaxWasmStringSize = 100'000;
50constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024; // = 1 GiB
51constexpr size_t kV8MaxWasmFunctionSize = 7'654'321;
52constexpr size_t kV8MaxWasmFunctionLocals = 50'000;
53constexpr size_t kV8MaxWasmFunctionParams = 1'000;
54constexpr size_t kV8MaxWasmFunctionReturns = 1'000;
55constexpr size_t kV8MaxWasmFunctionBrTableSize = 65'520;
56// Don't use this limit directly, but use the value of
57// v8_flags.wasm_max_table_size.
58constexpr size_t kV8MaxWasmTableSize = 10'000'000;
59constexpr size_t kV8MaxWasmTableInitEntries = 10'000'000;
60constexpr size_t kV8MaxWasmTables = 100'000;
61constexpr size_t kV8MaxWasmMemories = 100'000;
62
63// GC proposal.
64constexpr size_t kV8MaxWasmStructFields = 10'000;
65constexpr uint32_t kV8MaxRttSubtypingDepth = 63;
66constexpr size_t kV8MaxWasmArrayNewFixedLength = 10'000;
67
68// Stringref proposal. This limit is not standardized yet.
69constexpr size_t kV8MaxWasmStringLiterals = 1'000'000;
70
71static_assert(kV8MaxWasmTableSize <= 4294967295, // 2^32 - 1
72 "v8 should not exceed WebAssembly's non-web embedding limits");
74 "JS-API should not exceed v8's limit");
75
76// 64-bit platforms support the full spec'ed memory limits.
77static_assert(kSystemPointerSize == 4 ||
80
81constexpr uint64_t kWasmMaxHeapOffset =
82 static_cast<uint64_t>(
83 std::numeric_limits<uint32_t>::max()) // maximum base value
84 + std::numeric_limits<uint32_t>::max(); // maximum index value
85
86// This limit is a result of the limits for defined functions and the maximum of
87// imported functions.
88constexpr size_t kV8MaxWasmTotalFunctions =
90
91// The following functions are defined in wasm-engine.cc.
92
93// Maximum number of pages we can allocate, for memory32 and memory64. This
94// might be lower than the number of pages that can be declared (e.g. as
95// maximum): kSpecMaxMemory{32,64}Pages.
96// Even for 64-bit memory, the number of pages is still a 32-bit number for now,
97// which allows for up to 128 TB memories (2**31 * 64k).
98static_assert(kV8MaxWasmMemory64Pages <= kMaxUInt32);
101
102inline uint64_t max_mem32_bytes() {
103 return uint64_t{max_mem32_pages()} * kWasmPageSize;
104}
105
106inline uint64_t max_mem64_bytes() {
107 return uint64_t{max_mem64_pages()} * kWasmPageSize;
108}
109
110// The maximum memory64 size supported by our implementation, in bytes.
113
117
118} // namespace v8::internal::wasm
119
120#endif // V8_WASM_WASM_LIMITS_H_
constexpr size_t kV8MaxWasmTableInitEntries
Definition wasm-limits.h:59
constexpr size_t kV8MaxWasmExceptionTypes
Definition wasm-limits.h:36
uint32_t max_mem32_pages()
uint32_t max_table_size()
uint32_t max_mem64_pages()
constexpr size_t kSpecMaxMemory32Pages
Definition wasm-limits.h:25
constexpr size_t kV8MaxWasmFunctionLocals
Definition wasm-limits.h:52
constexpr size_t kV8MaxWasmImports
Definition wasm-limits.h:32
constexpr size_t kV8MaxWasmMemory64Pages
Definition wasm-limits.h:46
constexpr size_t kV8MaxWasmFunctionSize
Definition wasm-limits.h:51
constexpr size_t kV8MaxWasmModuleSize
Definition wasm-limits.h:50
constexpr size_t kV8MaxWasmArrayNewFixedLength
Definition wasm-limits.h:66
constexpr size_t kV8MaxWasmTypes
Definition wasm-limits.h:30
uint32_t max_table_init_entries()
constexpr size_t kV8MaxWasmExports
Definition wasm-limits.h:33
constexpr size_t kV8MaxWasmFunctionBrTableSize
Definition wasm-limits.h:55
constexpr size_t kMaxMemory64Size
constexpr size_t kV8MaxWasmTables
Definition wasm-limits.h:60
constexpr uint32_t kV8MaxRttSubtypingDepth
Definition wasm-limits.h:65
uint64_t max_mem32_bytes()
constexpr size_t kV8MaxWasmMemories
Definition wasm-limits.h:61
constexpr size_t kV8MaxWasmFunctionReturns
Definition wasm-limits.h:54
constexpr size_t kV8MaxWasmDefinedFunctions
Definition wasm-limits.h:31
constexpr size_t kV8MaxWasmDataSegments
Definition wasm-limits.h:37
constexpr size_t kWasmPageSize
constexpr uint64_t kWasmMaxHeapOffset
Definition wasm-limits.h:81
constexpr size_t kV8MaxWasmTableSize
Definition wasm-limits.h:58
constexpr size_t kSpecMaxMemory64Pages
Definition wasm-limits.h:26
constexpr size_t kV8MaxWasmTotalFunctions
Definition wasm-limits.h:88
uint64_t max_mem64_bytes()
constexpr size_t kV8MaxWasmGlobals
Definition wasm-limits.h:34
constexpr size_t kV8MaxWasmStringLiterals
Definition wasm-limits.h:69
constexpr size_t kV8MaxWasmFunctionParams
Definition wasm-limits.h:53
constexpr size_t kV8MaxWasmStructFields
Definition wasm-limits.h:64
constexpr size_t kV8MaxWasmMemory32Pages
Definition wasm-limits.h:43
constexpr size_t kV8MaxWasmStringSize
Definition wasm-limits.h:49
constexpr size_t kV8MaxWasmTags
Definition wasm-limits.h:35
constexpr int kSystemPointerSize
Definition globals.h:410
constexpr uint32_t kMaxUInt32
Definition globals.h:387
#define V8_EXPORT_PRIVATE
Definition macros.h:460