# We only need malloc and assert/abort, but for now just use WASI for those:
#EXTRA_LINK=/usr/lib/wasm32-wasi/libc.a
EXTRA_LINK=
- [ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,free"
+ [ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,aligned_alloc -Wl,-wrap,free"
if [ "$3" = "true" ]; then
WASM_FILE=liblightningjs_debug.wasm
$COMPILE -o liblightningjs_debug.wasm -g -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/debug/libldk.a $EXTRA_LINK
static allocation* allocation_ll = NULL;
static allocation* freed_ll = NULL;
-void* __real_malloc(size_t len);
-void* __real_calloc(size_t nmemb, size_t len);
+extern void* __real_malloc(size_t len);
+extern void* __real_calloc(size_t nmemb, size_t len);
+extern void* __real_aligned_alloc(size_t alignment, size_t size);
static void new_allocation(void* res, const char* struct_name, int lineno) {
allocation* new_alloc = __real_malloc(sizeof(allocation));
new_alloc->ptr = res;
new_allocation(res, "calloc call", 0);
return res;
}
+void* __wrap_aligned_alloc(size_t alignment, size_t size) {
+ void* res = __real_aligned_alloc(alignment, size);
+ new_allocation(res, "aligned_alloc call", 0);
+ return res;
+}
void __wrap_free(void* ptr) {
if (ptr == NULL) return;
alloc_freed(ptr, 0);