summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-09-24 09:56:04 +0200
committerJo-Philipp Wich <jo@mein.io>2021-09-24 09:56:04 +0200
commitce4a7d96a648d37a95ebe07dfef522073c1b2fae (patch)
treec736345a8db0702b7b6804c1479e180cb2014352
parent218e8221a80a8fcf8bfd6cc115d7a0ae00a65ead (diff)
vm: reset callframes before invoking unhandled exception handler
Reset all callframes when dealing with an unhandled exception to avoid resuming the code which raised the exception when restarting the VM later, e.g. through uc_vm_call() or uc_vm_invoke(). Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--examples/exception-handler.c2
-rw-r--r--vm.c2
2 files changed, 3 insertions, 1 deletions
diff --git a/examples/exception-handler.c b/examples/exception-handler.c
index 1e722ec..a9a0299 100644
--- a/examples/exception-handler.c
+++ b/examples/exception-handler.c
@@ -30,7 +30,7 @@ static const char *program = MULTILINE_STRING(
doesnotexist();
}
- fail();
+ map([1], x => fail(x));
%}
);
diff --git a/vm.c b/vm.c
index 2c8f524..65d6c81 100644
--- a/vm.c
+++ b/vm.c
@@ -2278,6 +2278,8 @@ uc_vm_execute_chunk(uc_vm_t *vm)
while (!uc_vm_handle_exception(vm)) {
/* no further callframe to pop, report unhandled exception and terminate */
if (vm->callframes.count <= 1) {
+ uc_vm_reset_callframes(vm);
+
if (vm->exhandler)
vm->exhandler(vm, &vm->exception);