Skip to content

Commit

Permalink
Use proxy_on_memory_allocate() as a fallback for malloc(). (#80)
Browse files Browse the repository at this point in the history
On some targets (e.g. Rust's wasm32-wasi), it's impossible to export
malloc due to a collision with libc's malloc.

Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora authored Oct 26, 2020
1 parent ca141b9 commit 7bd429d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,19 @@ void WasmBase::registerCallbacks() {

void WasmBase::getFunctions() {
#define _GET(_fn) wasm_vm_->getFunction(#_fn, &_fn##_);
#define _GET_ALIAS(_fn, _alias) wasm_vm_->getFunction(#_alias, &_fn##_);
_GET(_initialize);
_GET(_start);
_GET(__wasm_call_ctors);

_GET(malloc);
if (!malloc_) {
_GET_ALIAS(malloc, proxy_on_memory_allocate);
}
if (!malloc_) {
fail(FailState::MissingFunction, "Wasm module is missing malloc function.");
}
#undef _GET_ALIAS
#undef _GET

#define _GET_PROXY(_fn) wasm_vm_->getFunction("proxy_" #_fn, &_fn##_);
Expand Down

0 comments on commit 7bd429d

Please sign in to comment.