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 FLAG_wasm_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 kV8MaxWasmMemoryBytes = 50 kV8MaxWasmMemoryPages * uint64_t{kWasmPageSize}; 51 52 constexpr uint64_t kSpecMaxWasmMemoryBytes = 53 kSpecMaxWasmMemoryPages * uint64_t{kWasmPageSize}; 54 55 constexpr uint64_t kWasmMaxHeapOffset = 56 static_cast<uint64_t>( 57 std::numeric_limits<uint32_t>::max()) // maximum base value 58 + std::numeric_limits<uint32_t>::max(); // maximum index value 59 60 } // namespace wasm 61 } // namespace internal 62 } // namespace v8 63 64 #endif // V8_WASM_WASM_LIMITS_H_ 65