wip: working on infinite loop handling in vm
This commit is contained in:
+22
-1
@@ -4,6 +4,7 @@
|
||||
#include <common/fzl_value.h>
|
||||
#include <compiler/utils/fzl_const_pool.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -13,6 +14,11 @@
|
||||
#include <vm/fzl_vm_object.h>
|
||||
|
||||
char last_err[256];
|
||||
size_t last_jmp_ip = 0;
|
||||
|
||||
// NOTE: add `--max-iter` option for limit
|
||||
size_t max_iter_limit = 100000;
|
||||
size_t total_jmp_on_same = 0;
|
||||
|
||||
static char *expect_hdr = "FZL\0\1";
|
||||
|
||||
@@ -667,7 +673,22 @@ int fzl_vm_run(fzl_vm_t *vm)
|
||||
return -1;
|
||||
}
|
||||
uint64_t jmp_ip = vm->ops[++vm->ip];
|
||||
vm->ip = jmp_ip - 1;
|
||||
if (jmp_ip == last_jmp_ip)
|
||||
total_jmp_on_same++;
|
||||
else
|
||||
total_jmp_on_same = 0;
|
||||
|
||||
if (total_jmp_on_same > max_iter_limit)
|
||||
{
|
||||
snprintf(last_err, sizeof(last_err),
|
||||
"runtime error - exceeded max loop jumps (infinite loop?)\n"
|
||||
"If you thinks there's mistake, change jumps limit with "
|
||||
"--max-iter=N");
|
||||
return -1;
|
||||
}
|
||||
|
||||
vm->ip = jmp_ip - 1;
|
||||
last_jmp_ip = jmp_ip;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user