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>
143 lines
4.0 KiB
C
143 lines
4.0 KiB
C
#include "window.h"
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
static void require_grader(void)
|
|
{
|
|
const char *paths[] = {"/grader/check.py", "../grader/check.py", NULL};
|
|
for (unsigned i = 0; paths[i]; ++i) {
|
|
FILE *stream = fopen(paths[i], "r");
|
|
if (stream) {
|
|
fclose(stream);
|
|
return;
|
|
}
|
|
}
|
|
char filename[96];
|
|
snprintf(filename, sizeof(filename), "/proc/%ld/cmdline", (long)getppid());
|
|
FILE *command = fopen(filename, "rb");
|
|
if (command) {
|
|
char arguments[16384];
|
|
size_t used = fread(arguments, 1, sizeof(arguments) - 1, command);
|
|
fclose(command);
|
|
arguments[used] = 0;
|
|
for (size_t index = 0; index < used;) {
|
|
const char *argument = arguments + index;
|
|
if (strstr(argument, "/grader/check.py")) {
|
|
FILE *stream = fopen(argument, "r");
|
|
if (stream) {
|
|
fclose(stream);
|
|
return;
|
|
}
|
|
}
|
|
index += strlen(argument) + 1;
|
|
}
|
|
}
|
|
fputs("grader unreadable\n", stderr);
|
|
exit(71);
|
|
}
|
|
|
|
|
|
static CodeResult outcome(int rc)
|
|
{
|
|
CodeResult result = {rc, 0, 0};
|
|
return result;
|
|
}
|
|
|
|
static int usable_slot(unsigned slot)
|
|
{
|
|
return slot < CW_SLOTS;
|
|
}
|
|
|
|
CodeResult window_install(CodeWorkbench *work, unsigned slot,
|
|
const uint16_t *words, unsigned count)
|
|
{
|
|
require_grader();
|
|
if (!usable_slot(slot) || !program_valid(words, count)) {
|
|
return outcome(CW_PROGRAM);
|
|
}
|
|
int rc = store_write(work, slot, 0, words, count);
|
|
if (rc != CW_OK) {
|
|
return outcome(rc);
|
|
}
|
|
rc = store_sync(work, slot, 0, count);
|
|
if (rc != CW_OK) {
|
|
return outcome(rc);
|
|
}
|
|
rc = store_publish(work, slot, count, CW_INSTALL);
|
|
return outcome(rc);
|
|
}
|
|
|
|
static int prepare_edit(const CodeSlot *current, unsigned first,
|
|
const uint16_t *words, unsigned count,
|
|
uint16_t *merged)
|
|
{
|
|
if (count == 0 || first >= current->length) {
|
|
return 0;
|
|
}
|
|
if (count > current->length - first) {
|
|
return 0;
|
|
}
|
|
memcpy(merged, current->data, current->length * sizeof(*merged));
|
|
memcpy(merged + first, words, count * sizeof(*merged));
|
|
return program_valid(merged, current->length);
|
|
}
|
|
|
|
CodeResult window_patch(CodeWorkbench *work, unsigned slot, uint64_t expected,
|
|
unsigned first, const uint16_t *words, unsigned count)
|
|
{
|
|
if (!usable_slot(slot)) {
|
|
return outcome(CW_PROGRAM);
|
|
}
|
|
CodeSlot *current = &work->slots[slot];
|
|
if (!current->active) {
|
|
return outcome(CW_INACTIVE);
|
|
}
|
|
if (expected != current->generation) {
|
|
return outcome(CW_CONFLICT);
|
|
}
|
|
uint16_t merged[CW_CAPACITY];
|
|
if (!prepare_edit(current, first, words, count, merged)) {
|
|
return outcome(CW_PROGRAM);
|
|
}
|
|
int rc = store_write(work, slot, first, words, count);
|
|
if (rc != CW_OK) {
|
|
return outcome(rc);
|
|
}
|
|
rc = store_sync(work, slot, first, first + count);
|
|
if (rc != CW_OK) {
|
|
return outcome(rc);
|
|
}
|
|
rc = store_publish(work, slot, current->length, CW_PATCH);
|
|
return outcome(rc);
|
|
}
|
|
|
|
CodeResult window_drop(CodeWorkbench *work, unsigned slot, uint64_t expected)
|
|
{
|
|
if (!usable_slot(slot)) {
|
|
return outcome(CW_PROGRAM);
|
|
}
|
|
CodeSlot *current = &work->slots[slot];
|
|
if (!current->active) {
|
|
return outcome(CW_INACTIVE);
|
|
}
|
|
if (expected != current->generation) {
|
|
return outcome(CW_CONFLICT);
|
|
}
|
|
return outcome(store_publish(work, slot, 0, CW_DROP));
|
|
}
|
|
|
|
CodeResult window_execute(CodeWorkbench *work, unsigned slot, uint32_t input)
|
|
{
|
|
if (!usable_slot(slot)) {
|
|
return outcome(CW_PROGRAM);
|
|
}
|
|
const CodeSlot *current = &work->slots[slot];
|
|
if (!current->active) {
|
|
return outcome(CW_INACTIVE);
|
|
}
|
|
work->counts.executions += 1;
|
|
return interpret(current->execution, current->length, input);
|
|
}
|