wasm-limits.h 2.93 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_WASM_WASM_LIMITS_H_
#define V8_WASM_WASM_LIMITS_H_

8 9 10 11
#include <cstddef>
#include <cstdint>
#include <limits>

12
#include "src/base/macros.h"
13 14
#include "src/wasm/wasm-constants.h"

15 16 17 18
namespace v8 {
namespace internal {
namespace wasm {

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 24
// The following limits are imposed by V8 on WebAssembly modules.
// The limits are agreed upon with other engines for consistency.
25 26 27 28 29
constexpr size_t kV8MaxWasmTypes = 1000000;
constexpr size_t kV8MaxWasmFunctions = 1000000;
constexpr size_t kV8MaxWasmImports = 100000;
constexpr size_t kV8MaxWasmExports = 100000;
constexpr size_t kV8MaxWasmGlobals = 1000000;
30 31
constexpr size_t kV8MaxWasmExceptions = 1000000;
constexpr size_t kV8MaxWasmExceptionTypes = 1000000;
32
constexpr size_t kV8MaxWasmDataSegments = 100000;
33 34 35
// This indicates the maximum memory size our implementation supports.
// Don't use this limit directly; use {max_initial_mem_pages()} instead
// to take the spec'ed limit as well as command line flag into account.
36
constexpr size_t kV8MaxWasmMemoryPages = 65536;  // = 4 GiB
37 38
constexpr size_t kV8MaxWasmStringSize = 100000;
constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024;  // = 1 GiB
39
constexpr size_t kV8MaxWasmFunctionSize = 7654321;
40 41 42 43
constexpr size_t kV8MaxWasmFunctionLocals = 50000;
constexpr size_t kV8MaxWasmFunctionParams = 1000;
constexpr size_t kV8MaxWasmFunctionMultiReturns = 1000;
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 49
constexpr size_t kV8MaxWasmTables = 1;
constexpr size_t kV8MaxWasmMemories = 1;
50

51 52 53 54
static_assert(kV8MaxWasmTableSize <= 4294967295,  // 2^32 - 1
              "v8 should not exceed WebAssembly's non-web embedding limits");
static_assert(kV8MaxWasmTableInitEntries <= kV8MaxWasmTableSize,
              "JS-API should not exceed v8's limit");
55

56
constexpr uint64_t kWasmMaxHeapOffset =
57 58 59 60
    static_cast<uint64_t>(
        std::numeric_limits<uint32_t>::max())  // maximum base value
    + std::numeric_limits<uint32_t>::max();    // maximum index value

61 62 63
// Defined in wasm-engine.cc.
// TODO(wasm): Make this size_t for wasm64. Currently the --wasm-max-mem-pages
// flag is only uint32_t.
64 65
V8_EXPORT_PRIVATE uint32_t max_initial_mem_pages();
V8_EXPORT_PRIVATE uint32_t max_maximum_mem_pages();
66
uint32_t max_table_init_entries();
67
size_t max_module_size();
68 69

inline uint64_t max_mem_bytes() {
70
  return uint64_t{max_maximum_mem_pages()} * kWasmPageSize;
71 72
}

73 74 75 76 77
}  // namespace wasm
}  // namespace internal
}  // namespace v8

#endif  // V8_WASM_WASM_LIMITS_H_