From e59a74abddaf0b4f9a39432da21c6a98eae46df6 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 11 May 2019 22:44:49 -0700 Subject: 5156 - error-checking on writes to file Pretty blunt for now; just abort the entire program on any failure to write. I'm encountering it because I'm somehow treating a stream address as a file descriptor. Maybe mmap is returning addresses below 0x08000000? --- subx/050_write.subx | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'subx/050_write.subx') diff --git a/subx/050_write.subx b/subx/050_write.subx index 083adad6..0d6b8152 100644 --- a/subx/050_write.subx +++ b/subx/050_write.subx @@ -32,6 +32,9 @@ _write: # fd : int, s : (address array byte) -> # . syscall b8/copy-to-EAX 4/imm32/write cd/syscall 0x80/imm8 + # if (EAX < 0) abort + 3d/compare-EAX-with 0/imm32 + 0f 8c/jump-if-lesser $_write:abort/disp32 $_write:end: # . restore registers 5b/pop-to-EBX @@ -43,4 +46,12 @@ $_write:end: 5d/pop-to-EBP c3/return +$_write:abort: + # can't write a message here for risk of an infinite loop, so we'll use a special exit code instead + # . syscall(exit, 255) + bb/copy-to-EBX 0xff/imm32 + b8/copy-to-EAX 1/imm32/exit + cd/syscall 0x80/imm8 + # never gets here + # . . vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0