Skip to content

Commit 16fde82

Browse files
committed
faasm: force all heap allocations to use __sbrk
1 parent e35515b commit 16fde82

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

dlmalloc/src/dlmalloc.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66

77
// Define configuration macros for dlmalloc.
88

9-
#ifdef __faasm
10-
// Faasm supports mmap/ munmap
11-
#define HAVE_MMAP 1
9+
// WebAssembly doesn't have mmap-style memory allocation.
10+
#define HAVE_MMAP 0
1211

13-
// Faasm supports normal wasm memory growth, but we need to be able to reclaim
14-
// memory, so force everything through mmap/ munmap
12+
#ifdef __faasm
13+
// Faasm supports memory growth and shrinkage with sbrk-style positive and
14+
// negative allocation. We need to be explicit about sbrk usage (HAVE_MORECORE
15+
// set to 1) and not mmap/munmap usage (HAVE_MMAP set to 0, default in WASM).
16+
// Note that this does not mean that we don't support application code using
17+
// mmap/munmap, it means that heap is only managed with sbrk
1518
#define HAVE_MORECORE 1
1619
#define MORECORE_CONTIGUOUS 1
1720

18-
// Faasm supports shrinking linear memory using offsets
21+
// We don't shrink the linear memory, but claim the pages for the runtime, and
22+
// move the offset down, so that subsequent allocations can re-use the free-ed
23+
// memory
1924
#define MORECORE_CANNOT_TRIM 0
20-
2125
#else
22-
// WebAssembly doesn't have mmap-style memory allocation.
23-
#define HAVE_MMAP 0
24-
2526
// WebAssembly doesn't support shrinking linear memory.
2627
#define MORECORE_CANNOT_TRIM 1
2728
#endif

0 commit comments

Comments
 (0)