tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit f49212e6d50613b3ce7f7aedac5c364a33d542ae
parent 5fca0dd3b2149782d64aaacd4e8d4f83fa556341
Author: Andy Wingo <wingo@igalia.com>
Date:   Mon,  8 Dec 2025 16:02:52 +0000

Bug 1977854 - Add PageSize to wasm::Limits.  r=rhunt,bvisness

Differential Revision: https://phabricator.services.mozilla.com/D257725

Diffstat:
Mjs/src/wasm/AsmJS.cpp | 4+++-
Mjs/src/wasm/WasmBuiltinModule.cpp | 4++--
Mjs/src/wasm/WasmJS.cpp | 10+++++++---
Mjs/src/wasm/WasmModuleTypes.h | 16++++++++++------
Mjs/src/wasm/WasmValidate.cpp | 4++++
5 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/js/src/wasm/AsmJS.cpp b/js/src/wasm/AsmJS.cpp @@ -2094,7 +2094,8 @@ class MOZ_STACK_CLASS ModuleValidator : public ModuleValidatorShared { return false; } - Limits limits = Limits(mask + 1, Nothing(), Shareable::False); + Limits limits = + Limits(mask + 1, Nothing(), Shareable::False, PageSize::Standard); codeMeta_->asmJSSigToTableIndex[sigIndex] = codeMeta_->tables.length(); if (!codeMeta_->tables.emplaceBack(limits, RefType::func(), /* initExpr */ Nothing(), @@ -2159,6 +2160,7 @@ class MOZ_STACK_CLASS ModuleValidator : public ModuleValidatorShared { limits.initial = memory_.minPages(); limits.maximum = Nothing(); limits.addressType = AddressType::I32; + limits.pageSize = PageSize::Standard; if (!codeMeta_->memories.append(MemoryDesc(limits))) { return nullptr; } diff --git a/js/src/wasm/WasmBuiltinModule.cpp b/js/src/wasm/WasmBuiltinModule.cpp @@ -192,8 +192,8 @@ bool CompileBuiltinModule(JSContext* cx, ReportOutOfMemory(cx); return false; } - if (!codeMeta->memories.append( - MemoryDesc(Limits(0, Nothing(), memory->shared)))) { + if (!codeMeta->memories.append(MemoryDesc( + Limits(0, Nothing(), memory->shared, PageSize::Standard)))) { ReportOutOfMemory(cx); return false; } diff --git a/js/src/wasm/WasmJS.cpp b/js/src/wasm/WasmJS.cpp @@ -789,6 +789,10 @@ static bool GetLimits(JSContext* cx, HandleObject obj, LimitsKind kind, } } } + + // TODO: Should be updated when the JS API for custom page sizes + // is finalized, see https://bugzilla.mozilla.org/show_bug.cgi?id=1985679 + limits->pageSize = PageSize::Standard; } return true; @@ -2178,8 +2182,8 @@ bool WasmMemoryObject::construct(JSContext* cx, unsigned argc, Value* vp) { return false; } - if (Pages::fromPageCount(limits.initial, PageSize::Standard) > - MaxMemoryPages(limits.addressType, PageSize::Standard)) { + if (Pages::fromPageCount(limits.initial, limits.pageSize) > + MaxMemoryPages(limits.addressType, limits.pageSize)) { JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_MEM_IMP_LIMIT); return false; @@ -2662,7 +2666,7 @@ uint64_t WasmMemoryObject::grow(Handle<WasmMemoryObject*> memory, // TODO (large ArrayBuffer): See more information at the definition of // MaxMemoryBytes(). MOZ_ASSERT( - MaxMemoryBytes(memory->addressType(), PageSize::Standard) <= UINT32_MAX, + MaxMemoryBytes(memory->addressType(), memory->pageSize()) <= UINT32_MAX, "Avoid 32-bit overflows"); #endif diff --git a/js/src/wasm/WasmModuleTypes.h b/js/src/wasm/WasmModuleTypes.h @@ -796,16 +796,20 @@ struct Limits { // memories. Shareable shared; - WASM_CHECK_CACHEABLE_POD(addressType, initial, maximum, shared); + // `pageSize` is used only for memories. Defaults to the standard page size + // but may be set to other values with the custom page size proposal. + PageSize pageSize = PageSize::Standard; + + WASM_CHECK_CACHEABLE_POD(addressType, initial, maximum, shared, pageSize); Limits() = default; - explicit Limits(uint64_t initial, - const mozilla::Maybe<uint64_t>& maximum = mozilla::Nothing(), - Shareable shared = Shareable::False) + Limits(uint64_t initial, const mozilla::Maybe<uint64_t>& maximum, + Shareable shared, PageSize pageSize) : addressType(AddressType::I32), initial(initial), maximum(maximum), - shared(shared) {} + shared(shared), + pageSize(pageSize) {} }; WASM_DECLARE_CACHEABLE_POD(Limits); @@ -834,7 +838,7 @@ struct MemoryDesc { AddressType addressType() const { return limits.addressType; } - PageSize pageSize() const { return PageSize::Standard; } + PageSize pageSize() const { return limits.pageSize; } // The initial length of this memory in pages. Pages initialPages() const { diff --git a/js/src/wasm/WasmValidate.cpp b/js/src/wasm/WasmValidate.cpp @@ -2855,6 +2855,10 @@ static bool DecodeLimits(Decoder& d, LimitsKind kind, Limits* limits) { limits->maximum.emplace(maximum); } + if (kind == LimitsKind::Memory) { + limits->pageSize = PageSize::Standard; + } + return true; }