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>
12 lines
17 KiB
JSON
12 lines
17 KiB
JSON
{
|
|
"context": {
|
|
"wire.h": "#ifndef RX_WIRE_H\n#define RX_WIRE_H\n#include <stddef.h>\n#include <stdint.h>\n#define WIRE_PAYLOAD_MAX 96u\n#define WIRE_OVERHEAD 11u\n#define WIRE_MAX_SIZE (WIRE_PAYLOAD_MAX + WIRE_OVERHEAD)\nstruct wire_packet {\n uint32_t tag;\n unsigned flags;\n size_t size;\n uint8_t payload[WIRE_PAYLOAD_MAX];\n};\nuint16_t wire_crc16(const uint8_t *bytes, size_t length);\nint wire_decode(const uint8_t *bytes, size_t length, struct wire_packet *packet);\nint wire_encode(const struct wire_packet *packet, uint8_t *bytes,\n size_t capacity, size_t *written);\n#endif\n",
|
|
"rx_window.h": "#ifndef RX_WINDOW_H\n#define RX_WINDOW_H\n#include <stddef.h>\n#include <stdint.h>\n#include \"port.h\"\n#define RX_OK 0\n#define RX_PENDING 1\n#define RX_ARGUMENT (-1)\n#define RX_STATE (-2)\n#define RX_DEVICE (-3)\n#define RX_FORMAT (-4)\nstruct rx_receiver;\nstruct rx_result {\n uint32_t tag;\n unsigned flags;\n size_t size;\n uint8_t payload[96];\n};\nstruct rx_receiver *rx_create(struct rx_port *port);\nvoid rx_destroy(struct rx_receiver *receiver);\nsize_t rx_outstanding(const struct rx_receiver *receiver);\nint rx_submit(struct rx_receiver *receiver, unsigned slot, size_t offset,\n size_t capacity, uint32_t tag);\nint rx_collect(struct rx_receiver *receiver, unsigned slot, struct rx_result *out);\nint rx_cancel(struct rx_receiver *receiver, unsigned slot);\n#endif\n",
|
|
"wire.c": "#include \"wire.h\"\n#include <string.h>\n\nuint16_t wire_crc16(const uint8_t *bytes, size_t length)\n{\n uint16_t crc = 0xffffu;\n size_t index;\n unsigned bit;\n for (index = 0; index < length; ++index) {\n crc ^= (uint16_t)bytes[index] << 8;\n for (bit = 0; bit < 8; ++bit) {\n if (crc & 0x8000u)\n crc = (uint16_t)((crc << 1) ^ 0x1021u);\n else\n crc = (uint16_t)(crc << 1);\n }\n }\n return crc;\n}\n\nstatic uint32_t read_tag(const uint8_t *bytes)\n{\n return (uint32_t)bytes[4] | ((uint32_t)bytes[5] << 8) |\n ((uint32_t)bytes[6] << 16) | ((uint32_t)bytes[7] << 24);\n}\n\nstatic void write_tag(uint8_t *bytes, uint32_t tag)\n{\n unsigned index;\n for (index = 0; index < 4; ++index)\n bytes[4 + index] = (uint8_t)(tag >> (8 * index));\n}\n\nint wire_decode(const uint8_t *bytes, size_t length, struct wire_packet *packet)\n{\n size_t payload_size;\n uint16_t stored, computed;\n if (bytes == NULL || packet == NULL || length < WIRE_OVERHEAD ||\n length > WIRE_MAX_SIZE)\n return -1;\n if (bytes[0] != 0xc3u || bytes[1] != 0x5au || bytes[2] != 1u || bytes[3] > 3u)\n return -1;\n payload_size = bytes[8];\n if (payload_size > WIRE_PAYLOAD_MAX || length != WIRE_OVERHEAD + payload_size)\n return -1;\n computed = wire_crc16(bytes, length - 2);\n stored = (uint16_t)bytes[length - 2] | ((uint16_t)bytes[length - 1] << 8);\n if (stored != computed)\n return -1;\n packet->tag = read_tag(bytes);\n packet->flags = bytes[3];\n packet->size = payload_size;\n if (payload_size != 0)\n memcpy(packet->payload, bytes + 9, payload_size);\n return 0;\n}\n\nint wire_encode(const struct wire_packet *packet, uint8_t *bytes,\n size_t capacity, size_t *written)\n{\n size_t total;\n uint16_t crc;\n if (packet == NULL || bytes == NULL || written == NULL ||\n packet->size > WIRE_PAYLOAD_MAX || packet->flags > 3u)\n return -1;\n total = WIRE_OVERHEAD + packet->size;\n if (capacity < total)\n return -1;\n bytes[0] = 0xc3u;\n bytes[1] = 0x5au;\n bytes[2] = 1;\n bytes[3] = (uint8_t)packet->flags;\n write_tag(bytes, packet->tag);\n bytes[8] = (uint8_t)packet->size;\n if (packet->size != 0)\n memcpy(bytes + 9, packet->payload, packet->size);\n crc = wire_crc16(bytes, total - 2);\n bytes[total - 2] = (uint8_t)crc;\n bytes[total - 1] = (uint8_t)(crc >> 8);\n *written = total;\n return 0;\n}\n",
|
|
"port.h": "#ifndef RX_PORT_H\n#define RX_PORT_H\n#include <stddef.h>\n#include <stdint.h>\n#define PORT_SLOTS 4u\n#define PORT_BANK_SIZE 256u\n#define PORT_CAPACITY_MAX 128u\n#define PORT_LINE_SIZE 16u\n#define PORT_DONE 1\n#define PORT_FAILED 2\n#define PORT_CANCELLED 3\nstruct rx_port;\nstruct port_completion { int state; size_t actual; };\nstruct port_audit {\n unsigned acquired;\n unsigned returned;\n unsigned aborted;\n unsigned completed;\n unsigned live;\n unsigned violations;\n size_t cpu_distinct;\n};\nstruct rx_port *port_create(uint32_t seed);\nvoid port_destroy(struct rx_port *port);\nint port_acquire(struct rx_port *port, unsigned slot, size_t offset,\n size_t capacity, uint32_t tag, uint32_t *handle);\nint port_completion(struct rx_port *port, uint32_t handle,\n struct port_completion *completion);\nint port_invalidate(struct rx_port *port, uint32_t handle,\n size_t start, size_t length);\nint port_cpu_read(struct rx_port *port, uint32_t handle, size_t offset,\n uint8_t *out, size_t length);\nint port_abort(struct rx_port *port, uint32_t handle);\nint port_release(struct rx_port *port, uint32_t handle);\nint port_device_complete(struct rx_port *port, unsigned slot, int state,\n const uint8_t *bytes, size_t length);\nstruct port_audit port_audit(const struct rx_port *port);\n#endif\n",
|
|
"demo.c": "#include \"rx_window.h\"\n#include <errno.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nstatic int hex_digit(int character)\n{\n if (character >= '0' && character <= '9')\n return character - '0';\n if (character >= 'a' && character <= 'f')\n return character - 'a' + 10;\n if (character >= 'A' && character <= 'F')\n return character - 'A' + 10;\n return -1;\n}\n\nstatic int parse_bytes(const char *text, uint8_t *bytes, size_t *length)\n{\n size_t count, index;\n if (strcmp(text, \"-\") == 0) {\n *length = 0;\n return 0;\n }\n count = strlen(text);\n if (count % 2 != 0 || count / 2 > PORT_CAPACITY_MAX)\n return -1;\n for (index = 0; index < count / 2; ++index) {\n int high = hex_digit(text[index * 2]);\n int low = hex_digit(text[index * 2 + 1]);\n if (high < 0 || low < 0)\n return -1;\n bytes[index] = (uint8_t)(high * 16 + low);\n }\n *length = count / 2;\n return 0;\n}\n\nstatic void print_result(unsigned step, char command, int code,\n const struct rx_result *result)\n{\n size_t index, shown;\n if (command != 'C') {\n printf(\"O %u %c %d 0 0 0 -\\n\", step, command, code);\n return;\n }\n printf(\"O %u %c %d %u %u %zu \", step, command, code,\n result->tag, result->flags, result->size);\n shown = result->size;\n if (shown > sizeof(result->payload))\n shown = sizeof(result->payload);\n if (shown == 0)\n putchar('-');\n for (index = 0; index < shown; ++index)\n printf(\"%02x\", result->payload[index]);\n putchar('\\n');\n}\n\nstatic void print_audit(unsigned step, const struct rx_receiver *receiver,\n const struct rx_port *port)\n{\n struct port_audit audit = port_audit(port);\n printf(\"A %u %zu %u %u %u %u %u %u %zu\\n\", step,\n rx_outstanding(receiver), audit.acquired, audit.returned,\n audit.aborted, audit.completed, audit.live, audit.violations, audit.cpu_distinct);\n}\n\nint main(void)\n{\n char line[8192];\n struct rx_port *port = port_create(1);\n struct rx_receiver *receiver = rx_create(port);\n unsigned step = 0;\n if (port == NULL || receiver == NULL)\n return 2;\n while (fgets(line, sizeof(line), stdin) != NULL) {\n char command = 0;\n unsigned slot = 0, seed = 0, tag = 0;\n size_t offset = 0, capacity = 0;\n int code = RX_ARGUMENT;\n struct rx_result result;\n memset(&result, 0xa6, sizeof(result));\n if (sscanf(line, \" %c\", &command) != 1)\n continue;\n ++step;\n if (command == 'R' && sscanf(line, \" R %u\", &seed) == 1) {\n rx_destroy(receiver);\n port_destroy(port);\n port = port_create(seed);\n receiver = rx_create(port);\n if (port == NULL || receiver == NULL)\n return 2;\n code = RX_OK;\n } else if (command == 'S' &&\n sscanf(line, \" S %u %zu %zu %u\", &slot, &offset, &capacity, &tag) == 4) {\n code = rx_submit(receiver, slot, offset, capacity, tag);\n } else if (command == 'D') {\n char text[PORT_CAPACITY_MAX * 2 + 2];\n uint8_t bytes[PORT_CAPACITY_MAX];\n size_t length;\n int state;\n if (sscanf(line, \" D %u %d %257s\", &slot, &state, text) == 3 &&\n parse_bytes(text, bytes, &length) == 0)\n code = port_device_complete(port, slot, state, bytes, length);\n } else if (command == 'C' && sscanf(line, \" C %u\", &slot) == 1) {\n code = rx_collect(receiver, slot, &result);\n } else if (command == 'X' && sscanf(line, \" X %u\", &slot) == 1) {\n code = rx_cancel(receiver, slot);\n } else if (command == 'Z') {\n rx_destroy(receiver);\n receiver = rx_create(port);\n if (receiver == NULL)\n return 2;\n code = RX_OK;\n }\n print_result(step, command, code, &result);\n print_audit(step, receiver, port);\n }\n rx_destroy(receiver);\n port_destroy(port);\n return ferror(stdin) ? 2 : 0;\n}\n",
|
|
"port.c": "#include \"port.h\"\n#include <stdlib.h>\n#include <string.h>\n\nstruct bank {\n uint8_t memory[PORT_BANK_SIZE];\n uint8_t cache[PORT_BANK_SIZE];\n uint8_t valid[PORT_BANK_SIZE / PORT_LINE_SIZE];\n};\n\nstruct descriptor {\n uint32_t handle;\n uint32_t tag;\n size_t offset;\n size_t capacity;\n size_t actual;\n unsigned refreshed;\n uint8_t read_seen[PORT_CAPACITY_MAX];\n int state;\n};\n\nstruct rx_port {\n struct bank banks[PORT_SLOTS];\n struct descriptor requests[PORT_SLOTS];\n uint32_t next_handle;\n struct port_audit audit;\n};\n\nstatic int violation(struct rx_port *port, int code)\n{\n if (port != NULL)\n port->audit.violations++;\n return code;\n}\n\nstatic struct descriptor *lookup(struct rx_port *port, uint32_t handle,\n unsigned *slot)\n{\n unsigned index;\n if (port == NULL || handle == 0)\n return NULL;\n for (index = 0; index < PORT_SLOTS; ++index) {\n if (port->requests[index].handle == handle) {\n if (slot != NULL)\n *slot = index;\n return &port->requests[index];\n }\n }\n return NULL;\n}\n\nstruct rx_port *port_create(uint32_t seed)\n{\n struct rx_port *port = calloc(1, sizeof(*port));\n unsigned slot;\n size_t position;\n if (port == NULL)\n return NULL;\n port->next_handle = 1;\n for (slot = 0; slot < PORT_SLOTS; ++slot) {\n struct bank *bank = &port->banks[slot];\n for (position = 0; position < PORT_BANK_SIZE; ++position) {\n uint8_t value = (uint8_t)(seed * 17u + slot * 29u + position * 7u + 13u);\n bank->memory[position] = value;\n bank->cache[position] = value;\n }\n memset(bank->valid, 1, sizeof(bank->valid));\n }\n return port;\n}\n\nvoid port_destroy(struct rx_port *port)\n{\n free(port);\n}\n\nint port_acquire(struct rx_port *port, unsigned slot, size_t offset,\n size_t capacity, uint32_t tag, uint32_t *handle)\n{\n struct descriptor *request;\n if (port == NULL || handle == NULL || slot >= PORT_SLOTS ||\n capacity == 0 || capacity > PORT_CAPACITY_MAX ||\n offset >= PORT_BANK_SIZE || capacity > PORT_BANK_SIZE - offset)\n return violation(port, -1);\n request = &port->requests[slot];\n if (request->handle != 0)\n return violation(port, -2);\n memset(request, 0, sizeof(*request));\n request->handle = port->next_handle++;\n if (port->next_handle == 0)\n port->next_handle = 1;\n request->tag = tag;\n request->offset = offset;\n request->capacity = capacity;\n *handle = request->handle;\n port->audit.acquired++;\n port->audit.live++;\n return 0;\n}\n\nint port_completion(struct rx_port *port, uint32_t handle,\n struct port_completion *completion)\n{\n struct descriptor *request = lookup(port, handle, NULL);\n if (completion == NULL)\n return violation(port, -1);\n if (request == NULL)\n return violation(port, -2);\n if (request->state == 0)\n return 1;\n completion->state = request->state;\n completion->actual = request->actual;\n return 0;\n}\n\nint port_invalidate(struct rx_port *port, uint32_t handle,\n size_t start, size_t length)\n{\n unsigned slot;\n size_t first, end, line;\n struct descriptor *request = lookup(port, handle, &slot);\n if (request == NULL || request->state != PORT_DONE)\n return violation(port, -2);\n if (request->actual == 0 || start % PORT_LINE_SIZE != 0 ||\n length == 0 || length % PORT_LINE_SIZE != 0 ||\n start >= PORT_BANK_SIZE || length > PORT_BANK_SIZE - start)\n return violation(port, -1);\n first = request->offset / PORT_LINE_SIZE * PORT_LINE_SIZE;\n end = (request->offset + request->actual + PORT_LINE_SIZE - 1) /\n PORT_LINE_SIZE * PORT_LINE_SIZE;\n if (start < first || start + length > end)\n return violation(port, -1);\n for (line = start / PORT_LINE_SIZE;\n line < (start + length) / PORT_LINE_SIZE; ++line) {\n port->banks[slot].valid[line] = 0;\n request->refreshed |= 1u << line;\n }\n return 0;\n}\n\nstatic void refill_line(struct bank *bank, size_t line)\n{\n size_t first = line * PORT_LINE_SIZE;\n memcpy(bank->cache + first, bank->memory + first, PORT_LINE_SIZE);\n bank->valid[line] = 1;\n}\n\nint port_cpu_read(struct rx_port *port, uint32_t handle, size_t offset,\n uint8_t *out, size_t length)\n{\n unsigned slot;\n size_t position;\n struct descriptor *request = lookup(port, handle, &slot);\n struct bank *bank;\n if (request == NULL || request->state != PORT_DONE)\n return violation(port, -2);\n if (out == NULL || length == 0 || offset < request->offset ||\n offset - request->offset > request->actual ||\n length > request->actual - (offset - request->offset))\n return violation(port, -1);\n bank = &port->banks[slot];\n for (position = offset; position < offset + length; ++position) {\n size_t line = position / PORT_LINE_SIZE;\n if ((request->refreshed & (1u << line)) == 0)\n port->audit.violations++;\n if (!bank->valid[line])\n refill_line(bank, line);\n if (!request->read_seen[position - request->offset]) {\n request->read_seen[position - request->offset] = 1;\n port->audit.cpu_distinct++;\n }\n out[position - offset] = bank->cache[position];\n }\n return 0;\n}\n\nint port_abort(struct rx_port *port, uint32_t handle)\n{\n struct descriptor *request = lookup(port, handle, NULL);\n if (request == NULL)\n return violation(port, -2);\n if (request->state == 0) {\n request->state = PORT_CANCELLED;\n request->actual = 0;\n port->audit.aborted++;\n }\n return 0;\n}\n\nint port_release(struct rx_port *port, uint32_t handle)\n{\n struct descriptor *request = lookup(port, handle, NULL);\n if (request == NULL || request->state == 0)\n return violation(port, -2);\n memset(request, 0, sizeof(*request));\n port->audit.returned++;\n port->audit.live--;\n return 0;\n}\n\nint port_device_complete(struct rx_port *port, unsigned slot, int state,\n const uint8_t *bytes, size_t length)\n{\n struct descriptor *request;\n if (port == NULL || slot >= PORT_SLOTS ||\n (state != PORT_DONE && state != PORT_FAILED))\n return -1;\n request = &port->requests[slot];\n if (request->handle == 0 || request->state != 0)\n return -2;\n if (length > request->capacity || (length != 0 && bytes == NULL) ||\n (state == PORT_FAILED && length != 0))\n return -1;\n if (length != 0)\n memcpy(port->banks[slot].memory + request->offset, bytes, length);\n request->actual = length;\n request->state = state;\n request->refreshed = 0;\n port->audit.completed++;\n return 0;\n}\n\nstruct port_audit port_audit(const struct rx_port *port)\n{\n struct port_audit result = {0, 0, 0, 0, 0, 0, 0};\n if (port != NULL)\n result = port->audit;\n return result;\n}\n"
|
|
},
|
|
"seed": 150023
|
|
}
|