Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao environments: hidden assertions that ran inside the candidate's process now run in a trusted parent that reads observations from a low-UID worker; gold bytes are unchanged. 9 were excluded for scope (ROS2, oversize, security core), 3 are blocked because the source requires an exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6. Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the first 100 landed in 2f32624d. Claude reviewed 74/74 USABLE against current digests, canonical families, no ID or source overlap with main, plain public docs. Only the new task directories are taken; the stale pre-batch-20 copies of concur-release-capsule and resource-temp-link on the batch 21 branch and both branches' progress notes stay as main has them. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
237 lines
6.5 KiB
C++
237 lines
6.5 KiB
C++
#include <iostream>
|
|
#include "internal.hpp"
|
|
namespace edge {
|
|
namespace detail {
|
|
bool pin_range(std::int64_t value) {
|
|
return value >= 0 && value <= 7;
|
|
}
|
|
bool fd_range(std::int64_t value) {
|
|
return value >= 0 && value <= 15;
|
|
}
|
|
bool mode_range(std::int64_t value) {
|
|
return value >= 0 && value <= 3;
|
|
}
|
|
bool bit_range(std::int64_t value) {
|
|
return value >= 0 && value <= 1;
|
|
}
|
|
bool offset_range(std::int64_t value) {
|
|
return value >= 0 && value <= 2;
|
|
}
|
|
bool count_range(std::int64_t value) {
|
|
return value >= 0 && value <= 8;
|
|
}
|
|
bool events_range(std::int64_t value) {
|
|
return value >= 0 && value <= 7;
|
|
}
|
|
bool transition_matches(int mode, int before, int after) {
|
|
if (before == after) {
|
|
return false;
|
|
}
|
|
if (mode == 3) {
|
|
return true;
|
|
}
|
|
if (mode == 1) {
|
|
return before == 0 && after == 1;
|
|
}
|
|
if (mode == 2) {
|
|
return before == 1 && after == 0;
|
|
}
|
|
return false;
|
|
}
|
|
Reply failure(const std::string& name) {
|
|
Reply result;
|
|
result.error = name;
|
|
return result;
|
|
}
|
|
Reply success(std::int64_t number, const std::string& bytes) {
|
|
Reply result;
|
|
result.number = number;
|
|
result.bytes = bytes;
|
|
return result;
|
|
}
|
|
}
|
|
Bank::Bank() : state_(new State) {
|
|
std::cout << "trace\n";
|
|
}
|
|
Bank::~Bank() = default;
|
|
bool Bank::State::pending(int fd) const {
|
|
return descriptors[fd].pending;
|
|
}
|
|
void Bank::State::acknowledge(int fd) {
|
|
descriptors[fd].pending = false;
|
|
}
|
|
void Bank::State::notify(int pin) {
|
|
for (auto& entry : descriptors) {
|
|
if (entry.live && entry.pin == pin) {
|
|
entry.pending = true;
|
|
}
|
|
}
|
|
}
|
|
void Bank::State::disarm(int pin) {
|
|
for (auto& entry : descriptors) {
|
|
if (entry.live && entry.pin == pin) {
|
|
entry.pending = false;
|
|
}
|
|
}
|
|
}
|
|
Reply Bank::configure(std::int64_t pin, std::int64_t mode) {
|
|
if (!detail::pin_range(pin)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
if (!detail::mode_range(mode)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
auto& line = state_->pins[static_cast<int>(pin)];
|
|
line.mode = static_cast<int>(mode);
|
|
if (mode == 0) {
|
|
state_->disarm(static_cast<int>(pin));
|
|
} else {
|
|
state_->notify(static_cast<int>(pin));
|
|
}
|
|
return detail::success(mode);
|
|
}
|
|
Reply Bank::drive(std::int64_t pin, std::int64_t value) {
|
|
if (!detail::pin_range(pin)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
if (!detail::bit_range(value)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
auto& line = state_->pins[static_cast<int>(pin)];
|
|
const int previous = line.value;
|
|
const int next = static_cast<int>(value);
|
|
if (previous != next) {
|
|
line.value = next;
|
|
++line.changes;
|
|
}
|
|
if (detail::transition_matches(line.mode, previous, next)) {
|
|
state_->notify(static_cast<int>(pin));
|
|
}
|
|
return detail::success(value);
|
|
}
|
|
Reply Bank::open(std::int64_t fd, std::int64_t pin) {
|
|
if (!detail::fd_range(fd)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
if (!detail::pin_range(pin)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
auto& entry = state_->descriptors[static_cast<int>(fd)];
|
|
if (entry.live) {
|
|
return detail::failure("EXISTS");
|
|
}
|
|
entry.live = true;
|
|
entry.pin = static_cast<int>(pin);
|
|
entry.cursor = 0;
|
|
entry.pending = state_->pins[static_cast<int>(pin)].mode != 0;
|
|
return detail::success(fd);
|
|
}
|
|
Reply Bank::close(std::int64_t fd) {
|
|
if (!detail::fd_range(fd)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
auto& entry = state_->descriptors[static_cast<int>(fd)];
|
|
if (!entry.live) {
|
|
return detail::failure("CLOSED");
|
|
}
|
|
entry = DescriptorState{};
|
|
return detail::success(fd);
|
|
}
|
|
Reply Bank::seek(std::int64_t fd, std::int64_t offset) {
|
|
if (!detail::fd_range(fd)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
if (!detail::offset_range(offset)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
auto& entry = state_->descriptors[static_cast<int>(fd)];
|
|
if (!entry.live) {
|
|
return detail::failure("CLOSED");
|
|
}
|
|
entry.cursor = static_cast<int>(offset);
|
|
return detail::success(offset);
|
|
}
|
|
Reply Bank::poll(std::int64_t fd, std::int64_t events) const {
|
|
if (!detail::fd_range(fd)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
if (!detail::events_range(events)) {
|
|
return detail::failure("RANGE");
|
|
}
|
|
const auto& entry = state_->descriptors[static_cast<int>(fd)];
|
|
if (!entry.live) {
|
|
return detail::failure("CLOSED");
|
|
}
|
|
const int requested = static_cast<int>(events);
|
|
const int returned = state_->pending(static_cast<int>(fd)) ? requested & 6 : 0;
|
|
return detail::success(returned);
|
|
}
|
|
PollView Bank::poll_many(const std::vector<Watch>& watches) const {
|
|
PollView result;
|
|
if (watches.size() > 16) {
|
|
result.error = "RANGE";
|
|
return result;
|
|
}
|
|
for (const auto& request : watches) {
|
|
if (!detail::fd_range(request.fd)) {
|
|
result.error = "RANGE";
|
|
return result;
|
|
}
|
|
if (!detail::events_range(request.events)) {
|
|
result.error = "RANGE";
|
|
return result;
|
|
}
|
|
}
|
|
for (const auto& request : watches) {
|
|
const auto& entry = state_->descriptors[static_cast<int>(request.fd)];
|
|
if (!entry.live) {
|
|
result.error = "CLOSED";
|
|
return result;
|
|
}
|
|
}
|
|
result.ready = 0;
|
|
result.returned.reserve(watches.size());
|
|
for (const auto& request : watches) {
|
|
const int fd = static_cast<int>(request.fd);
|
|
const int events = static_cast<int>(request.events);
|
|
int revents = 0;
|
|
if (state_->pending(fd)) {
|
|
revents = events & 6;
|
|
}
|
|
result.returned.push_back(revents);
|
|
if (revents != 0) {
|
|
++result.ready;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
PinView Bank::pin(std::int64_t pin) const {
|
|
PinView result;
|
|
if (!detail::pin_range(pin)) {
|
|
result.error = "RANGE";
|
|
return result;
|
|
}
|
|
const auto& line = state_->pins[static_cast<int>(pin)];
|
|
result.value = line.value;
|
|
result.mode = line.mode;
|
|
result.changes = line.changes;
|
|
return result;
|
|
}
|
|
FdView Bank::descriptor(std::int64_t fd) const {
|
|
FdView result;
|
|
if (!detail::fd_range(fd)) {
|
|
result.error = "RANGE";
|
|
return result;
|
|
}
|
|
const auto& entry = state_->descriptors[static_cast<int>(fd)];
|
|
if (!entry.live) {
|
|
result.error = "CLOSED";
|
|
return result;
|
|
}
|
|
result.pin = entry.pin;
|
|
result.cursor = entry.cursor;
|
|
result.pending = state_->pending(static_cast<int>(fd));
|
|
return result;
|
|
}
|
|
}
|