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