WasmLimits.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #ifdef ENABLE_WASM
  7. namespace Wasm {
  8. class Limits {
  9. // The limits are agreed upon with other engines for consistency.
  10. static const uint32 MaxTypes = 1000000;
  11. static const uint32 MaxFunctions = 1000000;
  12. static const uint32 MaxImports = 100000;
  13. static const uint32 MaxExports = 100000;
  14. static const uint32 MaxGlobals = 1000000;
  15. static const uint32 MaxDataSegments = 100000;
  16. static const uint32 MaxElementSegments = 10000000;
  17. static const uint32 MaxTableSize = DEFAULT_CONFIG_WasmMaxTableSize;
  18. static const uint32 MaxStringSize = 100000;
  19. static const uint32 MaxFunctionLocals = 50000;
  20. static const uint32 MaxFunctionParams = 1000;
  21. static const uint32 MaxFunctionReturns = 10000; // todo::We need to figure out what is the right limit here
  22. static const uint32 MaxBrTableElems = 1000000;
  23. static const uint32 MaxMemoryInitialPages = Js::ArrayBuffer::MaxArrayBufferLength / Js::WebAssembly::PageSize;
  24. static const uint32 MaxMemoryMaximumPages = 65536;
  25. static const uint32 MaxModuleSize = 1024 * 1024 * 1024;
  26. static const uint32 MaxFunctionSize = 7654321;
  27. public:
  28. // Use accessors to easily switch to config flags if needed
  29. static uint32 GetMaxTypes() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxTypes; }
  30. static uint32 GetMaxFunctions() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxFunctions; }
  31. static uint32 GetMaxImports() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxImports; }
  32. static uint32 GetMaxExports() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxExports; }
  33. static uint32 GetMaxGlobals() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxGlobals; }
  34. static uint32 GetMaxDataSegments() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxDataSegments; }
  35. static uint32 GetMaxElementSegments() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxElementSegments; }
  36. static uint32 GetMaxTableSize() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : CONFIG_FLAG(WasmMaxTableSize); }
  37. static uint32 GetMaxStringSize() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxStringSize; }
  38. static uint32 GetMaxFunctionLocals() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxFunctionLocals; }
  39. static uint32 GetMaxFunctionParams() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxFunctionParams; }
  40. static uint32 GetMaxFunctionReturns() {
  41. if (CONFIG_FLAG(WasmMultiValue))
  42. {
  43. return CONFIG_FLAG(WasmIgnoreLimits) ? (UINT32_MAX - 1) : MaxFunctionReturns;
  44. }
  45. return 1;
  46. }
  47. static uint64 GetMaxBrTableElems() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxBrTableElems; }
  48. static uint32 GetMaxMemoryInitialPages() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxMemoryInitialPages; }
  49. static uint32 GetMaxMemoryMaximumPages() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxMemoryMaximumPages; }
  50. static uint32 GetMaxModuleSize() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxModuleSize; }
  51. static uint32 GetMaxFunctionSize() { return CONFIG_FLAG(WasmIgnoreLimits) ? UINT32_MAX : MaxFunctionSize; }
  52. };
  53. }
  54. #endif