mirror of
https://github.com/fluencelabs/musl
synced 2025-04-25 07:12:15 +00:00
Native wasm32 expand_heap implementation
This commit is contained in:
parent
edeb5004e6
commit
19296cd280
28
src/malloc/wasm32/expand_heap.c
Normal file
28
src/malloc/wasm32/expand_heap.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <limits.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include "libc.h"
|
||||||
|
#include "syscall.h"
|
||||||
|
|
||||||
|
#define WASM_PAGE_SIZE 65536
|
||||||
|
|
||||||
|
/* Expand the heap in-place use WebAssembly grow_memory operators.
|
||||||
|
* The caller is responsible for locking to prevent concurrent calls. */
|
||||||
|
|
||||||
|
void *__expand_heap(size_t *pn)
|
||||||
|
{
|
||||||
|
size_t n = *pn;
|
||||||
|
n += -n & WASM_PAGE_SIZE-1;
|
||||||
|
unsigned delta = n / WASM_PAGE_SIZE;
|
||||||
|
|
||||||
|
unsigned res = __builtin_wasm_memory_grow(0, delta);
|
||||||
|
if (res == (unsigned)-1) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *area = (void*)(WASM_PAGE_SIZE * res);
|
||||||
|
*pn = n;
|
||||||
|
return area;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user