• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/base/macros.h"
13 #include "src/wasm/wasm-constants.h"
14 
15 namespace v8 {
16 namespace internal {
17 namespace wasm {
18 
19 // This constant is defined in the Wasm JS API spec and as such only
20 // concern JS embeddings.
21 constexpr size_t kSpecMaxMemoryPages = 65536;
22 
23 // The following limits are imposed by V8 on WebAssembly modules.
24 // The limits are agreed upon with other engines for consistency.
25 constexpr size_t kV8MaxWasmTypes = 1000000;
26 constexpr size_t kV8MaxWasmFunctions = 1000000;
27 constexpr size_t kV8MaxWasmImports = 100000;
28 constexpr size_t kV8MaxWasmExports = 100000;
29 constexpr size_t kV8MaxWasmGlobals = 1000000;
30 constexpr size_t kV8MaxWasmExceptions = 1000000;
31 constexpr size_t kV8MaxWasmExceptionTypes = 1000000;
32 constexpr size_t kV8MaxWasmDataSegments = 100000;
33 // This indicates the maximum memory size our implementation supports.
34 // Don't use this limit directly; use {max_mem_pages()} instead to take the
35 // spec'ed limit as well as command line flag into account.
36 constexpr size_t kV8MaxWasmMemoryPages = 65536;  // = 4 GiB
37 constexpr size_t kV8MaxWasmStringSize = 100000;
38 constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024;  // = 1 GiB
39 constexpr size_t kV8MaxWasmFunctionSize = 7654321;
40 constexpr size_t kV8MaxWasmFunctionLocals = 50000;
41 constexpr size_t kV8MaxWasmFunctionParams = 1000;
42 constexpr size_t kV8MaxWasmFunctionMultiReturns = 1000;
43 constexpr size_t kV8MaxWasmFunctionReturns = 1;
44 constexpr size_t kV8MaxWasmFunctionBrTableSize = 65520;
45 // Don't use this limit directly, but use the value of FLAG_wasm_max_table_size.
46 constexpr size_t kV8MaxWasmTableSize = 10000000;
47 constexpr size_t kV8MaxWasmTableInitEntries = 10000000;
48 constexpr size_t kV8MaxWasmTables = 1;
49 constexpr size_t kV8MaxWasmMemories = 1;
50 
51 // GC proposal. These limits are not standardized yet.
52 constexpr size_t kV8MaxWasmStructFields = 999;
53 constexpr uint32_t kV8MaxRttSubtypingDepth = 31;
54 
55 static_assert(kV8MaxWasmTableSize <= 4294967295,  // 2^32 - 1
56               "v8 should not exceed WebAssembly's non-web embedding limits");
57 static_assert(kV8MaxWasmTableInitEntries <= kV8MaxWasmTableSize,
58               "JS-API should not exceed v8's limit");
59 
60 constexpr uint64_t kWasmMaxHeapOffset =
61     static_cast<uint64_t>(
62         std::numeric_limits<uint32_t>::max())  // maximum base value
63     + std::numeric_limits<uint32_t>::max();    // maximum index value
64 
65 // Defined in wasm-engine.cc.
66 // TODO(wasm): Make this size_t for wasm64. Currently the --wasm-max-mem-pages
67 // flag is only uint32_t.
68 V8_EXPORT_PRIVATE uint32_t max_mem_pages();
69 uint32_t max_table_init_entries();
70 size_t max_module_size();
71 
max_mem_bytes()72 inline uint64_t max_mem_bytes() {
73   return uint64_t{max_mem_pages()} * kWasmPageSize;
74 }
75 
76 }  // namespace wasm
77 }  // namespace internal
78 }  // namespace v8
79 
80 #endif  // V8_WASM_WASM_LIMITS_H_
81