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>
14 lines
16 KiB
JSON
14 lines
16 KiB
JSON
{
|
||
"Makefile": "CC = gcc\nCFLAGS = -std=c11 -O2 -Wall -Wextra -Wpedantic\nSOURCES = arena.c wire.c device.c descriptor_table.c batch.c console.c observe.c\nall: descriptor-observe\ndescriptor-observe: $(SOURCES) descriptor.h\n\t$(CC) $(CFLAGS) $(SOURCES) -o $@\nclean:\n\trm -f descriptor-observe\n.PHONY: all clean\n",
|
||
"README.md": "# Descriptor batch bench\n\n构建 `make`,运行 `./descriptor-observe < examples/demo.txt`。标准C11、gcc、make,不下载依赖。\n这是无硬件的软件诊断工具:arena提供真实对齐内存,device逐字节读取设备槽位;没有DMA、总线、设备寄存器或未对齐的类型解引用。\n公开行为见 docs/descriptor-contract.md,控制台格式见 docs/console.md。\n",
|
||
"arena.c": "#define _POSIX_C_SOURCE 200112L\n#include \"descriptor.h\"\n#include <stdlib.h>\n#include <string.h>\nstruct allocation {\n void *pointer;\n size_t bytes;\n};\nstatic struct allocation allocations[DEVICE_SLOTS * 2];\nstatic struct memory_stats totals;\nstatic size_t free_slot(void) {\n size_t index;\n for (index = 0; index < DEVICE_SLOTS * 2; ++index) {\n if (allocations[index].pointer == NULL) {\n return index;\n }\n }\n return DEVICE_SLOTS * 2;\n}\nvoid *arena_allocate(size_t alignment, size_t bytes) {\n void *pointer = NULL;\n size_t slot;\n if (alignment < sizeof(void *) || (alignment & (alignment - 1)) != 0) {\n return NULL;\n }\n if (bytes == 0) {\n return NULL;\n }\n slot = free_slot();\n if (slot == DEVICE_SLOTS * 2) {\n return NULL;\n }\n if (posix_memalign(&pointer, alignment, bytes) != 0) {\n return NULL;\n }\n memset(pointer, 0xa5, bytes);\n allocations[slot].pointer = pointer;\n allocations[slot].bytes = bytes;\n totals.blocks += 1;\n totals.bytes += bytes;\n totals.creates += 1;\n return pointer;\n}\nvoid arena_release(void *pointer) {\n size_t index;\n if (pointer == NULL) {\n return;\n }\n for (index = 0; index < DEVICE_SLOTS * 2; ++index) {\n if (allocations[index].pointer == pointer) {\n totals.blocks -= 1;\n totals.bytes -= allocations[index].bytes;\n totals.releases += 1;\n free(pointer);\n allocations[index].pointer = NULL;\n allocations[index].bytes = 0;\n return;\n }\n }\n}\nstruct memory_stats arena_snapshot(void) {\n return totals;\n}\nint arena_is_empty(void) {\n size_t index;\n if (totals.blocks != 0 || totals.bytes != 0) {\n return 0;\n }\n for (index = 0; index < DEVICE_SLOTS * 2; ++index) {\n if (allocations[index].pointer != NULL) {\n return 0;\n }\n }\n return 1;\n}\n",
|
||
"console.c": "#include \"descriptor.h\"\n#include <ctype.h>\n#include <errno.h>\n#include <stdlib.h>\n#include <string.h>\nstatic int number(const char **cursor, uint64_t *value) {\n char *end;\n unsigned long long parsed;\n const char *text = *cursor;\n while (isspace((unsigned char)*text)) {\n ++text;\n }\n if (!isdigit((unsigned char)*text)) {\n return 0;\n }\n errno = 0;\n parsed = strtoull(text, &end, 10);\n if (end == text || errno == ERANGE || (*end && !isspace((unsigned char)*end))) {\n return 0;\n }\n *value = (uint64_t)parsed;\n *cursor = end;\n return 1;\n}\nstatic unsigned arguments_for(char operation) {\n switch (operation) {\n case 'B':\n return 2;\n case 'A':\n return 3;\n case 'C':\n return 1;\n default:\n return 0;\n }\n}\nint command_read(const char *line, struct command *command) {\n const char *cursor = line;\n uint64_t slot;\n unsigned count;\n unsigned index;\n if (line == NULL || command == NULL) {\n return 0;\n }\n memset(command, 0, sizeof(*command));\n while (isspace((unsigned char)*cursor)) {\n ++cursor;\n }\n command->operation = *cursor++;\n if (command->operation == '\\0' || strchr(\"BASCXDQ\", command->operation) == NULL) {\n return 0;\n }\n if (!isspace((unsigned char)*cursor)) {\n return 0;\n }\n if (!number(&cursor, &slot) || slot >= DEVICE_SLOTS) {\n return 0;\n }\n command->slot = (unsigned)slot;\n count = arguments_for(command->operation);\n for (index = 0; index < count; ++index) {\n if (!number(&cursor, &command->arguments[index])) {\n return 0;\n }\n }\n while (isspace((unsigned char)*cursor)) {\n ++cursor;\n }\n return *cursor == '\\0';\n}\n",
|
||
"descriptor.h": "#ifndef DESCRIPTOR_H\n#define DESCRIPTOR_H\n#include <stddef.h>\n#include <stdint.h>\n#define MAX_ENTRIES 16u\n#define MAX_TRANSFER 1048576u\n#define WIRE_BYTES 32u\n#define DEVICE_SLOTS 2u\nenum result {\n RESULT_OK = 0,\n RESULT_INPUT = 1,\n RESULT_STATE = 2,\n RESULT_FULL = 3,\n RESULT_MEMORY = 4,\n RESULT_STALE = 5\n};\nenum phase {\n PHASE_IDLE = 0,\n PHASE_BUILDING = 1,\n PHASE_SUBMITTED = 2,\n PHASE_COMPLETE = 3\n};\nstruct memory_stats {\n size_t blocks;\n size_t bytes;\n size_t creates;\n size_t releases;\n};\nstruct transfer {\n uint64_t address;\n uint32_t length;\n uint32_t control;\n};\nstruct descriptor_table {\n unsigned char *data;\n size_t allocation_bytes;\n size_t stride;\n unsigned capacity;\n unsigned alignment;\n struct transfer staged[MAX_ENTRIES];\n};\nstruct batch {\n struct descriptor_table table;\n uint32_t epoch;\n unsigned count;\n enum phase phase;\n};\nstruct device_record {\n uintptr_t slot;\n uint64_t address;\n uint32_t length;\n uint32_t control;\n uint64_t cookie;\n uint32_t sequence;\n uint32_t checksum;\n};\nstruct command {\n char operation;\n unsigned slot;\n uint64_t arguments[3];\n};\nvoid *arena_allocate(size_t alignment, size_t bytes);\nvoid arena_release(void *pointer);\nstruct memory_stats arena_snapshot(void);\nint arena_is_empty(void);\nuint32_t wire_u32(const unsigned char *bytes);\nuint64_t wire_u64(const unsigned char *bytes);\nvoid wire_put32(unsigned char *bytes, uint32_t value);\nvoid wire_put64(unsigned char *bytes, uint64_t value);\nuint32_t descriptor_checksum(const unsigned char *bytes, size_t length);\nint table_create(struct descriptor_table *table, unsigned capacity, unsigned alignment);\nvoid table_destroy(struct descriptor_table *table);\nint table_store(struct descriptor_table *table, unsigned index,\n struct transfer transfer, uint64_t cookie);\nint table_publish(struct descriptor_table *table, unsigned count, uint64_t cookie);\nuintptr_t table_base(const struct descriptor_table *table);\nint device_read(const struct descriptor_table *table, unsigned index,\n struct device_record *record);\nvoid batch_initialize(struct batch *batch);\nint batch_begin(struct batch *batch, uint64_t capacity, uint64_t alignment);\nint batch_append(struct batch *batch, uint64_t address, uint64_t length, uint64_t control);\nint batch_submit(struct batch *batch);\nint batch_complete(struct batch *batch, uint64_t cookie);\nint batch_cancel(struct batch *batch);\nvoid batch_destroy(struct batch *batch);\nuint64_t batch_cookie(const struct batch *batch);\nint command_read(const char *line, struct command *command);\nvoid observe_batch(int result, const struct batch *batch);\n#endif\n",
|
||
"device.c": "#include \"descriptor.h\"\n#include <string.h>\nint device_read(const struct descriptor_table *table, unsigned index,\n struct device_record *record) {\n size_t offset;\n const unsigned char *bytes;\n if (table == NULL || record == NULL || table->data == NULL) {\n return RESULT_INPUT;\n }\n if (index >= table->capacity) {\n return RESULT_INPUT;\n }\n offset = (size_t)index * table->alignment;\n if (offset > table->allocation_bytes ||\n table->allocation_bytes - offset < WIRE_BYTES) {\n return RESULT_INPUT;\n }\n bytes = table->data + offset;\n memset(record, 0, sizeof(*record));\n record->slot = (uintptr_t)bytes;\n record->address = wire_u64(bytes);\n record->length = wire_u32(bytes + 8);\n record->control = wire_u32(bytes + 12);\n record->cookie = wire_u64(bytes + 16);\n record->sequence = wire_u32(bytes + 24);\n record->checksum = wire_u32(bytes + 28);\n return RESULT_OK;\n}\n",
|
||
"docs/console.md": "# 控制台原始观测\n\n每行一条命令,数值是十进制uint64。slot为0或1。B slot capacity alignment;A slot address length control;S slot;C slot cookie;X slot;D slot;Q slot。Q只观察,返回0;D调用destroy并返回0。非法命令语法写stderr并退出2;业务错误仍输出观测并继续,EOF正常销毁所有对象。\n每条有效命令输出一个JSON object:rc为API结果;view依次为phase、epoch、count、capacity、alignment、软件stride、真实base(uintptr十进制,无table时0);memory依次为blocks、bytes、creates、releases。\nwire在phase2/3时输出count个设备原始记录,否则空;每项依次是设备槽真实地址、address、length、control、cookie、sequence、checksum。设备槽不能读取时打印[null,错误码]。此观察器只输出原始值,没有期望或隐藏断言。\n返回码:0成功,1非法参数,2状态错误,3容量已满,4分配失败,5过期cookie。失败优先级见descriptor-contract.md。\n",
|
||
"docs/descriptor-contract.md": "# 描述符批次合同\n\nC01. 两个独立batch对象槽0、1。初始化phase=0、epoch=0、count=0、无table。每个非成功操作保持对象、资源统计和已发布有效字节不变。只检查有效count范围,不要求unused槽/尾部为零。\nC02. begin(capacity,alignment):capacity范围1..16,alignment只能32/64/128,非法返回1。phase=1/2时返回2;epoch=UINT32_MAX时返回2。其余成功返回0,epoch加一、count=0、phase=1,新table替换并释放旧table。参数检查优先于状态检查。\nC03. table由arena_allocate分配一个真实、非空、按alignment对齐的区域,恰为capacity*alignment字节。软件stride与设备槽距均为alignment。第i个设备槽地址=真实base+i*alignment,不是合成地址。每槽至少32字节。不做未对齐的C类型访问。\nC04. append(address,length,control):仅phase=1,否则2。length在1..1048576,control在0..3,address+length不得溢出uint64,非法1。合法参数但count=capacity返回3。否则按顺序存入、count加一,返回0。状态检查先于参数和容量检查。\nC05. submit:仅phase=1且count>0成功,返回0并phase=2;否则2。成功时所有有效槽编码完成。cookie=(uint64(epoch)<<32)|count,不受内存地址或另一对象影响。\nC06. 设备wire为little-endian:偏移0/8/12/16/24/28分别是address u64、length u32、control u32、cookie u64、sequence u32、checksum u32。sequence从0开始;checksum是前28字节FNV-1a32:初值2166136261,每字节先xor再乘16777619模2^32。全部有效项cookie等于当前batch cookie。device只解码原始bytes,不做通过判断。\nC07. complete(cookie):仅phase=2,否则2。cookie不同返回5,完全保持phase=2及内容。相同返回0并phase=3。取消、完成后重新begin时,旧通知不能完成新批次;begin每次成功都增加epoch,取消不重置epoch。\nC08. cancel任意phase返回0、释放table并清空table/count,phase=0,保留epoch;重复取消安全。destroy任意phase释放所有资源并恢复初始化状态,可重新使用对象。phase=3保留table供观察,直到begin/cancel/destroy。\nC09. 内存统计为arena真实追踪的全局blocks、bytes、累计creates、累计releases。每个成功begin新建一个table;释放任何已有table累计releases+1。无table释放不增加统计。所有对象销毁后blocks=bytes=0。begin替换已完成table时先建后换,分配失败返回4且保持原状态。\nC10. 支持边界值、任意合法地址、1..16项、32/64/128 alignment,两个槽交错操作、长序列重复使用、迟到与重复通知。业务只保证软件memory布局和生命周期;不证明硬件DMA/cache一致性。\nC11. 仅最终descriptor_table.c与batch.c进入评分。支持文件冻结为公开版本。可调整候选内部组织,但保持公开header ABI及全部行为。可使用staged记录、直接编码或其他正确实现。stderr允许任意诊断字节;stdout遵循控制台原始观测格式。正常合法控制台输入退出0,不可伪造原始地址或观测、绕开真正的table/device行为。\n",
|
||
"examples/demo.txt": "B 0 3 32\nA 0 4096 64 1\nA 0 8192 128 2\nS 0\nC 0 4294967298\nQ 0\nX 0\n",
|
||
"observe.c": "#include \"descriptor.h\"\n#include <inttypes.h>\n#include <stdio.h>\nvoid observe_batch(int result, const struct batch *batch) {\n struct memory_stats stats = arena_snapshot();\n unsigned index;\n printf(\"{\\\"rc\\\":%d,\\\"view\\\":[%u,%\" PRIu32 \",%u,%u,%u,%zu,%\" PRIuPTR\n \"],\\\"memory\\\":[%zu,%zu,%zu,%zu],\\\"wire\\\":[\", result,\n (unsigned)batch->phase, batch->epoch, batch->count,\n batch->table.capacity, batch->table.alignment, batch->table.stride,\n table_base(&batch->table), stats.blocks, stats.bytes,\n stats.creates, stats.releases);\n if (batch->phase == PHASE_SUBMITTED || batch->phase == PHASE_COMPLETE) {\n for (index = 0; index < batch->count; ++index) {\n struct device_record record;\n int read_result = device_read(&batch->table, index, &record);\n if (index != 0) {\n putchar(',');\n }\n if (read_result != RESULT_OK) {\n printf(\"[null,%d]\", read_result);\n } else {\n printf(\"[%\" PRIuPTR \",%\" PRIu64 \",%\" PRIu32 \",%\" PRIu32\n \",%\" PRIu64 \",%\" PRIu32 \",%\" PRIu32 \"]\", record.slot,\n record.address, record.length, record.control,\n record.cookie, record.sequence, record.checksum);\n }\n }\n }\n puts(\"]}\");\n}\nstatic int dispatch(struct batch *batch, const struct command *command) {\n switch (command->operation) {\n case 'B':\n return batch_begin(batch, command->arguments[0], command->arguments[1]);\n case 'A':\n return batch_append(batch, command->arguments[0], command->arguments[1],\n command->arguments[2]);\n case 'S':\n return batch_submit(batch);\n case 'C':\n return batch_complete(batch, command->arguments[0]);\n case 'X':\n return batch_cancel(batch);\n case 'D':\n batch_destroy(batch);\n return RESULT_OK;\n case 'Q':\n return RESULT_OK;\n default:\n return RESULT_INPUT;\n }\n}\nint main(void) {\n struct batch batches[DEVICE_SLOTS];\n struct command command;\n char line[512];\n unsigned slot;\n int result = 0;\n for (slot = 0; slot < DEVICE_SLOTS; ++slot) {\n batch_initialize(&batches[slot]);\n }\n while (fgets(line, sizeof(line), stdin) != NULL) {\n if (!command_read(line, &command)) {\n fputs(\"invalid console command\\n\", stderr);\n result = 2;\n break;\n }\n observe_batch(dispatch(&batches[command.slot], &command), &batches[command.slot]);\n }\n for (slot = 0; slot < DEVICE_SLOTS; ++slot) {\n batch_destroy(&batches[slot]);\n }\n return arena_is_empty() ? result : 3;\n}\n",
|
||
"wire.c": "#include \"descriptor.h\"\nuint32_t wire_u32(const unsigned char *bytes) {\n uint32_t value = 0;\n unsigned index;\n for (index = 0; index < 4; ++index) {\n value |= (uint32_t)bytes[index] << (8 * index);\n }\n return value;\n}\nuint64_t wire_u64(const unsigned char *bytes) {\n uint64_t value = 0;\n unsigned index;\n for (index = 0; index < 8; ++index) {\n value |= (uint64_t)bytes[index] << (8 * index);\n }\n return value;\n}\nvoid wire_put32(unsigned char *bytes, uint32_t value) {\n unsigned index;\n for (index = 0; index < 4; ++index) {\n bytes[index] = (unsigned char)(value >> (8 * index));\n }\n}\nvoid wire_put64(unsigned char *bytes, uint64_t value) {\n unsigned index;\n for (index = 0; index < 8; ++index) {\n bytes[index] = (unsigned char)(value >> (8 * index));\n }\n}\nuint32_t descriptor_checksum(const unsigned char *bytes, size_t length) {\n uint32_t value = UINT32_C(2166136261);\n size_t index;\n for (index = 0; index < length; ++index) {\n value ^= bytes[index];\n value *= UINT32_C(16777619);\n }\n return value;\n}\n"
|
||
}
|