All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
3.6 KiB
C++
127 lines
3.6 KiB
C++
#include "sysctl_overlay.hpp"
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <map>
|
|
#include <set>
|
|
#include <utility>
|
|
|
|
namespace sysctloverlay {
|
|
namespace {
|
|
|
|
bool prepare_keys(const std::vector<std::string> &keys,
|
|
std::vector<std::string> &sorted)
|
|
{
|
|
if (keys.size() > 256) {
|
|
return false;
|
|
}
|
|
std::set<std::string> unique;
|
|
std::size_t bytes = 0;
|
|
for (const std::string &key : keys) {
|
|
if (!valid_kernel_key(key) || !unique.insert(key).second) {
|
|
return false;
|
|
}
|
|
bytes += key.size();
|
|
if (bytes > 32768) {
|
|
return false;
|
|
}
|
|
}
|
|
sorted.assign(unique.begin(), unique.end());
|
|
return true;
|
|
}
|
|
|
|
bool matching_budget(const Configuration &configuration,
|
|
const std::vector<std::string> &keys)
|
|
{
|
|
std::uint64_t work = 0;
|
|
for (const LocatedRule &located : configuration.rules) {
|
|
if (located.rule.kind != RuleKind::assignment || !located.rule.pattern) {
|
|
continue;
|
|
}
|
|
for (const std::string &key : keys) {
|
|
work += std::uint64_t(located.rule.key.size() + 1) * (key.size() + 1);
|
|
if (work > 16777216) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void replace_record(const std::string &key, const LocatedRule &located,
|
|
std::map<std::string, Entry> &records)
|
|
{
|
|
Entry next;
|
|
next.key = key;
|
|
next.value = located.rule.value;
|
|
next.ignore_error = located.rule.ignore_error;
|
|
next.layer = located.layer;
|
|
next.basename = located.basename;
|
|
next.row = located.rule.row;
|
|
const auto old = records.find(key);
|
|
if (old != records.end()) {
|
|
next.ignore_error = old->second.ignore_error;
|
|
}
|
|
records[key] = std::move(next);
|
|
}
|
|
|
|
}
|
|
|
|
Error plan_configuration(const Configuration &configuration,
|
|
const std::vector<std::string> &keys, Plan &output)
|
|
{
|
|
output = Plan{};
|
|
std::vector<std::string> sorted;
|
|
if (!prepare_keys(keys, sorted) || !matching_budget(configuration, sorted)) {
|
|
return Error::invalid;
|
|
}
|
|
std::map<std::string, Entry> records;
|
|
for (const LocatedRule &located : configuration.rules) {
|
|
const Rule &rule = located.rule;
|
|
if (rule.kind == RuleKind::exclusion) {
|
|
continue;
|
|
}
|
|
if (!rule.pattern) {
|
|
if (!std::binary_search(sorted.begin(), sorted.end(), rule.key)) {
|
|
if (rule.ignore_error) {
|
|
continue;
|
|
}
|
|
return Error::invalid;
|
|
}
|
|
replace_record(rule.key, located, records);
|
|
continue;
|
|
}
|
|
for (const std::string &key : sorted) {
|
|
if (std::binary_search(configuration.excluded.begin(),
|
|
configuration.excluded.end(), key)) {
|
|
continue;
|
|
}
|
|
bool matches = false;
|
|
if (match_pattern(rule.key, key, matches) != Error::none) {
|
|
return Error::invalid;
|
|
}
|
|
if (matches) {
|
|
replace_record(key, located, records);
|
|
}
|
|
}
|
|
}
|
|
Plan result;
|
|
for (const auto &entry : records) {
|
|
result.entries.push_back(entry.second);
|
|
}
|
|
output = std::move(result);
|
|
return Error::none;
|
|
}
|
|
|
|
Error make_plan(const std::vector<Layer> &layers,
|
|
const std::vector<std::string> &keys, Plan &output)
|
|
{
|
|
output = Plan{};
|
|
Configuration configuration;
|
|
if (compile_configuration(layers, configuration) != Error::none) {
|
|
return Error::invalid;
|
|
}
|
|
return plan_configuration(configuration, keys, output);
|
|
}
|
|
|
|
}
|