Debian Codegraph @

runtime/platform/wasi.c

raw symbols SCIP
1 #include "platform.h"
2
3 /* WASI only implements a subset of POSIX, and given how it works it doesn't
4 * make too much sense to try too hard to emulate missing functionality.
5 *
6 * Every function needed by the runtime library and not provided by WASI
7 * is declared in wasi.h, but only a tiny number are implemented here.
8 *
9 * This means that any use of missing runtime functions from SML code will
10 * result in linker errors at the end of compilation, rather than as a runtime
11 * error later.
12 *
13 * The functions in this file are the bare minimum to get the GC working,
14 * needed by every program compiled by MLton.
15 */
16
17 size_t GC_pageSize (void) {
18 return PAGESIZE;
19 }
20
21 uintmax_t GC_physMem (void) {
22 /* WASI doesn't provide a way to query actual physical memory, so pick
23 * a reasonable amount (as of Feb 2024).
24 */
25 return 1 << 30; /* 1 GiB */
26 }
27
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,
38 __attribute__ ((unused)) int flags) {
39 return GC_mmapAnon (start, length);
40 }
41
42 void GC_release (void *base, __attribute__ ((unused)) size_t length) {
43 free (base);
44 }
45
46 void GC_displayMem (void) {
47 size_t memory_size = (size_t) sbrk(0);
48 size_t pages = memory_size / PAGESIZE;
49 printf ("memory.size: pages=%zu, pagesize=%d, total=%zu\n",
50 pages, PAGESIZE, memory_size);
51 }
52
53 void GC_diskBack_close (__attribute__ ((unused)) void *data) {
54 die ("Disk-backed heap not supported on WASI");
55 }
56
57 void GC_diskBack_read (__attribute__ ((unused)) void *data,
58 __attribute__ ((unused)) pointer buf,
59 __attribute__ ((unused)) size_t size) {
60 die ("Disk-backed heap not supported on WASI");
61 }
62
63 void *GC_diskBack_write (__attribute__ ((unused)) pointer buf,
64 __attribute__ ((unused)) size_t size) {
65 die ("Disk-backed heap not supported on WASI");
66 }
67
68 int sigemptyset (sigset_t *set) {
69 *set = (sigset_t) 0;
70 return 0;
71 }