diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-05-11 22:44:49 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-05-11 22:44:49 -0700 |
commit | e59a74abddaf0b4f9a39432da21c6a98eae46df6 (patch) | |
tree | b21109b5889dcdb9011e5a8559e7fb8e0ba00c4c /subx/050_write.subx | |
parent | 6362c51d11ef27335875469e0ff06347357f46b1 (diff) | |
download | mu-e59a74abddaf0b4f9a39432da21c6a98eae46df6.tar.gz |
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?
Diffstat (limited to 'subx/050_write.subx')
-rw-r--r-- | subx/050_write.subx | 11 |
1 files changed, 11 insertions, 0 deletions
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) -> <void> # . 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 |