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.

prevent segfault on cstack

+15 -3
+12
include/silver/engine.h
··· 825 825 return sv_call_closure(vm, js, closure, callee_func, ctx, out_this); 826 826 } 827 827 828 + static inline bool sv_check_c_stack_overflow(ant_t *js) { 829 + volatile char marker; 830 + if (js->cstk.limit == 0 || js->cstk.base == NULL) return false; 831 + uintptr_t base = (uintptr_t)js->cstk.base; 832 + uintptr_t curr = (uintptr_t)▮ 833 + size_t used = (base > curr) ? (base - curr) : (curr - base); 834 + return used > js->cstk.limit; 835 + } 836 + 828 837 static inline ant_value_t sv_vm_call( 829 838 sv_vm_t *vm, ant_t *js, ant_value_t func, 830 839 ant_value_t this_val, ant_value_t *args, int argc, 831 840 ant_value_t *out_this, bool is_construct_call 832 841 ) { 842 + if (sv_check_c_stack_overflow(js)) 843 + return js_mkerr_typed(js, JS_ERR_RANGE | JS_ERR_NO_STACK, "Maximum call stack size exceeded"); 844 + 833 845 if (!is_construct_call) js->new_target = js_mkundef(); 834 846 if (out_this) *out_this = this_val; 835 847
+3 -3
src/silver/engine.c
··· 233 233 if (!vm || !vm->js || !func) return mkval(T_ERR, 0); 234 234 ant_t *js = vm->js; 235 235 if (vm->fp + 1 >= vm->max_frames && !sv_vm_grow_frames(vm)) 236 - return js_mkerr_typed(js, JS_ERR_RANGE | JS_ERR_NO_STACK, "Maximum AOT call stack size exceeded"); 236 + return js_mkerr_typed(js, JS_ERR_RANGE | JS_ERR_NO_STACK, "Maximum call stack size exceeded"); 237 237 238 238 int saved_fp = vm->fp; 239 239 vm->fp = saved_fp + 1; ··· 788 788 } 789 789 #endif 790 790 if (vm->fp + 1 >= vm->max_frames && !sv_vm_grow_frames(vm)) { 791 - sv_err = js_mkerr_typed(js, JS_ERR_RANGE | JS_ERR_NO_STACK, "Maximum AOT call stack size exceeded"); 791 + sv_err = js_mkerr_typed(js, JS_ERR_RANGE | JS_ERR_NO_STACK, "Maximum call stack size exceeded"); 792 792 goto sv_throw; 793 793 } 794 794 if (closure->func->is_arrow || vtype(closure->bound_this) != T_UNDEF) call_this = closure->bound_this; ··· 911 911 } 912 912 #endif 913 913 if (vm->fp + 1 >= vm->max_frames && !sv_vm_grow_frames(vm)) { 914 - sv_err = js_mkerr_typed(js, JS_ERR_RANGE | JS_ERR_NO_STACK, "Maximum AOT call stack size exceeded"); 914 + sv_err = js_mkerr_typed(js, JS_ERR_RANGE | JS_ERR_NO_STACK, "Maximum call stack size exceeded"); 915 915 goto sv_throw; 916 916 } 917 917 if (closure->func->is_arrow || vtype(closure->bound_this) != T_UNDEF)