uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 06ef423f5801a514a4733054d2b647b90636836c
parent 30ac4bdcb1efed3680f746fd8290f1aeb7a6fd27
Author: ctrlaltmilk <iris@ctrlaltmilk.net>
Date:   Wed,  6 Nov 2024 18:52:43 -0800

feat: add step limit to prevent infinite loops

On Linux, when uxnemu enters an infinite loop, the only way to stop
it is to send SIGKILL to it. This makes debugging infinite loops very
annoying. This patch adds a step limit per execution, which should be
well out of the realm of a plausible use, and helps stop infinite
loops.

Diffstat:
Msrc/uxn.c | 5+++--
Msrc/uxn.h | 2++
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/uxn.c b/src/uxn.c @@ -45,9 +45,9 @@ WITH REGARD TO THIS SOFTWARE. int uxn_eval(Uint16 pc) { - int a, b, c, x[2], y[2], z[2]; + int step, a, b, c, x[2], y[2], z[2]; if(!pc || uxn.dev[0x0f]) return 0; - for(;;) { + for(step = 0; step < STEP_LIMIT; step++) { switch(uxn.ram[pc++]) { /* BRK */ case 0x00: return 1; /* JCI */ case 0x20: if(DEC(wst)) { JMI break; } pc += 2; break; @@ -90,4 +90,5 @@ uxn_eval(Uint16 pc) /* SFT */ OPC(0x1f, PO1(a) POx(b),PUx(b >> (a & 0xf) << (a >> 4))) } } + return 0; } diff --git a/src/uxn.h b/src/uxn.h @@ -18,6 +18,8 @@ WITH REGARD TO THIS SOFTWARE. #define PAGE_PROGRAM 0x0100 +#define STEP_LIMIT 0x100000 + typedef unsigned char Uint8; typedef signed char Sint8; typedef unsigned short Uint16;