]> git.bitcoin.ninja Git - ldk-java/commitdiff
[TS] Wrap `aligned_alloc` as well as other malloc's.
authorMatt Corallo <git@bluematt.me>
Sun, 16 Jan 2022 22:25:20 +0000 (22:25 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 17 Jan 2022 04:34:51 +0000 (04:34 +0000)
genbindings.sh
typescript_strings.py

index 3d6ea6bcef5f033c9eae90f07c07a4f6f2513305..9d42bbbd25e2a6c5fa34d57dd564c2001d2ab3f8 100755 (executable)
@@ -203,7 +203,7 @@ else
        # 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
index 2979481d1e9ab4648d4d532246e090284923e3ea..7d63af91a69f405765cdfd67c54fb31eea1c07c4 100644 (file)
@@ -376,8 +376,9 @@ typedef struct allocation {
 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;
@@ -450,6 +451,11 @@ void* __wrap_calloc(size_t nmemb, size_t len) {
        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);