File WasmModule.h

namespace wasm

SYSCALL NUMBERING

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

Enums

enum ThreadRequestType

Values:

enumerator UNSET
enumerator PTHREAD
enumerator OPENMP
class WasmExitException : public exception

Public Functions

inline explicit WasmExitException(int exitCode)

Public Members

int exitCode
class WasmModule

Subclassed by wasm::EnclaveInterface, wasm::WAMRWasmModule, wasm::WAVMWasmModule

Public Functions

WasmModule()
explicit WasmModule(int threadPoolSizeIn)
virtual ~WasmModule()
virtual void reset(faabric::Message &msg, const std::string &snapshotKey)
void bindToFunction(faabric::Message &msg, bool cache = true)
int32_t executeTask(int threadPoolIdx, int msgIdx, std::shared_ptr<faabric::BatchExecuteRequest> req)
virtual int32_t executeFunction(faabric::Message &msg)
bool isBound()
std::string getBoundUser()
std::string getBoundFunction()
virtual void flush()
uint32_t getArgc()
uint32_t getArgvBufferSize()
virtual void writeArgvToMemory(uint32_t wasmArgvPointers, uint32_t wasmArgvBuffer)
virtual void writeWasmEnvToMemory(uint32_t envPointers, uint32_t envBuffer)
WasmEnvironment &getWasmEnvironment()
storage::FileSystem &getFileSystem()
virtual void doThrowException(std::exception &e)
ssize_t captureStdout(const struct ::iovec *iovecs, int iovecCount)
ssize_t captureStdout(const void *buffer)
std::string getCapturedStdout()
void clearCapturedStdout()
uint32_t getCurrentBrk()
virtual void setMemorySize(size_t nBytes)
uint32_t growMemory(size_t nBytes)
uint32_t shrinkMemory(size_t nBytes)
uint32_t mmapMemory(size_t nBytes)
virtual uint32_t mmapFile(uint32_t fp, size_t length)
void unmapMemory(uint32_t offset, size_t nBytes)
uint32_t createMemoryGuardRegion(uint32_t wasmOffset)
virtual uint32_t mapSharedStateMemory(const std::shared_ptr<faabric::state::StateKeyValue> &kv, long offset, uint32_t length)

Maps the given state into the module’s memory.

If we are dealing with a chunk of a larger state value, the host memory will be reserved for the full value, but only the necessary wasm pages will be created. Loading many chunks of the same value leads to fragmentation, but usually only one or two chunks are loaded per module.

To perform the mapping we need to ensure allocated memory is page-aligned.

virtual uint8_t *wasmPointerToNative(uint32_t wasmPtr)
virtual size_t getMemorySizeBytes()
virtual size_t getMaxMemoryPages()
virtual uint8_t *getMemoryBase()
std::shared_ptr<faabric::util::SnapshotData> getSnapshotData()
std::span<uint8_t> getMemoryView()
std::string snapshot(bool locallyRestorable = true)
void restore(const std::string &snapshotKey)
void queuePthreadCall(threads::PthreadCall call)
int awaitPthreadCall(faabric::Message *msg, int pthreadPtr)
std::vector<uint32_t> getThreadStacks()
std::shared_ptr<std::mutex> getPthreadMutex(uint32_t id)
std::shared_ptr<std::mutex> getOrCreatePthreadMutex(uint32_t id)
void addMergeRegionForNextThreads(uint32_t wasmPtr, size_t regionSize, faabric::util::SnapshotDataType dataType, faabric::util::SnapshotMergeOperation mergeOp)
std::vector<faabric::util::SnapshotMergeRegion> getMergeRegions()
void clearMergeRegions()
virtual int32_t executeOMPThread(int threadPoolIdx, uint32_t stackTop, faabric::Message &msg)
virtual int32_t executePthread(int threadPoolIdx, uint32_t stackTop, faabric::Message &msg)
virtual void printDebugInfo()

Protected Functions

int getStdoutFd()
void prepareArgcArgv(const faabric::Message &msg)
virtual void doBindToFunction(faabric::Message &msg, bool cache)
virtual bool doGrowMemory(uint32_t pageChange)
void snapshotWithKey(const std::string &snapKey)
void ignoreThreadStacksInSnapshot(const std::string &snapKey)
void createThreadStacks()

Protected Attributes

std::shared_mutex moduleMutex
std::atomic<uint32_t> currentBrk = 0
std::string boundUser
std::string boundFunction
bool _isBound = false
storage::FileSystem filesystem
WasmEnvironment wasmEnvironment
int stdoutMemFd = 0
ssize_t stdoutSize = 0
int threadPoolSize = 0
std::vector<uint32_t> threadStacks
unsigned int argc
std::vector<std::string> argv
size_t argvBufferSize
std::vector<threads::PthreadCall> queuedPthreadCalls
std::unordered_map<int32_t, uint32_t> pthreadPtrsToChainedCalls
std::vector<std::pair<uint32_t, int32_t>> lastPthreadResults
std::vector<faabric::util::SnapshotMergeRegion> mergeRegions
std::shared_mutex pthreadLocksMx
std::unordered_map<uint32_t, std::shared_ptr<std::mutex>> pthreadLocks
std::shared_mutex sharedMemWasmPtrsMutex
std::unordered_map<std::string, uint32_t> sharedMemWasmPtrs
faabric::snapshot::SnapshotRegistry &reg