One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8.0 KiB
Static byte store and framing contract
Build with make; the only required tools are GNU make and a C11 compiler. The library is compiled from store.c, wire.c, stream.c, and batch.c. The headers in this directory define the public ABI. Applications may link these objects directly. make check builds and runs the public smoke observer; it is a short reproducible example, not the full acceptance matrix.
Store
There are exactly four independent slots, numbered 0 through 3. Each slot has a static-storage-duration effective payload span of 128 bytes. store_span(slot) returns the same non-null, writable address for each valid slot throughout the process. Every returned effective span address has ((uintptr_t)span % 32) == 0; the four spans do not overlap. Invalid slots return null. This condition concerns userspace virtual addresses only. No DMA, physical contiguity, cache coherency, cache-line size, or ARM execution is promised. store_reset clears the logical lengths to zero; unused tail bytes have no specified value. store_length returns zero for invalid slots.
All data inputs are byte sequences. For functions with data and length, null data is allowed only when length==0. Lengths are in bytes. A successful function returns 0, except query functions defined below. A failed operation leaves all logical lengths and valid payload bytes unchanged. Return values: bad slot -1, capacity exceeded -2, invalid range or null input -3. A valid slot never contains more than 128 live bytes; caller can read/write only the first store_length(slot) bytes as live payload. The unused tail is unspecified. Inputs may alias a live span, so copying must preserve the source bytes for the duration of the operation.
store_write replaces a slot's live payload; store_append adds bytes; store_patch overwrites only an existing range; store_fill replaces the payload with repeated byte; store_copy copies source payload to destination. store_erase removes a live range and closes the gap. store_reverse reverses live bytes. store_rotate rotates live bytes left by distance modulo live length; empty is unchanged. store_xor modifies each live byte with the key. Invalid offsets or offset+length beyond live length return -3 (evaluate without overflow). store_find returns first matching zero-based offset or -1 if absent; invalid slot also returns -1. store_compare is lexicographic over unsigned bytes, returning -1, 0, or 1; invalid slot returns -1. store_checksum starts at zero and for each live byte rotates the 16-bit sum left five bits then adds the byte modulo 65536; invalid slot returns zero.
Wire
wire_pack emits one frame: magic a7, one-byte slot, one-byte payload length, live payload, and a two-byte big-endian CRC-16/CCITT-FALSE over the preceding bytes (initial value ffff, polynomial 1021, no reflection or final XOR). Total frame length is payload length plus five. wire_crc exposes this algorithm; null with positive length returns zero. wire_peek validates only shape, returning parsed slot and length. wire_unpack validates shape and CRC, then replaces the addressed slot's live payload atomically. wire_payload_copy validates frame and CRC, then copies just payload to caller output; it does not change a slot. Failures must not change live slots or output bytes. Output written is set to zero before a capacity failure. Wire errors are -10 argument, -11 short (<5 bytes), -12 malformed magic/slot/length, -13 CRC, -14 output capacity. Empty payload is valid. The API does not promise a particular value in output scalars after other errors.
Streaming decoder
stream_init clears a caller-owned decoder. stream_feed accepts arbitrary chunks of concatenated wire frames and noise. It discards bytes until magic, waits for a complete possible frame, and validates via wire_unpack. Valid frames replace their slots and increment accepted. Invalid slot or length immediately rejects and discards the leading magic; a completed frame with bad CRC also rejects and discards one leading byte before resynchronizing. Every discarded byte increments discarded; each invalid frame candidate increments rejected. last_slot starts at -1 and records the last accepted frame. stream_flush discards any pending incomplete bytes. stream_pending, stream_accepted, stream_rejected, stream_discarded, and stream_last_slot expose these values. A null decoder or null positive-length input gives STREAM_OVERFLOW=-20; the 512-byte buffer overflow is also -20. A valid call returns zero.
Batch
batch_apply processes at most 32 operations in order. Kinds are the BATCH_* constants in batch.h, with fields there: slot is the primary target, peer is the other slot for copy/swap, offset is range offset or rotate distance, length is byte count, value is fill/xor byte, and data supplies write/append/patch bytes. On the first failure it restores all four slots' live lengths and payloads to their entry state, returns that operation's status, and writes its zero-based index to failed_at. On success, failed_at=count. Invalid count/null operations/null failed_at return -3. batch_fingerprint is FNV-1a with 32-bit wrap: start 2166136261, then for each slot in order process one slot-index byte, one live-length byte, and all live bytes, each XOR then multiply 16777619. batch_export writes one length byte then live payload, with capacity checking. batch_import validates that exact format and replaces a slot. batch_slice copies an existing live range to output with capacity checking. Batch/export/import/slice failures leave live slots unchanged.
Observer protocol
make check runs ./observe on a small fixed command file. The same observer source is used with fresh randomized command streams in acceptance. One command per ASCII line, operands separated by single spaces; byte strings are lowercase even-length hex or - for empty. Commands: R; W/A <slot> <hex>; P <slot> <offset> <hex>; F <slot> <byte> <length>; C <dst> <src>; E <slot> <offset> <length>; V <slot>; O <slot> <distance>; X <slot> <byte>; Q <slot> <byte>; M <left> <right>; K <slot>; Z <slot> <capacity> for pack; U <hex> for unpack; T <hex> for stream feed; L for stream flush. Decimal operands use ordinary nonnegative ASCII digits, except slot operands can be -1. Each output line gives the raw return value, any result bytes, all four live spans' address remainders modulo 32, live lengths, and live payload hex. No expected values or assertions run in the observer. Diagnostic stderr is allowed, including non-UTF8 bytes; only stdout protocol is graded.
Additional observer commands: B <kind> <slot> <peer> <offset> <length> <value> <hex> applies one batch operation; J followed by two such seven-field groups applies two operations. H prints the fingerprint as its signed 32-bit representation in the return-value field. D <slot> <capacity> exports; I <slot> <hex> imports; S <slot> <offset> <length> <capacity> slices. Data fields for batch operations contain at most 128 bytes; their explicit length may exceed capacity to test rejection. Kind numbers are write=1, append=2, patch=3, erase=4, copy=5, reverse=6, rotate=7, xor=8, fill=9, swap=10. Unrecognized kinds return -3.
Every output line contains eight space-separated fields: signed return value, auxiliary integer, output hex (or -), four address_remainder:live_length:payload_hex fields, and accepted:rejected:discarded:pending:last_slot. Auxiliary is the decoded slot for successful U, the failed operation index or operation count for B/J, and zero otherwise. Auxiliary is unspecified after a failed U. Output hex is present only for successful pack/export/slice. Numeric output tokens may use a leading sign and any number of leading zeroes; horizontal spaces, tabs, and carriage returns between fields are equivalent. Each record ends with a newline. Hex output uses lowercase. The observer prints raw observations, without hidden assertions.