From f04fdc8e57e805466d4260b4dfdc1e0b185cf422 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 23 Jul 2019 23:51:06 -0700 Subject: 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. --- subx/069allocate.subx | 24 ++++++++++++++++++------ subx/apps/assort | Bin 34330 -> 34384 bytes subx/apps/crenshaw2-1 | Bin 24734 -> 24788 bytes subx/apps/crenshaw2-1b | Bin 25293 -> 25347 bytes subx/apps/dquotes | Bin 40886 -> 40940 bytes subx/apps/factorial | Bin 23650 -> 23704 bytes subx/apps/handle | Bin 24509 -> 24558 bytes subx/apps/handle.subx | 2 +- subx/apps/hex | Bin 27743 -> 27797 bytes subx/apps/pack | Bin 47016 -> 47070 bytes subx/apps/subx-common.subx | 6 +++--- subx/apps/survey | Bin 43551 -> 43605 bytes subx/apps/survey.subx | 4 ++-- subx/apps/tests | Bin 33142 -> 33196 bytes 14 files changed, 24 insertions(+), 12 deletions(-) (limited to 'subx') 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 diff --git a/subx/apps/assort b/subx/apps/assort index 6b31712a..c0fc6873 100755 Binary files a/subx/apps/assort and b/subx/apps/assort differ diff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1 index 93183803..47ee601e 100755 Binary files a/subx/apps/crenshaw2-1 and b/subx/apps/crenshaw2-1 differ diff --git a/subx/apps/crenshaw2-1b b/subx/apps/crenshaw2-1b index c0eae5f9..fba81a7d 100755 Binary files a/subx/apps/crenshaw2-1b and b/subx/apps/crenshaw2-1b differ diff --git a/subx/apps/dquotes b/subx/apps/dquotes index bbaa4119..6b88fbde 100755 Binary files a/subx/apps/dquotes and b/subx/apps/dquotes differ diff --git a/subx/apps/factorial b/subx/apps/factorial index c015a3c9..b82be120 100755 Binary files a/subx/apps/factorial and b/subx/apps/factorial differ diff --git a/subx/apps/handle b/subx/apps/handle index f098c715..b6794474 100755 Binary files a/subx/apps/handle and b/subx/apps/handle differ diff --git a/subx/apps/handle.subx b/subx/apps/handle.subx index 97a6c622..ba824f85 100644 --- a/subx/apps/handle.subx +++ b/subx/apps/handle.subx @@ -143,7 +143,7 @@ test-new: 5d/pop-to-EBP c3/return -test-new-failure: +_pending-test-new-failure: # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP diff --git a/subx/apps/hex b/subx/apps/hex index ff5d30b5..c5d1f415 100755 Binary files a/subx/apps/hex and b/subx/apps/hex differ diff --git a/subx/apps/pack b/subx/apps/pack index efd22fef..fd29e9aa 100755 Binary files a/subx/apps/pack and b/subx/apps/pack differ diff --git a/subx/apps/subx-common.subx b/subx/apps/subx-common.subx index 27f488c9..baf247f2 100644 --- a/subx/apps/subx-common.subx +++ b/subx/apps/subx-common.subx @@ -5,11 +5,11 @@ # maximum memory available for allocation Heap-size: - 0x100000/imm32/1MB + 0x200000/imm32/2MB # maximum size of a single segment Segment-size: - 0x40000/imm32/256KB + 0x80000/imm32/512KB # maximum size of input textual stream (spanning all segments) Input-size: @@ -17,7 +17,7 @@ Input-size: # maximum size of the 'labels' table in survey.subx Max-labels: - 0x4000/imm32/1K-labels/16KB + 0x10000/imm32/4K-labels/64KB == code # instruction effective address register displacement immediate diff --git a/subx/apps/survey b/subx/apps/survey index 80dea805..348e20f0 100755 Binary files a/subx/apps/survey and b/subx/apps/survey differ diff --git a/subx/apps/survey.subx b/subx/apps/survey.subx index bd7596da..15957fa2 100644 --- a/subx/apps/survey.subx +++ b/subx/apps/survey.subx @@ -117,7 +117,7 @@ convert: # infile : (address buffered-file), out : (address buffered-file) -> < # var in : (address stream byte) = stream(4096) # slurp(infile, in) # var segments = new-stream(10 rows, 16 bytes each) - # var labels = new-stream(512 rows, 16 bytes each) + # var labels = new-stream(Max-labels rows, 16 bytes each) # compute-offsets(in, segments, labels) # compute-addresses(segments, labels) # rewind-stream(in) @@ -136,7 +136,7 @@ convert: # infile : (address buffered-file), out : (address buffered-file) -> < 68/push 0/imm32/read 68/push 0/imm32/write 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . . # copy ESP to ECX - # var labels/EDX = stream(1024 * 16) + # var labels/EDX = stream(Max-labels * 16) # . data 2b/subtract 0/mod/indirect 5/rm32/.disp32 . . 4/r32/ESP Max-labels/disp32 # subtract *Max-labels from ESP # . length diff --git a/subx/apps/tests b/subx/apps/tests index c4a9aaa5..08e586e3 100755 Binary files a/subx/apps/tests and b/subx/apps/tests differ -- cgit 1.4.1-2-gfad0