Line data Source code
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 kV8MaxWasmTableInitEntries = 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 : static_assert(kV8MaxWasmTableSize <= 4294967295, // 2^32 - 1
48 : "v8 should not exceed WebAssembly's non-web embedding limits");
49 : static_assert(kV8MaxWasmTableInitEntries <= kV8MaxWasmTableSize,
50 : "JS-API should not exceed v8's limit");
51 :
52 : constexpr uint64_t kWasmMaxHeapOffset =
53 : static_cast<uint64_t>(
54 : std::numeric_limits<uint32_t>::max()) // maximum base value
55 : + std::numeric_limits<uint32_t>::max(); // maximum index value
56 :
57 : // Defined in wasm-engine.cc.
58 : // TODO(wasm): Make this size_t for wasm64. Currently the --wasm-max-mem-pages
59 : // flag is only uint32_t.
60 : uint32_t max_mem_pages();
61 : uint32_t max_table_init_entries();
62 :
63 : inline uint64_t max_mem_bytes() {
64 1509727 : return uint64_t{max_mem_pages()} * kWasmPageSize;
65 : }
66 :
67 : } // namespace wasm
68 : } // namespace internal
69 : } // namespace v8
70 :
71 : #endif // V8_WASM_WASM_LIMITS_H_
|