summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/c-writer.cc5
-rw-r--r--src/template/wasm2c.declarations.c11
-rw-r--r--src/tools/wasm2c.cc2
-rwxr-xr-xtest/run-spec-wasm2c.py21
-rwxr-xr-xtest/run-tests.py6
-rw-r--r--test/spec-wasm2c-prefix.c2
-rw-r--r--test/wasm2c/add.txt11
-rw-r--r--test/wasm2c/hello.txt13
-rw-r--r--test/wasm2c/minimal.txt11
-rw-r--r--test/wasm2c/spec/memory64/address.txt6
-rw-r--r--test/wasm2c/spec/memory64/address64.txt6
-rw-r--r--test/wasm2c/spec/memory64/align64.txt6
-rw-r--r--test/wasm2c/spec/memory64/binary-leb128.txt6
-rw-r--r--test/wasm2c/spec/memory64/binary.txt6
-rw-r--r--test/wasm2c/spec/memory64/endianness64.txt6
-rw-r--r--test/wasm2c/spec/memory64/float_memory64.txt6
-rw-r--r--test/wasm2c/spec/memory64/load64.txt6
-rw-r--r--test/wasm2c/spec/memory64/memory.txt6
-rw-r--r--test/wasm2c/spec/memory64/memory64.txt6
-rw-r--r--test/wasm2c/spec/memory64/memory_grow64.txt6
-rw-r--r--test/wasm2c/spec/memory64/memory_redundancy64.txt6
-rw-r--r--test/wasm2c/spec/memory64/memory_trap64.txt6
-rw-r--r--wasm2c/wasm-rt-impl.c29
-rw-r--r--wasm2c/wasm-rt.h17
25 files changed, 177 insertions, 31 deletions
diff --git a/README.md b/README.md
index 01c9109d..98342a36 100644
--- a/README.md
+++ b/README.md
@@ -58,7 +58,7 @@ Wabt has been compiled to JavaScript via emscripten. Some of the functionality i
| [bulk memory][] | `--disable-bulk-memory` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| [reference types][] | `--disable-reference-types` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| [annotations][] | `--enable-annotations` | | | ✓ | | | |
-| [memory64][] | `--enable-memory64` | | ✓ | ✓ | ✓ | ✓ | |
+| [memory64][] | `--enable-memory64` | | ✓ | ✓ | ✓ | ✓ | ✓ |
| [multi-memory][] | `--enable-multi-memory` | | ✓ | ✓ | ✓ | ✓ | ✓ |
| [extended-const][] | `--enable-extended-const` | | ✓ | ✓ | ✓ | ✓ | |
| [relaxed-simd*][] | `--enable-relaxed-simd` | | ✓ | ✓ | ✓ | ✓ | |
diff --git a/src/c-writer.cc b/src/c-writer.cc
index 3e6082bf..b2aaa869 100644
--- a/src/c-writer.cc
+++ b/src/c-writer.cc
@@ -1462,7 +1462,8 @@ void CWriter::WriteDataInitializers() {
memory->page_limits.has_max ? memory->page_limits.max : 65536;
Write("wasm_rt_allocate_memory(",
ExternalInstancePtr(ModuleFieldType::Memory, memory->name), ", ",
- memory->page_limits.initial, ", ", max, ");", Newline());
+ memory->page_limits.initial, ", ", max, ", ",
+ memory->page_limits.is_64, ");", Newline());
}
}
@@ -2773,7 +2774,7 @@ void CWriter::Write(const ExprList& exprs) {
Memory* memory = module_->memories[module_->GetMemoryIndex(
cast<MemorySizeExpr>(&expr)->memidx)];
- PushType(Type::I32);
+ PushType(memory->page_limits.IndexType());
Write(StackVar(0), " = ",
ExternalInstanceRef(ModuleFieldType::Memory, memory->name),
".pages;", Newline());
diff --git a/src/template/wasm2c.declarations.c b/src/template/wasm2c.declarations.c
index 64ad213e..0546b57d 100644
--- a/src/template/wasm2c.declarations.c
+++ b/src/template/wasm2c.declarations.c
@@ -21,9 +21,20 @@
TRAP(CALL_INDIRECT), \
((t)table.data[x].func)(__VA_ARGS__))
+#ifdef SUPPORT_MEMORY64
+#define RANGE_CHECK(mem, offset, len) \
+ do { \
+ uint64_t res; \
+ if (__builtin_add_overflow(offset, len, &res)) \
+ TRAP(OOB); \
+ if (UNLIKELY(res > mem->size)) \
+ TRAP(OOB); \
+ } while (0);
+#else
#define RANGE_CHECK(mem, offset, len) \
if (UNLIKELY(offset + (uint64_t)len > mem->size)) \
TRAP(OOB);
+#endif
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER
#define MEMCHECK(mem, a, t)
diff --git a/src/tools/wasm2c.cc b/src/tools/wasm2c.cc
index b00bce58..8994b1ac 100644
--- a/src/tools/wasm2c.cc
+++ b/src/tools/wasm2c.cc
@@ -58,7 +58,7 @@ examples:
static const std::string supported_features[] = {
"multi-memory", "multi-value", "sign-extend", "saturating-float-to-int",
- "exceptions"};
+ "exceptions", "memory64"};
static bool IsFeatureSupported(const std::string& feature) {
return std::find(std::begin(supported_features), std::end(supported_features),
diff --git a/test/run-spec-wasm2c.py b/test/run-spec-wasm2c.py
index 9e4d3f2b..bde9ece6 100755
--- a/test/run-spec-wasm2c.py
+++ b/test/run-spec-wasm2c.py
@@ -34,6 +34,7 @@ WASM2C_DIR = os.path.join(find_exe.REPO_ROOT_DIR, 'wasm2c')
IS_WINDOWS = sys.platform == 'win32'
IS_MACOS = platform.mac_ver()[0] != ''
MAX_COMMANDS_PER_FUNCTION = 1024 # GCC has trouble with extremely long function bodies
+SKIPPED = 2
def ReinterpretF32(f32_bits):
@@ -393,13 +394,13 @@ class CWriter(object):
raise Error('Unexpected action type: %s' % type_)
-def Compile(cc, c_filename, out_dir, *args):
+def Compile(cc, c_filename, out_dir, *cflags):
if IS_WINDOWS:
ext = '.obj'
else:
ext = '.o'
o_filename = utils.ChangeDir(utils.ChangeExt(c_filename, ext), out_dir)
- args = list(args)
+ args = list(cflags)
if IS_WINDOWS:
args += ['/nologo', '/MDd', '/c', c_filename, '/Fo' + o_filename]
else:
@@ -477,6 +478,7 @@ def main(args):
parser.add_argument('file', help='wast file.')
parser.add_argument('--enable-exceptions', action='store_true')
parser.add_argument('--enable-multi-memory', action='store_true')
+ parser.add_argument('--enable-memory64', action='store_true')
parser.add_argument('--disable-bulk-memory', action='store_true')
parser.add_argument('--disable-reference-types', action='store_true')
parser.add_argument('--debug-names', action='store_true')
@@ -491,6 +493,7 @@ def main(args):
wast2json.AppendOptionalArgs({
'-v': options.verbose,
'--enable-exceptions': options.enable_exceptions,
+ '--enable-memory64': options.enable_memory64,
'--enable-multi-memory': options.enable_multi_memory,
'--disable-bulk-memory': options.disable_bulk_memory,
'--disable-reference-types': options.disable_reference_types,
@@ -506,6 +509,7 @@ def main(args):
wasm2c.verbose = options.print_cmd
wasm2c.AppendOptionalArgs({
'--enable-exceptions': options.enable_exceptions,
+ '--enable-memory64': options.enable_memory64,
'--enable-multi-memory': options.enable_multi_memory})
options.cflags += shlex.split(os.environ.get('WASM2C_CFLAGS', ''))
@@ -525,7 +529,12 @@ def main(args):
cwriter = CWriter(spec_json, prefix, output, out_dir)
o_filenames = []
- includes = '-I%s' % options.wasmrt_dir
+ cflags = ['-I%s' % options.wasmrt_dir]
+ if options.enable_memory64:
+ if IS_WINDOWS:
+ sys.stderr.write('skipping: wasm2c+memory64 is not yet supported under msvc\n')
+ return SKIPPED
+ cflags.append('-DSUPPORT_MEMORY64=1')
for i, wasm_filename in enumerate(cwriter.GetModuleFilenames()):
wasm_filename = os.path.join(out_dir, wasm_filename)
@@ -533,7 +542,7 @@ def main(args):
args = ['-n', cwriter.GetModulePrefixUnmangled(i)]
wasm2c.RunWithArgs(wasm_filename, '-o', c_filename, *args)
if options.compile:
- o_filenames.append(Compile(cc, c_filename, out_dir, includes))
+ o_filenames.append(Compile(cc, c_filename, out_dir, *cflags))
cwriter.Write()
main_filename = utils.ChangeExt(json_file_path, '-main.c')
@@ -543,10 +552,10 @@ def main(args):
if options.compile:
# Compile wasm-rt-impl.
wasm_rt_impl_c = os.path.join(options.wasmrt_dir, 'wasm-rt-impl.c')
- o_filenames.append(Compile(cc, wasm_rt_impl_c, out_dir, includes))
+ o_filenames.append(Compile(cc, wasm_rt_impl_c, out_dir, *cflags))
# Compile and link -main test run entry point
- o_filenames.append(Compile(cc, main_filename, out_dir, includes))
+ o_filenames.append(Compile(cc, main_filename, out_dir, *cflags))
if IS_WINDOWS:
exe_ext = '.exe'
libs = []
diff --git a/test/run-tests.py b/test/run-tests.py
index 14b332e6..66567e28 100755
--- a/test/run-tests.py
+++ b/test/run-tests.py
@@ -384,6 +384,7 @@ class TestInfo(object):
self.slow = False
self.skip = False
self.is_roundtrip = False
+ self.is_wasm2c = False
def CreateRoundtripInfo(self, fold_exprs):
if self.tool not in ROUNDTRIP_TOOLS:
@@ -453,6 +454,7 @@ class TestInfo(object):
if tool not in TOOLS:
raise Error('Unknown tool: %s' % tool)
self.tool = tool
+ self.is_wasm2c = self.tool == 'run-spec-wasm2c'
for tool_key, tool_value in TOOLS[tool]:
self.ParseDirective(tool_key, tool_value)
@@ -666,7 +668,7 @@ class Status(object):
assert(self.isatty)
total_duration = time.time() - self.start_time
name = info.GetName() if info else ''
- if (self.total - self.skipped):
+ if self.total - self.skipped:
percent = 100 * (self.passed + self.failed) / (self.total - self.skipped)
else:
percent = 100
@@ -772,7 +774,7 @@ def HandleTestResult(status, info, result, rebase=False):
if isinstance(result, (Error, KeyboardInterrupt)):
raise result
- if info.is_roundtrip:
+ if info.is_roundtrip or info.is_wasm2c:
if result.Failed():
if result.GetLastFailure().returncode == 2:
# run-roundtrip.py returns 2 if the file couldn't be parsed.
diff --git a/test/spec-wasm2c-prefix.c b/test/spec-wasm2c-prefix.c
index 1e81fd78..b9ba0934 100644
--- a/test/spec-wasm2c-prefix.c
+++ b/test/spec-wasm2c-prefix.c
@@ -321,7 +321,7 @@ double* Z_spectestZ_global_f64(Z_spectest_instance_t* instance) {
static void init_spectest_module(Z_spectest_instance_t* instance) {
instance->spectest_global_i32 = 666;
instance->spectest_global_i64 = 666l;
- wasm_rt_allocate_memory(&instance->spectest_memory, 1, 2);
+ wasm_rt_allocate_memory(&instance->spectest_memory, 1, 2, false);
wasm_rt_allocate_funcref_table(&instance->spectest_table, 10, 20);
}
diff --git a/test/wasm2c/add.txt b/test/wasm2c/add.txt
index ec0d2b49..6f005f6d 100644
--- a/test/wasm2c/add.txt
+++ b/test/wasm2c/add.txt
@@ -84,9 +84,20 @@ u32 Z_testZ_add(Z_test_instance_t*, u32, u32);
TRAP(CALL_INDIRECT), \
((t)table.data[x].func)(__VA_ARGS__))
+#ifdef SUPPORT_MEMORY64
+#define RANGE_CHECK(mem, offset, len) \
+ do { \
+ uint64_t res; \
+ if (__builtin_add_overflow(offset, len, &res)) \
+ TRAP(OOB); \
+ if (UNLIKELY(res > mem->size)) \
+ TRAP(OOB); \
+ } while (0);
+#else
#define RANGE_CHECK(mem, offset, len) \
if (UNLIKELY(offset + (uint64_t)len > mem->size)) \
TRAP(OOB);
+#endif
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER
#define MEMCHECK(mem, a, t)
diff --git a/test/wasm2c/hello.txt b/test/wasm2c/hello.txt
index 667d0d74..0e3f0f26 100644
--- a/test/wasm2c/hello.txt
+++ b/test/wasm2c/hello.txt
@@ -114,9 +114,20 @@ void Z_testZ__start(Z_test_instance_t*);
TRAP(CALL_INDIRECT), \
((t)table.data[x].func)(__VA_ARGS__))
+#ifdef SUPPORT_MEMORY64
+#define RANGE_CHECK(mem, offset, len) \
+ do { \
+ uint64_t res; \
+ if (__builtin_add_overflow(offset, len, &res)) \
+ TRAP(OOB); \
+ if (UNLIKELY(res > mem->size)) \
+ TRAP(OOB); \
+ } while (0);
+#else
#define RANGE_CHECK(mem, offset, len) \
if (UNLIKELY(offset + (uint64_t)len > mem->size)) \
TRAP(OOB);
+#endif
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER
#define MEMCHECK(mem, a, t)
@@ -672,7 +683,7 @@ static const u8 data_segment_data_w2c_d0[] = {
};
static void init_memories(Z_test_instance_t* instance) {
- wasm_rt_allocate_memory(&instance->w2c_memory, 1, 65536);
+ wasm_rt_allocate_memory(&instance->w2c_memory, 1, 65536, 0);
LOAD_DATA(instance->w2c_memory, 8u, data_segment_data_w2c_d0, 14);
}
diff --git a/test/wasm2c/minimal.txt b/test/wasm2c/minimal.txt
index de6af442..857dc879 100644
--- a/test/wasm2c/minimal.txt
+++ b/test/wasm2c/minimal.txt
@@ -78,9 +78,20 @@ void Z_test_free(Z_test_instance_t*);
TRAP(CALL_INDIRECT), \
((t)table.data[x].func)(__VA_ARGS__))
+#ifdef SUPPORT_MEMORY64
+#define RANGE_CHECK(mem, offset, len) \
+ do { \
+ uint64_t res; \
+ if (__builtin_add_overflow(offset, len, &res)) \
+ TRAP(OOB); \
+ if (UNLIKELY(res > mem->size)) \
+ TRAP(OOB); \
+ } while (0);
+#else
#define RANGE_CHECK(mem, offset, len) \
if (UNLIKELY(offset + (uint64_t)len > mem->size)) \
TRAP(OOB);
+#endif
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER
#define MEMCHECK(mem, a, t)
diff --git a/test/wasm2c/spec/memory64/address.txt b/test/wasm2c/spec/memory64/address.txt
new file mode 100644
index 00000000..e24ff962
--- /dev/null
+++ b/test/wasm2c/spec/memory64/address.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/address.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+255/255 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/address64.txt b/test/wasm2c/spec/memory64/address64.txt
new file mode 100644
index 00000000..a716106f
--- /dev/null
+++ b/test/wasm2c/spec/memory64/address64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/address64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+238/238 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/align64.txt b/test/wasm2c/spec/memory64/align64.txt
new file mode 100644
index 00000000..2019195d
--- /dev/null
+++ b/test/wasm2c/spec/memory64/align64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/align64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+48/48 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/binary-leb128.txt b/test/wasm2c/spec/memory64/binary-leb128.txt
new file mode 100644
index 00000000..30c46dff
--- /dev/null
+++ b/test/wasm2c/spec/memory64/binary-leb128.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/binary-leb128.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+0/0 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/binary.txt b/test/wasm2c/spec/memory64/binary.txt
new file mode 100644
index 00000000..9169d71c
--- /dev/null
+++ b/test/wasm2c/spec/memory64/binary.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/binary.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+0/0 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/endianness64.txt b/test/wasm2c/spec/memory64/endianness64.txt
new file mode 100644
index 00000000..d1f8edcd
--- /dev/null
+++ b/test/wasm2c/spec/memory64/endianness64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/endianness64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+68/68 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/float_memory64.txt b/test/wasm2c/spec/memory64/float_memory64.txt
new file mode 100644
index 00000000..e223a57b
--- /dev/null
+++ b/test/wasm2c/spec/memory64/float_memory64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/float_memory64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+60/60 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/load64.txt b/test/wasm2c/spec/memory64/load64.txt
new file mode 100644
index 00000000..020a1193
--- /dev/null
+++ b/test/wasm2c/spec/memory64/load64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/load64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+37/37 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/memory.txt b/test/wasm2c/spec/memory64/memory.txt
new file mode 100644
index 00000000..5260807c
--- /dev/null
+++ b/test/wasm2c/spec/memory64/memory.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/memory.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+45/45 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/memory64.txt b/test/wasm2c/spec/memory64/memory64.txt
new file mode 100644
index 00000000..a62c2c1d
--- /dev/null
+++ b/test/wasm2c/spec/memory64/memory64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/memory64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+45/45 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/memory_grow64.txt b/test/wasm2c/spec/memory64/memory_grow64.txt
new file mode 100644
index 00000000..7e9b4034
--- /dev/null
+++ b/test/wasm2c/spec/memory64/memory_grow64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/memory_grow64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+45/45 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/memory_redundancy64.txt b/test/wasm2c/spec/memory64/memory_redundancy64.txt
new file mode 100644
index 00000000..1911eb7a
--- /dev/null
+++ b/test/wasm2c/spec/memory64/memory_redundancy64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/memory_redundancy64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+4/4 tests passed.
+;;; STDOUT ;;)
diff --git a/test/wasm2c/spec/memory64/memory_trap64.txt b/test/wasm2c/spec/memory64/memory_trap64.txt
new file mode 100644
index 00000000..a81329a2
--- /dev/null
+++ b/test/wasm2c/spec/memory64/memory_trap64.txt
@@ -0,0 +1,6 @@
+;;; TOOL: run-spec-wasm2c
+;;; STDIN_FILE: third_party/testsuite/proposals/memory64/memory_trap64.wast
+;;; ARGS*: --enable-memory64
+(;; STDOUT ;;;
+170/170 tests passed.
+;;; STDOUT ;;)
diff --git a/wasm2c/wasm-rt-impl.c b/wasm2c/wasm-rt-impl.c
index 9349be68..dbd7ce41 100644
--- a/wasm2c/wasm-rt-impl.c
+++ b/wasm2c/wasm-rt-impl.c
@@ -361,11 +361,15 @@ void wasm_rt_free(void) {
}
void wasm_rt_allocate_memory(wasm_rt_memory_t* memory,
- uint32_t initial_pages,
- uint32_t max_pages) {
- uint32_t byte_length = initial_pages * PAGE_SIZE;
+ uint64_t initial_pages,
+ uint64_t max_pages,
+ bool is64) {
+ uint64_t byte_length = initial_pages * PAGE_SIZE;
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER
/* Reserve 8GiB. */
+ assert(
+ !is64 &&
+ "memory64 is not yet compatible with WASM_RT_MEMCHECK_SIGNAL_HANDLER");
void* addr = os_mmap(0x200000000ul);
if (!addr) {
@@ -384,30 +388,31 @@ void wasm_rt_allocate_memory(wasm_rt_memory_t* memory,
memory->size = byte_length;
memory->pages = initial_pages;
memory->max_pages = max_pages;
+ memory->is64 = is64;
}
-uint32_t wasm_rt_grow_memory(wasm_rt_memory_t* memory, uint32_t delta) {
- uint32_t old_pages = memory->pages;
- uint32_t new_pages = memory->pages + delta;
+uint64_t wasm_rt_grow_memory(wasm_rt_memory_t* memory, uint64_t delta) {
+ uint64_t old_pages = memory->pages;
+ uint64_t new_pages = memory->pages + delta;
if (new_pages == 0) {
return 0;
}
if (new_pages < old_pages || new_pages > memory->max_pages) {
- return (uint32_t)-1;
+ return (uint64_t)-1;
}
- uint32_t old_size = old_pages * PAGE_SIZE;
- uint32_t new_size = new_pages * PAGE_SIZE;
- uint32_t delta_size = delta * PAGE_SIZE;
+ uint64_t old_size = old_pages * PAGE_SIZE;
+ uint64_t new_size = new_pages * PAGE_SIZE;
+ uint64_t delta_size = delta * PAGE_SIZE;
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER
uint8_t* new_data = memory->data;
int ret = os_mprotect(new_data + old_size, delta_size);
if (ret != 0) {
- return (uint32_t)-1;
+ return (uint64_t)-1;
}
#else
uint8_t* new_data = realloc(memory->data, new_size);
if (new_data == NULL) {
- return (uint32_t)-1;
+ return (uint64_t)-1;
}
#if !WABT_BIG_ENDIAN
memset(new_data + old_size, 0, delta_size);
diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h
index 07c8fd5f..d3ab3f36 100644
--- a/wasm2c/wasm-rt.h
+++ b/wasm2c/wasm-rt.h
@@ -76,8 +76,12 @@ extern "C" {
/* Signal handler is supported. Use it by default. */
#ifndef WASM_RT_MEMCHECK_SIGNAL_HANDLER
+#ifdef SUPPORT_MEMORY64
+#define WASM_RT_MEMCHECK_SIGNAL_HANDLER 0
+#else
#define WASM_RT_MEMCHECK_SIGNAL_HANDLER 1
#endif
+#endif
#else
#define WASM_RT_SIGNAL_RECOVERY_SUPPORTED 0
@@ -202,9 +206,11 @@ typedef struct {
uint8_t* data;
/** The current and maximum page count for this Memory object. If there is no
* maximum, `max_pages` is 0xffffffffu (i.e. UINT32_MAX). */
- uint32_t pages, max_pages;
+ uint64_t pages, max_pages;
/** The current size of the linear memory, in bytes. */
- uint32_t size;
+ uint64_t size;
+ /** Is this memory indexed by u64 (as opposed to default u32) */
+ bool is64;
} wasm_rt_memory_t;
/** A Table of type funcref. */
@@ -352,8 +358,9 @@ void* wasm_rt_exception(void);
* ```
*/
void wasm_rt_allocate_memory(wasm_rt_memory_t*,
- uint32_t initial_pages,
- uint32_t max_pages);
+ uint64_t initial_pages,
+ uint64_t max_pages,
+ bool is64);
/**
* Grow a Memory object by `pages`, and return the previous page count. If
@@ -370,7 +377,7 @@ void wasm_rt_allocate_memory(wasm_rt_memory_t*,
* }
* ```
*/
-uint32_t wasm_rt_grow_memory(wasm_rt_memory_t*, uint32_t pages);
+uint64_t wasm_rt_grow_memory(wasm_rt_memory_t*, uint64_t pages);
/**
* Free a Memory object.