amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

166 lines
4.6 KiB
C++

#include "minor_router.hpp"
#include <algorithm>
#include <limits>
namespace minorio {
int Router::extract(const Device &object, std::uint64_t offset,
std::uint64_t count, Bytes &out)
{
Bytes result;
if (offset < object.data.size()) {
const auto available = object.data.size() - static_cast<std::size_t>(offset);
const auto amount = static_cast<std::size_t>(std::min<std::uint64_t>(count, available));
const auto first = object.data.begin() + static_cast<std::size_t>(offset);
result.assign(first, first + amount);
}
const int result_size = static_cast<int>(result.size());
out.swap(result);
return result_size;
}
int Router::store(Device &object, std::uint64_t offset, const Bytes &data)
{
if (data.empty()) {
return 0;
}
const auto room = object.capacity - static_cast<std::size_t>(offset);
const auto amount = std::min(room, data.size());
if (amount == 0) {
return 0;
}
const auto finish = static_cast<std::size_t>(offset) + amount;
if (object.data.size() < finish) {
object.data.resize(finish, 0);
}
auto destination = object.data.begin() + static_cast<std::size_t>(offset);
std::copy_n(data.begin(), amount, destination);
return static_cast<int>(amount);
}
int Router::read(int fd, std::uint64_t count, Bytes &out)
{
std::shared_ptr<Session> value;
const int error = readable(fd, value);
if (error != 0) {
return error;
}
const int amount = extract(*value->object, value->cursor, count, out);
const auto room = value->object->capacity - value->cursor;
value->cursor += std::min<std::uint64_t>(count, room);
return amount;
}
int Router::write(int fd, const Bytes &data)
{
std::shared_ptr<Session> value;
const int error = writable(fd, value);
if (error != 0) {
return error;
}
if (data.size() > 4096) {
return -22;
}
if (data.empty()) {
return 0;
}
const auto offset = value->append ? value->object->data.size() : value->cursor;
const int amount = store(*value->object, offset, data);
value->cursor = offset + static_cast<std::uint64_t>(amount);
return amount;
}
int Router::pread(int fd, std::uint64_t offset, std::uint64_t count, Bytes &out)
{
std::shared_ptr<Session> value;
const int error = readable(fd, value);
if (error != 0) {
return error;
}
if (offset > value->object->capacity) {
return -22;
}
return extract(*value->object, offset, count, out);
}
int Router::pwrite(int fd, std::uint64_t offset, const Bytes &data)
{
std::shared_ptr<Session> value;
const int error = writable(fd, value);
if (error != 0) {
return error;
}
if (offset > value->object->capacity) {
return -22;
}
if (data.size() > 4096) {
return -22;
}
return store(*value->object, offset, data);
}
int Router::seek(int fd, int whence, std::int64_t delta)
{
auto value = find_session(fd);
if (!value) {
return -9;
}
std::uint64_t base = 0;
if (whence == 0) {
base = 0;
} else if (whence == 1) {
base = value->cursor;
} else if (whence == 2) {
base = value->object->data.size();
} else {
return -22;
}
std::uint64_t result = base;
if (delta >= 0) {
const auto amount = static_cast<std::uint64_t>(delta);
const auto room = value->object->capacity - base;
if (amount > room) {
return -22;
}
result += amount;
} else {
const auto amount = static_cast<std::uint64_t>(-(delta + 1)) + 1;
if (amount > base) {
return -22;
}
result -= amount;
}
value->cursor = result;
return static_cast<int>(result);
}
int Router::resize(int fd, std::uint64_t length)
{
std::shared_ptr<Session> value;
const int error = writable(fd, value);
if (error != 0) {
return error;
}
if (length > value->object->capacity) {
return -22;
}
value->object->data.resize(static_cast<std::size_t>(length), 0);
return 0;
}
int Router::clear(int fd)
{
std::shared_ptr<Session> value;
const int error = writable(fd, value);
if (error != 0) {
return error;
}
value->object->data.clear();
return 0;
}
int Router::peek(int minor, std::uint64_t offset, std::uint64_t count, Bytes &out) const
{
if (!valid_minor(minor)) {
return -22;
}
const auto object = route(minor);
if (!object) {
return -2;
}
if (offset > object->capacity) {
return -22;
}
return extract(*object, offset, count, out);
}
}