Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions clang/sys/mmap_anon.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#if defined(__EMSCRIPTEN__) || defined(HVM_NO_MMAP)

#include <stdlib.h>

// Fallback for platforms without mmap (WASM, embedded).
// Uses calloc to preserve mmap's zero-initialization guarantee.
// Note: unlike mmap, calloc does not support lazy page allocation,
// so HEAP_CAP should be reduced on these platforms.
fn void *sys_mmap_anon(size_t bytes) {
return calloc(1, bytes);
}

#else

#include <sys/mman.h>

#ifndef MAP_ANONYMOUS
Expand All @@ -17,3 +31,5 @@ fn void *sys_mmap_anon(size_t bytes) {
}
return map;
}

#endif
13 changes: 13 additions & 0 deletions clang/sys/munmap_anon.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#if defined(__EMSCRIPTEN__) || defined(HVM_NO_MMAP)

#include <stdlib.h>

fn void sys_munmap_anon(void *ptr, size_t bytes) {
(void)bytes;
free(ptr);
}

#else

#include <sys/mman.h>

fn void sys_munmap_anon(void *ptr, size_t bytes) {
Expand All @@ -6,3 +17,5 @@ fn void sys_munmap_anon(void *ptr, size_t bytes) {
}
munmap(ptr, bytes);
}

#endif