Skip to content

Commit 9eb4b36

Browse files
committed
Don't use WASI emulated mmap
It does not return aligned memory (WebAssembly/wasi-libc#207) and we don't need it for anything fancy. Instead, just use posix_memalign() and free() for the GC functions.
1 parent 62c1ffb commit 9eb4b36

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

bin/mlton-script

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ for arg in "$@"; do
131131
-target-cc-opt wasi '-D_WASI_EMULATED_SIGNAL' \
132132
-target-cc-opt wasi '-D_WASI_EMULATED_PROCESS_CLOCKS' \
133133
-target-cc-opt wasi '-D_WASI_EMULATED_GETPID' \
134-
-target-cc-opt wasi '-D_WASI_EMULATED_MMAN' \
135134
-target-cc-opt x86 '-m32' \
136135
-target-link-opt aix '-maix64' \
137136
-target-link-opt alpha \
@@ -150,7 +149,6 @@ for arg in "$@"; do
150149
-target-link-opt wasi '-lwasi-emulated-signal' \
151150
-target-link-opt wasi '-lwasi-emulated-process-clocks' \
152151
-target-link-opt wasi '-lwasi-emulated-getpid' \
153-
-target-link-opt wasi '-lwasi-emulated-mman' \
154152
-target-link-opt x86 '-m32' \
155153
-profile-exclude '\$\(SML_LIB\)'
156154
fi

runtime/Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,10 @@ ifeq ($(TARGET_OS), wasi)
121121
WASMTIME := wasmtime
122122
XCPPFLAGS += -D_WASI_EMULATED_SIGNAL \
123123
-D_WASI_EMULATED_PROCESS_CLOCKS \
124-
-D_WASI_EMULATED_GETPID \
125-
-D_WASI_EMULATED_MMAN
124+
-D_WASI_EMULATED_GETPID
126125
XLDFLAGS += -lwasi-emulated-signal \
127126
-lwasi-emulated-process-clocks \
128-
-lwasi-emulated-getpid \
129-
-lwasi-emulated-mman
127+
-lwasi-emulated-getpid
130128
endif
131129

132130
ifeq ($(TARGET_OS), mingw)

runtime/platform/wasi.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "platform.h"
22

3-
#include "platform/mremap.c"
4-
#include "platform/use-mmap.c"
5-
63
/* WASI only implements a subset of POSIX, and given how it works it doesn't
74
* make too much sense to try too hard to emulate missing functionality.
85
*
@@ -18,13 +15,7 @@
1815
*/
1916

2017
size_t GC_pageSize (void) {
21-
long int pageSize;
22-
23-
pageSize = sysconf (_SC_PAGESIZE);
24-
if (pageSize < 0)
25-
diee ("GC_pageSize error: sysconf (_SC_PAGESIZE) failed");
26-
27-
return (size_t)pageSize;
18+
return PAGESIZE;
2819
}
2920

3021
uintmax_t GC_physMem (void) {
@@ -34,12 +25,21 @@ uintmax_t GC_physMem (void) {
3425
return 1 << 30; /* 1 GiB */
3526
}
3627

37-
void* GC_extendHead (void *base, size_t length) {
38-
return mmapAnon (base, length);
28+
void *GC_mmapAnon (__attribute__ ((unused)) void *start, size_t length) {
29+
void *mem;
30+
int err = posix_memalign (&mem, PAGESIZE, length);
31+
if (err) {
32+
return (void *) -1;
33+
}
34+
return memset(mem, 0, length);
35+
}
36+
37+
void *GC_mmapAnonFlags (void *start, size_t length, __attribute__ ((unused)) int flags) {
38+
return GC_mmapAnon(start, length);
3939
}
4040

41-
void* GC_extendTail (void *base, size_t length) {
42-
return mmapAnon (base, length);
41+
void GC_release (void *base, __attribute__ ((unused)) size_t length) {
42+
free (base);
4343
}
4444

4545
void GC_displayMem (void) {

runtime/platform/wasi.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <netinet/tcp.h>
99
#include <poll.h>
1010
#include <sys/ioctl.h>
11-
#include <sys/mman.h>
1211
#include <sys/resource.h>
1312
#include <sys/socket.h>
1413
#include <sys/stat.h>
@@ -20,7 +19,7 @@
2019

2120
#define HAS_FEROUND TRUE
2221
#define HAS_MSG_DONTWAIT TRUE
23-
#define HAS_REMAP TRUE
22+
#define HAS_REMAP FALSE
2423
#define HAS_SIGALTSTACK FALSE
2524
#define NEEDS_SIGALTSTACK_EXEC FALSE
2625
#define HAS_SPAWN FALSE

0 commit comments

Comments
 (0)