diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-07-23 23:51:06 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-07-24 00:18:21 -0700 |
commit | f04fdc8e57e805466d4260b4dfdc1e0b185cf422 (patch) | |
tree | 46a7e8f726af5653ef745dbf1da1b3f4c2944fb8 /subx/069allocate.subx | |
parent | 43e6c3787d79bb965b98641a4e44be771dee4cc2 (diff) | |
download | mu-f04fdc8e57e805466d4260b4dfdc1e0b185cf422.tar.gz |
5460
A little more resizing of buffers. apps/hex.subx is now building an identical binary. I'm now aborting on allocation failures. That requires disabling a couple of tests. (I'm not quite confident enough of this decision to delete them outright.) I want to treat all segfaults as bugs, and machine code is no place to add boilerplate checks for return values of standard library functions.
Diffstat (limited to 'subx/069allocate.subx')
-rw-r--r-- | subx/069allocate.subx | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/subx/069allocate.subx b/subx/069allocate.subx index e262b4d5..6521b43a 100644 --- a/subx/069allocate.subx +++ b/subx/069allocate.subx @@ -22,7 +22,7 @@ # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes # Claim the next 'n' bytes of memory starting at ad->curr and update ad->curr. -# If there isn't enough memory before ad->limit, return 0 and leave 'ad' unmodified. +# Abort if there isn't enough memory in 'ad'. allocate: # ad : (address allocation-descriptor), n : int -> address-or-null/EAX # . prolog 55/push-EBP @@ -39,10 +39,7 @@ allocate: # ad : (address allocation-descriptor), n : int -> address-or-null/EA 89/copy 3/mod/direct 2/rm32/EDX . . . 0/r32/EAX . . # copy EAX to EDX 03/add 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0xc/disp8 . # add *(EBP+12) to EDX 3b/compare 1/mod/*+disp8 1/rm32/ECX . . . 2/r32/EDX 4/disp8 . # compare EDX with *(ECX+4) - 72/jump-if-lesser-signed $allocate:commit/disp8 - # return null if not - b8/copy-to-EAX 0/imm32 - eb/jump $allocate:end/disp8 + 73/jump-if-greater-or-equal-signed $allocate:abort/disp8 $allocate:commit: # update ad->curr 89/copy 0/mod/indirect 1/rm32/ECX . . . 2/r32/EDX . . # copy EDX to *ECX @@ -55,6 +52,21 @@ $allocate:end: 5d/pop-to-EBP c3/return +$allocate:abort: + # . _write(2/stderr, error) + # . . push args + 68/push "allocate: failed to allocate\n"/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call _write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . syscall(exit, 1) + bb/copy-to-EBX 1/imm32 + b8/copy-to-EAX 1/imm32/exit + cd/syscall 0x80/imm8 + # never gets here + test-allocate-success: # . prolog 55/push-EBP @@ -94,7 +106,7 @@ test-allocate-success: 5d/pop-to-EBP c3/return -test-allocate-failure: +_pending-test-allocate-failure: # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP |