flag used for actor stopping insetad of counter

This commit is contained in:
2026-02-17 17:59:12 -06:00
parent 5ee51198a7
commit b16fa75706
10 changed files with 115 additions and 109 deletions

View File

@@ -678,18 +678,6 @@ static JSValue reg_vm_binop(JSContext *ctx, int op, JSValue a, JSValue b) {
return JS_ThrowTypeError(ctx, "type mismatch in binary operation");
}
/* Check for interrupt — returns: 0 = continue, -1 = hard kill, 1 = suspend */
int reg_vm_check_interrupt(JSContext *ctx) {
if (--ctx->interrupt_counter <= 0) {
ctx->interrupt_counter = JS_INTERRUPT_COUNTER_INIT;
if (ctx->interrupt_handler) {
int r = ctx->interrupt_handler(ctx->rt, ctx->interrupt_opaque);
if (r < 0) return -1; /* hard kill */
if (r > 0) return 1; /* suspend request */
}
}
return 0;
}
#ifdef HAVE_ASAN
void __asan_on_error(void) {
@@ -1406,12 +1394,17 @@ vm_dispatch:
int offset = MACH_GET_sJ(instr);
pc = (uint32_t)((int32_t)pc + offset);
if (offset < 0) {
int irc = reg_vm_check_interrupt(ctx);
if (irc < 0) {
int pf = atomic_load_explicit(&ctx->pause_flag, memory_order_relaxed);
if (pf == 2) {
result = JS_ThrowInternalError(ctx, "interrupted");
goto done;
}
if (irc > 0) goto suspend;
if (pf == 1) {
if (ctx->vm_call_depth > 0)
atomic_store_explicit(&ctx->pause_flag, 0, memory_order_relaxed);
else
goto suspend;
}
}
VM_BREAK();
}
@@ -1426,12 +1419,17 @@ vm_dispatch:
int offset = MACH_GET_sBx(instr);
pc = (uint32_t)((int32_t)pc + offset);
if (offset < 0) {
int irc = reg_vm_check_interrupt(ctx);
if (irc < 0) {
int pf = atomic_load_explicit(&ctx->pause_flag, memory_order_relaxed);
if (pf == 2) {
result = JS_ThrowInternalError(ctx, "interrupted");
goto done;
}
if (irc > 0) goto suspend;
if (pf == 1) {
if (ctx->vm_call_depth > 0)
atomic_store_explicit(&ctx->pause_flag, 0, memory_order_relaxed);
else
goto suspend;
}
}
}
VM_BREAK();
@@ -1447,12 +1445,17 @@ vm_dispatch:
int offset = MACH_GET_sBx(instr);
pc = (uint32_t)((int32_t)pc + offset);
if (offset < 0) {
int irc = reg_vm_check_interrupt(ctx);
if (irc < 0) {
int pf = atomic_load_explicit(&ctx->pause_flag, memory_order_relaxed);
if (pf == 2) {
result = JS_ThrowInternalError(ctx, "interrupted");
goto done;
}
if (irc > 0) goto suspend;
if (pf == 1) {
if (ctx->vm_call_depth > 0)
atomic_store_explicit(&ctx->pause_flag, 0, memory_order_relaxed);
else
goto suspend;
}
}
}
VM_BREAK();