From f0ab6fb6ef29b90911fc2f6e6ad2de44a4f3b11d Mon Sep 17 00:00:00 2001 From: Joshua Litt Date: Tue, 6 Sep 2022 18:25:36 +0000 Subject: [PATCH] [dart2wasm] Fix memory definition. Size is number of 64kb pages. Change-Id: I4c2876ebee553d0dc219e8dd8bb6b1169799a465 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/257260 Commit-Queue: Joshua Litt Reviewed-by: Aske Simon Christensen --- pkg/dart2wasm/lib/constants.dart | 4 ++-- pkg/wasm_builder/lib/src/module.dart | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/dart2wasm/lib/constants.dart b/pkg/dart2wasm/lib/constants.dart index a29932ec60f..d4279aa6dfd 100644 --- a/pkg/dart2wasm/lib/constants.dart +++ b/pkg/dart2wasm/lib/constants.dart @@ -175,8 +175,8 @@ class Constants { ..add(oneByteStringsAsBytes)) .toBytes(); - w.Memory stringMemory = - m.addMemory(false, stringsAsBytes.length, stringsAsBytes.length); + double minSize = stringsAsBytes.length / w.Module.memoryBlockSize; + w.Memory stringMemory = m.addMemory(false, minSize.ceil(), minSize.ceil()); m.addDataSegment(stringsAsBytes, stringMemory, 0); makeStringFunctionBody(translator.oneByteStringClass, oneByteStringFunction, (b) { diff --git a/pkg/wasm_builder/lib/src/module.dart b/pkg/wasm_builder/lib/src/module.dart index ced6ed4ca1a..d38f51d01bb 100644 --- a/pkg/wasm_builder/lib/src/module.dart +++ b/pkg/wasm_builder/lib/src/module.dart @@ -35,6 +35,8 @@ class Module with SerializerMixin { int functionNameCount = 0; + static const int memoryBlockSize = 0x10000; + /// Create a new, initially empty, module. /// /// The [watchPoints] is a list of byte offsets within the final module of @@ -170,7 +172,8 @@ class Module with SerializerMixin { initialContent ??= Uint8List(0); assert((memory != null) == (offset != null)); assert(memory == null || - offset! >= 0 && offset + initialContent.length <= memory.minSize); + offset! >= 0 && + offset + initialContent.length <= memory.minSize * memoryBlockSize); final DataSegment data = DataSegment(dataSegments.length, initialContent, memory, offset); dataSegments.add(data);