~rabbits/public-inbox

uxn: feat: add step limit to prevent infinite loops v1 PROPOSED

ctrlaltmilk: 1
 feat: add step limit to prevent infinite loops

 2 files changed, 5 insertions(+), 2 deletions(-)
#1364589 .build.yml success
Thanks! Merged :)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rabbits/public-inbox/patches/55850/mbox | git am -3
Learn more about email & git

[PATCH uxn] feat: add step limit to prevent infinite loops Export this patch

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. 

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

diff --git a/src/uxn.c b/src/uxn.c
index a56fdc0..55a12c1 100644
--- 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
index c63e6bf..ab1d337 100644
--- 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;
-- 
2.47.0
uxn/patches/.build.yml: SUCCESS in 23s

[feat: add step limit to prevent infinite loops][0] from [ctrlaltmilk][1]

[0]: https://lists.sr.ht/~rabbits/public-inbox/patches/55850
[1]: mailto:iris@ctrlaltmilk.net

✓ #1364589 SUCCESS uxn/patches/.build.yml https://builds.sr.ht/~rabbits/job/1364589