V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
wasm-limits.h
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 #include <cstddef>
9 #include <cstdint>
10 #include <limits>
11 
12 #include "src/wasm/wasm-constants.h"
13 
14 namespace v8 {
15 namespace internal {
16 namespace wasm {
17 
18 constexpr size_t kSpecMaxWasmMemoryPages = 65536;
19 
20 // The following limits are imposed by V8 on WebAssembly modules.
21 // The limits are agreed upon with other engines for consistency.
22 constexpr size_t kV8MaxWasmTypes = 1000000;
23 constexpr size_t kV8MaxWasmFunctions = 1000000;
24 constexpr size_t kV8MaxWasmImports = 100000;
25 constexpr size_t kV8MaxWasmExports = 100000;
26 constexpr size_t kV8MaxWasmGlobals = 1000000;
27 constexpr size_t kV8MaxWasmExceptions = 1000000;
28 constexpr size_t kV8MaxWasmExceptionTypes = 1000000;
29 constexpr size_t kV8MaxWasmDataSegments = 100000;
30 // Don't use this limit directly, but use the value of {max_mem_pages()}.
31 constexpr size_t kV8MaxWasmMemoryPages = 32767; // = ~ 2 GiB
32 constexpr size_t kV8MaxWasmStringSize = 100000;
33 constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024; // = 1 GiB
34 constexpr size_t kV8MaxWasmFunctionSize = 7654321;
35 constexpr size_t kV8MaxWasmFunctionLocals = 50000;
36 constexpr size_t kV8MaxWasmFunctionParams = 1000;
37 constexpr size_t kV8MaxWasmFunctionMultiReturns = 1000;
38 constexpr size_t kV8MaxWasmFunctionReturns = 1;
39 // Don't use this limit directly, but use the value of FLAG_wasm_max_table_size.
40 constexpr size_t kV8MaxWasmTableSize = 10000000;
41 constexpr size_t kV8MaxWasmTableEntries = 10000000;
42 constexpr size_t kV8MaxWasmTables = 1;
43 constexpr size_t kV8MaxWasmMemories = 1;
44 
45 static_assert(kV8MaxWasmMemoryPages <= kSpecMaxWasmMemoryPages,
46  "v8 should not be more permissive than the spec");
47 constexpr size_t kSpecMaxWasmTableSize = 0xFFFFFFFFu;
48 
49 constexpr uint64_t kWasmMaxHeapOffset =
50  static_cast<uint64_t>(
51  std::numeric_limits<uint32_t>::max()) // maximum base value
52  + std::numeric_limits<uint32_t>::max(); // maximum index value
53 
54 // Defined in wasm-engine.cc.
55 // TODO(wasm): Make this size_t for wasm64. Currently the --wasm-max-mem-pages
56 // flag is only uint32_t.
57 uint32_t max_mem_pages();
58 
59 inline uint64_t max_mem_bytes() {
60  return uint64_t{max_mem_pages()} * kWasmPageSize;
61 }
62 
63 } // namespace wasm
64 } // namespace internal
65 } // namespace v8
66 
67 #endif // V8_WASM_WASM_LIMITS_H_
Definition: libplatform.h:13