summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-07-05 20:24:43 +0200
committerJo-Philipp Wich <jo@mein.io>2021-07-11 15:49:14 +0200
commit4ae056867d96b1795fec7f4cfd0f68b124e398cd (patch)
tree1d9ae3590b83cdd9ea9c37f35f2981d61d526efa /lib.c
parent2f77657ae97f84edcd665c4cfe00ef91b9cde1bc (diff)
lib, vm: reimplement exit() as exception type
Instead of invoking exit(3) from uc_exit(), use a new EXCEPTION_EXIT exception type to instruct the VM to shutdown cleanly. This is required to not terminate the host program in case libucode is embedded and loaded scripts invoke the exit() function. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index 750acfb..cd0f582 100644
--- a/lib.c
+++ b/lib.c
@@ -502,12 +502,15 @@ uc_exists(uc_vm *vm, size_t nargs)
return ucv_boolean_new(found);
}
-__attribute__((noreturn)) static uc_value_t *
+static uc_value_t *
uc_exit(uc_vm *vm, size_t nargs)
{
int64_t n = uc_cast_int64(uc_get_arg(0));
- exit(n);
+ vm->arg.s32 = (int32_t)n;
+ uc_vm_raise_exception(vm, EXCEPTION_EXIT, "Terminated");
+
+ return NULL;
}
static uc_value_t *