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>
6 lines
12 KiB
JSON
6 lines
12 KiB
JSON
{
|
|
"tx.h": "#ifndef TX_H\n#define TX_H\n#include <stddef.h>\n#include <stdint.h>\n#define TX_SLOTS 4\n#define TX_CAPACITY 256\n#define TX_OK 0\n#define TX_INVALID -1\n#define TX_ABSENT -2\n#define TX_BUSY -3\n#define TX_INCOMPLETE -4\n#define TX_DRAFT 1\n#define TX_PENDING 2\nstruct port_descriptor {\n int active;\n int id;\n int slot;\n size_t length;\n};\nstruct memory_port {\n size_t line;\n uint8_t cpu[TX_SLOTS][TX_CAPACITY];\n uint8_t memory[TX_SLOTS][TX_CAPACITY];\n struct port_descriptor queue[TX_SLOTS];\n};\nstruct tx_slot {\n int state;\n int id;\n size_t length;\n uint8_t covered[TX_CAPACITY];\n uint64_t order;\n};\nstruct tx_stats {\n uint64_t begins;\n uint64_t writes;\n uint64_t submits;\n uint64_t completed;\n uint64_t failures;\n uint64_t cancelled;\n uint64_t bytes;\n unsigned drafts;\n unsigned pending;\n};\nstruct tx_frame {\n int state;\n int slot;\n size_t length;\n size_t covered;\n};\nstruct tx_completion {\n int id;\n size_t length;\n uint8_t data[TX_CAPACITY];\n};\nstruct tx_engine {\n struct memory_port port;\n struct tx_slot slots[TX_SLOTS];\n struct tx_stats totals;\n uint64_t next_order;\n};\nint port_init(struct memory_port *p, int line);\nint port_write(struct memory_port *p, int slot, size_t offset,\n const uint8_t *data, size_t length);\nint port_fill(struct memory_port *p, int slot, size_t offset,\n size_t length, uint8_t value);\nint port_clean(struct memory_port *p, int slot, size_t offset, size_t length);\nint port_queue(struct memory_port *p, int slot, int id, size_t length);\nint port_complete(struct memory_port *p, int id, int status,\n struct tx_completion *out);\nint tx_init(struct tx_engine *e, int line);\nint tx_begin(struct tx_engine *e, int id, int length);\nint tx_write(struct tx_engine *e, int id, int offset,\n const uint8_t *data, int length);\nint tx_fill(struct tx_engine *e, int id, int offset, int length, int value);\nint tx_send(struct tx_engine *e, int id);\nint tx_complete(struct tx_engine *e, int id, int status,\n struct tx_completion *out);\nint tx_cancel(struct tx_engine *e, int id);\nint tx_inspect(const struct tx_engine *e, int id, struct tx_frame *out);\nvoid tx_statistics(const struct tx_engine *e, struct tx_stats *out);\n#endif\n",
|
|
"port.c": "#include \"tx.h\"\n#include <string.h>\nstatic int slot_valid(int slot)\n{\n return slot >= 0 && slot < TX_SLOTS;\n}\nstatic int range_valid(size_t offset, size_t length)\n{\n if (length == 0 || length > TX_CAPACITY)\n return 0;\n if (offset >= TX_CAPACITY)\n return 0;\n return length <= TX_CAPACITY - offset;\n}\nstatic struct port_descriptor *descriptor_for(struct memory_port *p, int id)\n{\n for (int i = 0; i < TX_SLOTS; ++i) {\n if (p->queue[i].active && p->queue[i].id == id)\n return &p->queue[i];\n }\n return NULL;\n}\nstatic struct port_descriptor *empty_descriptor(struct memory_port *p)\n{\n for (int i = 0; i < TX_SLOTS; ++i) {\n if (!p->queue[i].active)\n return &p->queue[i];\n }\n return NULL;\n}\nint port_init(struct memory_port *p, int line)\n{\n if (line != 16 && line != 32 && line != 64)\n return TX_INVALID;\n memset(p, 0, sizeof(*p));\n p->line = (size_t)line;\n for (int s = 0; s < TX_SLOTS; ++s) {\n for (size_t i = 0; i < TX_CAPACITY; ++i) {\n p->cpu[s][i] = 0x5a;\n p->memory[s][i] = 0x5a;\n }\n }\n return TX_OK;\n}\nint port_write(struct memory_port *p, int slot, size_t offset,\n const uint8_t *data, size_t length)\n{\n if (!slot_valid(slot) || !range_valid(offset, length) || !data)\n return TX_INVALID;\n memcpy(&p->cpu[slot][offset], data, length);\n return TX_OK;\n}\nint port_fill(struct memory_port *p, int slot, size_t offset,\n size_t length, uint8_t value)\n{\n if (!slot_valid(slot) || !range_valid(offset, length))\n return TX_INVALID;\n memset(&p->cpu[slot][offset], value, length);\n return TX_OK;\n}\nint port_clean(struct memory_port *p, int slot, size_t offset, size_t length)\n{\n if (!slot_valid(slot) || !range_valid(offset, length))\n return TX_INVALID;\n size_t first = offset - offset % p->line;\n size_t limit = offset + length;\n if (limit % p->line)\n limit += p->line - limit % p->line;\n if (limit > TX_CAPACITY)\n limit = TX_CAPACITY;\n memcpy(&p->memory[slot][first], &p->cpu[slot][first], limit - first);\n return TX_OK;\n}\nint port_queue(struct memory_port *p, int slot, int id, size_t length)\n{\n if (!slot_valid(slot) || id < 1 || id > 65535 ||\n length < 1 || length > TX_CAPACITY)\n return TX_INVALID;\n if (descriptor_for(p, id))\n return TX_BUSY;\n for (int i = 0; i < TX_SLOTS; ++i) {\n if (p->queue[i].active && p->queue[i].slot == slot)\n return TX_BUSY;\n }\n struct port_descriptor *d = empty_descriptor(p);\n if (!d)\n return TX_BUSY;\n d->id = id;\n d->slot = slot;\n d->length = length;\n d->active = 1;\n return TX_OK;\n}\nint port_complete(struct memory_port *p, int id, int status,\n struct tx_completion *out)\n{\n out->id = 0;\n out->length = 0;\n if (id < 1 || id > 65535 || (status != 0 && status != 1))\n return TX_INVALID;\n struct port_descriptor *d = descriptor_for(p, id);\n if (!d)\n return TX_ABSENT;\n out->id = id;\n if (status == 0) {\n out->length = d->length;\n memcpy(out->data, p->memory[d->slot], d->length);\n }\n d->active = 0;\n return TX_OK;\n}\n",
|
|
"main.c": "#include \"tx.h\"\n#include <ctype.h>\n#include <errno.h>\n#include <inttypes.h>\n#include <limits.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\nstruct command {\n char op;\n int count;\n char *args[5];\n};\nstatic int decimal(const char *text, int *out)\n{\n if (!text || !*text)\n return 0;\n const char *digits = text;\n if (*digits == '+' || *digits == '-')\n ++digits;\n if (!*digits)\n return 0;\n for (const char *p = digits; *p; ++p) {\n if (*p < '0' || *p > '9')\n return 0;\n }\n errno = 0;\n char *end;\n long value = strtol(text, &end, 10);\n if (errno || *end || value < INT_MIN || value > INT_MAX)\n return 0;\n *out = (int)value;\n return 1;\n}\nstatic int hex_digit(char c)\n{\n if (c >= '0' && c <= '9')\n return c - '0';\n if (c >= 'a' && c <= 'f')\n return c - 'a' + 10;\n if (c >= 'A' && c <= 'F')\n return c - 'A' + 10;\n return -1;\n}\nstatic int payload(const char *text, uint8_t *data, int *length)\n{\n size_t n = strlen(text);\n if (!n || n % 2 || n > TX_CAPACITY * 2)\n return 0;\n for (size_t i = 0; i < n; i += 2) {\n int high = hex_digit(text[i]);\n int low = hex_digit(text[i + 1]);\n if (high < 0 || low < 0)\n return 0;\n data[i / 2] = (uint8_t)(high * 16 + low);\n }\n *length = (int)(n / 2);\n return 1;\n}\nstatic int tokenize(char *line, struct command *c)\n{\n char *p = line;\n while (isspace((unsigned char)*p))\n ++p;\n if (!*p || *p == '#')\n return 0;\n c->op = *p++;\n c->count = 0;\n if (*p && !isspace((unsigned char)*p))\n return -1;\n while (*p) {\n while (isspace((unsigned char)*p))\n ++p;\n if (!*p)\n break;\n if (c->count == 5)\n return -1;\n c->args[c->count++] = p;\n while (*p && !isspace((unsigned char)*p))\n ++p;\n if (*p)\n *p++ = '\\0';\n }\n return 1;\n}\nstatic void print_data(const uint8_t *data, size_t length)\n{\n if (!length) {\n putchar('-');\n return;\n }\n for (size_t i = 0; i < length; ++i)\n printf(\"%02x\", (unsigned)data[i]);\n}\nstatic void print_stats(const struct tx_engine *e)\n{\n struct tx_stats s;\n tx_statistics(e, &s);\n printf(\"STATS %\" PRIu64 \" %\" PRIu64 \" %\" PRIu64 \" %\" PRIu64\n \" %\" PRIu64 \" %\" PRIu64 \" %\" PRIu64 \" %u %u\\n\",\n s.begins, s.writes, s.submits, s.completed, s.failures,\n s.cancelled, s.bytes, s.drafts, s.pending);\n}\nstatic void print_frame(const struct tx_engine *e, int id)\n{\n struct tx_frame f;\n int rc = tx_inspect(e, id, &f);\n printf(\"FRAME %d %d %d %zu %zu\\n\", rc, f.state, f.slot, f.length, f.covered);\n}\nstatic void print_device(const struct tx_engine *e, int id)\n{\n const struct port_descriptor *found = NULL;\n int rc = TX_ABSENT;\n if (id < 1 || id > 65535)\n rc = TX_INVALID;\n else {\n for (int i = 0; i < TX_SLOTS; ++i) {\n if (e->port.queue[i].active && e->port.queue[i].id == id)\n found = &e->port.queue[i];\n }\n }\n if (!found) {\n printf(\"DEVICE %d 0 0 -\\n\", rc);\n return;\n }\n printf(\"DEVICE 0 %d %zu \", id, found->length);\n print_data(e->port.memory[found->slot], found->length);\n putchar('\\n');\n}\nstatic int numeric_args(const struct command *c, int count, int *values)\n{\n if (c->count != count)\n return 0;\n for (int i = 0; i < count; ++i) {\n if (!decimal(c->args[i], &values[i]))\n return 0;\n }\n return 1;\n}\nstatic int execute(struct tx_engine *e, const struct command *c)\n{\n int a[4];\n int rc;\n uint8_t bytes[TX_CAPACITY];\n int length;\n switch (c->op) {\n case 'R':\n if (!numeric_args(c, 1, a))\n return 0;\n rc = tx_init(e, a[0]);\n break;\n case 'B':\n if (!numeric_args(c, 2, a))\n return 0;\n rc = tx_begin(e, a[0], a[1]);\n break;\n case 'W':\n if (c->count != 3 || !decimal(c->args[0], &a[0]) ||\n !decimal(c->args[1], &a[1]) || !payload(c->args[2], bytes, &length))\n return 0;\n rc = tx_write(e, a[0], a[1], bytes, length);\n break;\n case 'F':\n if (!numeric_args(c, 4, a))\n return 0;\n rc = tx_fill(e, a[0], a[1], a[2], a[3]);\n break;\n case 'S':\n case 'X':\n case 'P':\n case 'D':\n if (!numeric_args(c, 1, a))\n return 0;\n if (c->op == 'P') {\n print_frame(e, a[0]);\n return 1;\n }\n if (c->op == 'D') {\n print_device(e, a[0]);\n return 1;\n }\n rc = c->op == 'S' ? tx_send(e, a[0]) : tx_cancel(e, a[0]);\n break;\n case 'C': {\n if (!numeric_args(c, 2, a))\n return 0;\n struct tx_completion completion;\n rc = tx_complete(e, a[0], a[1], &completion);\n printf(\"COMPLETE %d %d %zu \", rc, completion.id, completion.length);\n print_data(completion.data, completion.length);\n putchar('\\n');\n return 1;\n }\n case 'Q':\n if (c->count)\n return 0;\n print_stats(e);\n return 1;\n default:\n return 0;\n }\n printf(\"RESULT %c %d\\n\", c->op, rc);\n return 1;\n}\nint main(void)\n{\n struct tx_engine engine;\n if (tx_init(&engine, 32) != TX_OK)\n return 2;\n char line[2048];\n while (fgets(line, sizeof(line), stdin)) {\n struct command c;\n int parsed = tokenize(line, &c);\n if (parsed < 0 || (parsed > 0 && !execute(&engine, &c)))\n puts(\"ERROR\");\n }\n if (ferror(stdin) || ferror(stdout))\n return 2;\n return 0;\n}\n"
|
|
}
|