Skip to content

Commit 7bd429d

Browse files
authored
Use proxy_on_memory_allocate() as a fallback for malloc(). (#80)
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 <piotrsikora@google.com>
1 parent ca141b9 commit 7bd429d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/wasm.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,19 @@ void WasmBase::registerCallbacks() {
193193

194194
void WasmBase::getFunctions() {
195195
#define _GET(_fn) wasm_vm_->getFunction(#_fn, &_fn##_);
196+
#define _GET_ALIAS(_fn, _alias) wasm_vm_->getFunction(#_alias, &_fn##_);
196197
_GET(_initialize);
197198
_GET(_start);
198199
_GET(__wasm_call_ctors);
199200

200201
_GET(malloc);
202+
if (!malloc_) {
203+
_GET_ALIAS(malloc, proxy_on_memory_allocate);
204+
}
201205
if (!malloc_) {
202206
fail(FailState::MissingFunction, "Wasm module is missing malloc function.");
203207
}
208+
#undef _GET_ALIAS
204209
#undef _GET
205210

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

0 commit comments

Comments
 (0)