]>
git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/sources/sbrk.c
4 #include <__macro_PAGESIZE.h>
6 // Bare-bones implementation of sbrk.
7 void *sbrk(intptr_t increment
) {
8 // sbrk(0) returns the current memory size.
10 // The wasm spec doesn't guarantee that memory.grow of 0 always succeeds.
11 return (void *)(__builtin_wasm_memory_size(0) * PAGESIZE
);
14 // We only support page-size increments.
15 if (increment
% PAGESIZE
!= 0) {
19 // WebAssembly doesn't support shrinking linear memory.
24 uintptr_t old
= __builtin_wasm_memory_grow(0, (uintptr_t)increment
/ PAGESIZE
);
26 if (old
== SIZE_MAX
) {
31 return (void *)(old
* PAGESIZE
);