Add an optional watchdog timer (set vm.watchdog and build with -DENABLE_WATCHDOG)
This commit is contained in:
parent
3cc8e8ef79
commit
3c6b45709a
15
vm.c
15
vm.c
@ -2363,6 +2363,7 @@ void krk_initVM(int flags) {
|
||||
krk_initTable(&vm.globals);
|
||||
krk_initTable(&vm.strings);
|
||||
memset(vm.specialMethodNames,0,sizeof(vm.specialMethodNames));
|
||||
vm.watchdog = 0;
|
||||
|
||||
/* To make lookup faster, store these so we can don't have to keep boxing
|
||||
* and unboxing, copying/hashing etc. */
|
||||
@ -2968,6 +2969,20 @@ static KrkValue run() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_WATCHDOG
|
||||
if (vm.watchdog - 1 == 0) {
|
||||
fprintf(stderr, "Watchdog timer tripped.\n\n");
|
||||
krk_dumpTraceback();
|
||||
krk_resetStack();
|
||||
fprintf(stderr, "\n\n");
|
||||
vm.watchdog = 0;
|
||||
exit(0);
|
||||
return NONE_VAL();
|
||||
} else if (vm.watchdog > 0) {
|
||||
vm.watchdog--;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t opcode = READ_BYTE();
|
||||
|
||||
/* We split the instruction opcode table in half and use the top bit
|
||||
|
Loading…
Reference in New Issue
Block a user