summaryrefslogtreecommitdiffhomepage
path: root/vm.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-04-07 14:54:52 +0200
committerJo-Philipp Wich <jo@mein.io>2022-04-07 15:13:02 +0200
commite0e9431c2715ec60b469258336bd6a35b344fee3 (patch)
treec3478ac21ea8e78c711579cce69be0268e2f5bc4 /vm.c
parent2b59140b2c00987b9d8c2c908d2d44c67786e71e (diff)
vm: move unhandled exception reporting out of `uc_vm_execute_chunk()`
Move the invocation of the unhandled exception callback handler out of `uc_vm_execute_chunk()` into both `uc_vm_execute()` and `uc_vm_invoke()` in order to consistently report exceptions exactly once regardless of whether a native or managed code function is executed as topmost VM call. This solves cases where the unhandled exception callback was either called multiple times or never at all. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/vm.c b/vm.c
index 45e6f42..7d4c10e 100644
--- a/vm.c
+++ b/vm.c
@@ -2602,9 +2602,6 @@ uc_vm_execute_chunk(uc_vm_t *vm)
if (vm->callframes.count <= 1) {
uc_vm_reset_callframes(vm);
- if (vm->exhandler)
- vm->exhandler(vm, &vm->exception);
-
return ERROR_RUNTIME;
}
@@ -2677,6 +2674,9 @@ uc_vm_execute(uc_vm_t *vm, uc_program_t *program, uc_value_t **retval)
break;
default:
+ if (vm->exhandler)
+ vm->exhandler(vm, &vm->exception);
+
if (retval)
*retval = NULL;
@@ -2741,8 +2741,12 @@ uc_vm_invoke(uc_vm_t *vm, const char *fname, size_t nargs, ...)
ex = uc_vm_call(vm, false, nargs);
- if (ex)
+ if (ex) {
+ if (vm->exhandler)
+ vm->exhandler(vm, &vm->exception);
+
return NULL;
+ }
return uc_vm_stack_pop(vm);
}