File wavm/memory.cpp

namespace wasm

SYSCALL NUMBERING

Have a look in the sysroot at include/bits/syscall.h to determine the system call numbering.

Functions

I32 s__madvise(I32 address, I32 numBytes, I32 advice)
I32 s__membarrier(I32 a)
std::shared_ptr<faabric::state::StateKeyValue> getStateKV(I32 keyPtr, size_t size)
std::shared_ptr<faabric::state::StateKeyValue> getStateKV(I32 keyPtr)
I32 doMmap(I32 addr, I32 length, I32 prot, I32 flags, I32 fd, I32 offset)
I32 s__mmap(I32 addr, I32 length, I32 prot, I32 flags, I32 fd, I32 offset)

Note that syscall 192 is mmap2, which has the same interface as mmap except that the final argument specifies the offset into the file in 4096-byte units (instead of bytes, as is done by mmap). Given that we ignore the offset we can just treat it like mmap

WAVM_DEFINE_INTRINSIC_FUNCTION (env, "mmap", I32, wasi_mmap, I32 addr, I32 length, I32 prot, I32 flags, I32 fd, I64 offset)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "munmap", I32, wasi_munmap, I32 addr, I32 length)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "__sbrk", I32, __sbrk, I32 increment)

Note that sbrk should only be called indirectly through musl. The required behaviour is:

  • brk(0) returns the current break

  • returns the new break if successful

  • returns -1 if there’s an issue and sets errno

Note that we assume the address is page-aligned and shrink memory if necessary.

I32 s__mprotect(I32 addrPtr, I32 len, I32 prot)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "shm_open", I32, shm_open, I32 a, I32 b, I32 c)
void memoryLink()