MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add pointer checks for GC functions

+20 -3
+20 -3
include/arena.h
··· 2 2 #define ARENA_H 3 3 4 4 #include <gc.h> 5 + #include <stdio.h> 6 + #include <stdlib.h> 5 7 #include <string.h> 6 8 #include <minicoro.h> 7 9 ··· 30 32 } 31 33 } 32 34 33 - #define ANT_GC_MALLOC(size) GC_MALLOC_IGNORE_OFF_PAGE(size) 34 - #define ANT_GC_MALLOC_ATOMIC(size) GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(size) 35 - #define ANT_GC_REALLOC(ptr, size) GC_REALLOC(ptr, size) 35 + static inline void *ant_gc_check_ptr(void *p, const char *func) { 36 + if (p && ((uintptr_t)p >> 48) != 0) { 37 + fprintf(stderr, 38 + "FATAL: %s returned pointer %p outside 48-bit NaN-boxing range\n" 39 + "Please report this issue with your OS/architecture details.\n", func, p 40 + ); abort(); 41 + } 42 + 43 + return p; 44 + } 45 + 46 + #define ANT_GC_MALLOC(size) \ 47 + ant_gc_check_ptr(GC_MALLOC_IGNORE_OFF_PAGE(size), "GC_MALLOC") 48 + #define ANT_GC_MALLOC_ATOMIC(size) \ 49 + ant_gc_check_ptr(GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(size), "GC_MALLOC_ATOMIC") 50 + #define ANT_GC_REALLOC(ptr, size) \ 51 + ant_gc_check_ptr(GC_REALLOC(ptr, size), "GC_REALLOC") 52 + 36 53 #define ANT_GC_FREE(ptr) GC_FREE(ptr) 37 54 38 55 #define ANT_GC_REGISTER_ROOT(ptr)