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>
212 lines
7.2 KiB
C
212 lines
7.2 KiB
C
#include "rb.h"
|
|
#include <string.h>
|
|
|
|
static int valid_span(const rb_batch *batch, size_t offset, size_t length)
|
|
{
|
|
if (offset > batch->width) return 0;
|
|
return length <= batch->width - offset;
|
|
}
|
|
|
|
static unsigned char initial_byte(uint32_t salt, size_t index, size_t offset)
|
|
{
|
|
uint32_t value = salt + (uint32_t)(17u * index) + (uint32_t)(29u * offset);
|
|
return (unsigned char)(value & 255u);
|
|
}
|
|
|
|
static void reset_batch(rb_batch *batch)
|
|
{
|
|
batch->slots = NULL;
|
|
batch->allocator.context = NULL;
|
|
batch->allocator.take = NULL;
|
|
batch->allocator.give = NULL;
|
|
batch->count = 0;
|
|
batch->width = 0;
|
|
batch->obtained = 0;
|
|
batch->salt = 0;
|
|
batch->writes = 0;
|
|
batch->copies = 0;
|
|
}
|
|
|
|
int rb_open(rb_batch *batch, rb_allocator allocator, size_t count,
|
|
size_t width, uint32_t salt)
|
|
{
|
|
size_t index;
|
|
unsigned char **slots;
|
|
if (batch == NULL) return RB_BAD_ARGUMENT;
|
|
if (batch->slots != NULL) return RB_ALREADY_OPEN;
|
|
if (allocator.take == NULL || allocator.give == NULL ||
|
|
count == 0 || count > RB_LIMIT || width < 8 || width > RB_MAX_WIDTH)
|
|
return RB_BAD_ARGUMENT;
|
|
slots = allocator.take(allocator.context, count * sizeof(*slots), RB_TABLE_TAG);
|
|
if (slots == NULL) return RB_TABLE_FAILED;
|
|
memset(slots, 0, count * sizeof(*slots));
|
|
batch->slots = slots;
|
|
batch->allocator = allocator;
|
|
batch->count = count;
|
|
batch->width = width;
|
|
batch->obtained = 0;
|
|
batch->salt = salt;
|
|
batch->writes = 0;
|
|
batch->copies = 0;
|
|
for (index = 0; index < count; ++index) {
|
|
size_t position;
|
|
unsigned char *block = allocator.take(allocator.context, width,
|
|
(uint32_t)index + 1u);
|
|
slots[index] = block;
|
|
if (block == NULL) continue;
|
|
++batch->obtained;
|
|
for (position = 0; position < width; ++position)
|
|
block[position] = initial_byte(salt, index, position);
|
|
}
|
|
return RB_OK;
|
|
}
|
|
|
|
void rb_close(rb_batch *batch)
|
|
{
|
|
size_t index;
|
|
if (batch == NULL || batch->slots == NULL) return;
|
|
for (index = 0; index < batch->count; ++index) {
|
|
if (batch->slots[index] != NULL)
|
|
batch->allocator.give(batch->allocator.context, batch->slots[index],
|
|
(uint32_t)index + 1u);
|
|
}
|
|
batch->allocator.give(batch->allocator.context, batch->slots, RB_TABLE_TAG);
|
|
reset_batch(batch);
|
|
}
|
|
|
|
size_t rb_obtained(const rb_batch *batch)
|
|
{
|
|
if (batch == NULL || batch->slots == NULL) return 0;
|
|
return batch->obtained;
|
|
}
|
|
|
|
int rb_is_available(const rb_batch *batch, size_t index)
|
|
{
|
|
if (batch == NULL || batch->slots == NULL || index >= batch->count)
|
|
return RB_BAD_ARGUMENT;
|
|
return batch->slots[index] != NULL ? 1 : 0;
|
|
}
|
|
|
|
int rb_put(rb_batch *batch, size_t index, size_t offset,
|
|
const unsigned char *source, size_t length)
|
|
{
|
|
if (batch == NULL || batch->slots == NULL || index >= batch->count ||
|
|
(source == NULL && length != 0) || !valid_span(batch, offset, length))
|
|
return RB_BAD_ARGUMENT;
|
|
if (batch->slots[index] == NULL) return RB_UNAVAILABLE;
|
|
if (length != 0) memcpy(batch->slots[index] + offset, source, length);
|
|
++batch->writes;
|
|
return RB_OK;
|
|
}
|
|
|
|
int rb_get(const rb_batch *batch, size_t index, size_t offset,
|
|
unsigned char *destination, size_t length)
|
|
{
|
|
if (batch == NULL || batch->slots == NULL || index >= batch->count ||
|
|
(destination == NULL && length != 0) || !valid_span(batch, offset, length))
|
|
return RB_BAD_ARGUMENT;
|
|
if (batch->slots[index] == NULL) return RB_UNAVAILABLE;
|
|
if (length != 0) memcpy(destination, batch->slots[index] + offset, length);
|
|
return RB_OK;
|
|
}
|
|
|
|
int rb_copy(rb_batch *batch, size_t from, size_t to, size_t offset,
|
|
size_t length)
|
|
{
|
|
if (batch == NULL || batch->slots == NULL ||
|
|
from >= batch->count || to >= batch->count ||
|
|
!valid_span(batch, offset, length)) return RB_BAD_ARGUMENT;
|
|
if (batch->slots[from] == NULL || batch->slots[to] == NULL)
|
|
return RB_UNAVAILABLE;
|
|
if (length != 0 && from != to)
|
|
memcpy(batch->slots[to] + offset, batch->slots[from] + offset, length);
|
|
++batch->copies;
|
|
return RB_OK;
|
|
}
|
|
|
|
int rb_digest(const rb_batch *batch, size_t index, uint32_t *value)
|
|
{
|
|
size_t position;
|
|
uint32_t hash = UINT32_C(2166136261);
|
|
if (batch == NULL || batch->slots == NULL || index >= batch->count ||
|
|
value == NULL) return RB_BAD_ARGUMENT;
|
|
if (batch->slots[index] == NULL) return RB_UNAVAILABLE;
|
|
for (position = 0; position < batch->width; ++position) {
|
|
hash ^= (unsigned char)position;
|
|
hash *= UINT32_C(16777619);
|
|
}
|
|
*value = hash;
|
|
return RB_OK;
|
|
}
|
|
|
|
int rb_fill(rb_batch *batch, size_t index, size_t offset,
|
|
size_t length, unsigned char value)
|
|
{
|
|
if (batch == NULL || batch->slots == NULL || index >= batch->count ||
|
|
!valid_span(batch, offset, length)) return RB_BAD_ARGUMENT;
|
|
if (batch->slots[index] == NULL) return RB_UNAVAILABLE;
|
|
if (length != 0) memset(batch->slots[index] + offset, value, length);
|
|
++batch->writes;
|
|
return RB_OK;
|
|
}
|
|
|
|
int rb_xor(rb_batch *batch, size_t index, size_t offset,
|
|
size_t length, unsigned char mask)
|
|
{
|
|
size_t position;
|
|
if (batch == NULL || batch->slots == NULL || index >= batch->count ||
|
|
!valid_span(batch, offset, length)) return RB_BAD_ARGUMENT;
|
|
if (batch->slots[index] == NULL) return RB_UNAVAILABLE;
|
|
for (position = offset; position < offset + length; ++position)
|
|
batch->slots[index][position] ^= mask;
|
|
++batch->writes;
|
|
return RB_OK;
|
|
}
|
|
|
|
int rb_equal(const rb_batch *batch, size_t left, size_t right,
|
|
size_t offset, size_t length, int *equal)
|
|
{
|
|
if (batch == NULL || batch->slots == NULL || equal == NULL ||
|
|
left >= batch->count || right >= batch->count ||
|
|
!valid_span(batch, offset, length)) return RB_BAD_ARGUMENT;
|
|
if (batch->slots[left] == NULL || batch->slots[right] == NULL)
|
|
return RB_UNAVAILABLE;
|
|
*equal = memcmp(batch->slots[left] + offset,
|
|
batch->slots[right] + offset, length) == 0;
|
|
return RB_OK;
|
|
}
|
|
|
|
int rb_find(const rb_batch *batch, size_t index, size_t offset,
|
|
size_t length, unsigned char needle, size_t *found)
|
|
{
|
|
size_t position;
|
|
if (batch == NULL || batch->slots == NULL || found == NULL ||
|
|
index >= batch->count || !valid_span(batch, offset, length))
|
|
return RB_BAD_ARGUMENT;
|
|
if (batch->slots[index] == NULL) return RB_UNAVAILABLE;
|
|
*found = batch->width;
|
|
for (position = offset; position < offset + length; ++position) {
|
|
if (batch->slots[index][position] == needle) {
|
|
*found = position;
|
|
break;
|
|
}
|
|
}
|
|
return RB_OK;
|
|
}
|
|
|
|
int rb_count_byte(const rb_batch *batch, size_t index, size_t offset,
|
|
size_t length, unsigned char needle, size_t *matches)
|
|
{
|
|
size_t position;
|
|
size_t total = 0;
|
|
if (batch == NULL || batch->slots == NULL || matches == NULL ||
|
|
index >= batch->count || !valid_span(batch, offset, length))
|
|
return RB_BAD_ARGUMENT;
|
|
if (batch->slots[index] == NULL) return RB_UNAVAILABLE;
|
|
for (position = offset; position < offset + length; ++position) {
|
|
if (batch->slots[index][position] == needle) ++total;
|
|
}
|
|
*matches = total;
|
|
return RB_OK;
|
|
}
|