Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ members = [
"system/toybox",
"system/toybox/copies",
"system/trace",
"system/uart",
"system/update",
"system/update/copies",
"system/usbd",
Expand Down
82 changes: 76 additions & 6 deletions build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ struct ProgramConfig {
syscap: Vec<String>,
/// The idle slot (`toyos_manifest::Program::slots`).
slots: bool,
/// The machine-wide objects the supervisor makes once and endows this row
/// (`toyos_manifest::Program::holds`).
holds: Vec<String>,
/// Disk authorizations minted at its start (`toyos_manifest::authorize`).
authorize: Vec<String>,
/// A system service: the supervisor starts it with `HOME` at its own `/state/<name>`
Expand Down Expand Up @@ -677,7 +680,8 @@ const SUPERVISOR_SERVED: &[&str] = &[toyos_swap::PORT, "power", toyos_manifest::
/// drawn at, the session-admin port, whose holder signs its user's sessions
/// out, the wifi port, whose holder joins networks and hands over their
/// passphrases, the radio port, whose holder is sent a network's keys, the
/// log's carrier port, for whose holder the console UART goes quiet, and the
/// log's carrier port, for whose holder the console UART goes quiet, the
/// log's wire port, whose holder puts the log on the console UART, and the
/// clipboard agent's port, whose holder speaks to the agent as the host.
const HELD_ALONE: &[(&str, &[&str])] = &[
(toyos_swap::PORT, &[toyos_swap::HOLDER]),
Expand All @@ -690,17 +694,30 @@ const HELD_ALONE: &[(&str, &[&str])] = &[
(toyos_wifi::PORT, toyos_wifi::HOLDERS),
(toyos_radio::PORT, toyos_radio::HOLDERS),
(toyos_logstream::CARRIER, &[toyos_logstream::CARRIER_HOLDER]),
(toyos_logstream::WIRE, &[toyos_logstream::WIRE_HOLDER]),
(toyos_vdagent::endpoint::SERVICE, &[toyos_vdagent::endpoint::SERVICE_HOLDER]),
];

/// The objects the supervisor makes once and endows the row that holds them
/// (`toyos_manifest::HOLDINGS`), each with the one row that may: the acceptor
/// every program's log ring reaches `logkeeper` on, whose holder names every
/// line's writer, and the console's input, whose holder types at every
/// program's standard input.
const HOLDINGS: &[(&str, &str)] = &[
(toyos_logstream::ORIGINS, toyos_logstream::LOGKEEPER),
(toyos_logstream::CONSOLE_INPUT, toyos_logstream::WIRE_HOLDER),
];

/// Rows, as a refusal names them.
fn named(rows: &[&str]) -> String {
rows.iter().map(|r| format!("`{r}`")).collect::<Vec<_>>().join(" and ")
}

/// Who may hold the authorities that change what the machine runs or what a
/// package sees: each of [`HELD_ALONE`]'s ports, its holder and nothing else
/// — no other `[programs]` row and never `[apps]` — the idle slot,
/// — no other `[programs]` row and never `[apps]` — each of [`HOLDINGS`], its
/// one row, the `console` syscap, which keeps the kernel's records off a fatal
/// path's output, `logkeeper` alone, the idle slot,
/// [`toyos_update::slots::HOLDER`] alone, and the consent port, which no row
/// receives and its server alone serves.
///
Expand All @@ -723,6 +740,14 @@ fn held_by_their_holders_alone(config: &SystemConfig) -> Result<(), String> {
if name != consent::SERVER && program.serves.iter().any(|s| s == consent::PORT) {
return Err(format!("`{name}` serves `{}`, which only `{}` may serve", consent::PORT, consent::SERVER));
}
for (held, holder) in HOLDINGS {
if name != holder && program.holds.iter().any(|h| h == held) {
return Err(format!("`{name}` holds `{held}`, which only `{holder}` may hold"));
}
}
if name != toyos_logstream::LOGKEEPER && program.syscap.iter().any(|s| s == "console") {
return Err(format!("`{name}` asks for the `console` syscap, which only `{}` may hold", toyos_logstream::LOGKEEPER));
}
if name != toyos_update::slots::HOLDER && program.slots {
return Err(format!("`{name}` asks for `slots`, which only `{}` may hold", toyos_update::slots::HOLDER));
}
Expand Down Expand Up @@ -889,6 +914,7 @@ fn render_manifest(config: &SystemConfig) -> Vec<u8> {
firmware: cfg.firmware.clone(),
syscap: cfg.syscap.clone(),
slots: cfg.slots,
holds: cfg.holds.clone(),
authorize: cfg.authorize.clone(),
service: cfg.service,
state: cfg.state,
Expand Down Expand Up @@ -988,11 +1014,13 @@ pub fn trust_roots() -> Vec<u8> {
roots.map(|cert| pem::encode_config(&pem::Pem::new("CERTIFICATE", cert.to_vec()), config)).collect::<String>().into_bytes()
}

#[allow(clippy::too_many_arguments)]
fn build_and_assemble(
root: &Path,
config: &SystemConfig,
env: &GuestEnv,
extra_files: &[(String, Vec<u8>)],
omits: &[String],
quiet: bool,
arch: Arch,
machines: crate::microcode::Machines,
Expand Down Expand Up @@ -1036,6 +1064,12 @@ fn build_and_assemble(
for (name, data) in extra_files {
root_files.push((name.clone(), data.clone()));
}
for omitted in omits {
let Some(at) = root_files.iter().position(|(name, _)| name == omitted) else {
panic!("root: '{omitted}' is to be left out, and the image has no such file");
};
root_files.remove(at);
}

let symlinks: Vec<(String, String)> = config.symlinks.iter()
.map(|(k, v)| (k.clone(), v.clone()))
Expand Down Expand Up @@ -1173,6 +1207,9 @@ pub struct Plan {
pub machines: crate::microcode::Machines,
/// The scale `cargo run --scale` starts the desktop at.
pub scale: Option<String>,
/// Files of the image's own ROOT a test boot is staged without, each by
/// its ROOT-relative path: a `/system` missing one.
pub root_omits: Vec<String>,
}

impl Plan {
Expand All @@ -1185,6 +1222,7 @@ impl Plan {
version: image::version_now(),
machines: crate::microcode::Machines::Qemu,
scale: None,
root_omits: Vec::new(),
}
}
}
Expand Down Expand Up @@ -1222,6 +1260,7 @@ pub fn plan_for(root: &Path, boot: &Boot, debug: bool, args: &[String]) -> Plan
crate::microcode::Machines::Qemu
},
scale: flags::CARGO_RUN.value(args, &flags::SCALE).map(String::from),
root_omits: Vec::new(),
}
}

Expand Down Expand Up @@ -2039,7 +2078,7 @@ fn shipped_parts(root: &Path, boot: &Boot, plan: &Plan) -> (Vec<u8>, Vec<u8>, Us
)
};

let userland = build_and_assemble(root, &config, &env, &[], false, arch, plan.machines);
let userland = build_and_assemble(root, &config, &env, &[], &plan.root_omits, false, arch, plan.machines);

let bl_bytes = fs::read(&bl_art).expect("Failed to read staged bootloader");
(kernel_bytes, bl_bytes, userland)
Expand Down Expand Up @@ -2142,6 +2181,7 @@ fn root_image_key(plan: &Plan, image_key: &str, extra_files: &[(String, Vec<u8>)
plan.config.hash(&mut h);
plan.arch.hash(&mut h);
plan.machines.hash(&mut h);
plan.root_omits.hash(&mut h);
image_key.hash(&mut h);
for (name, data) in extra_files {
name.hash(&mut h);
Expand Down Expand Up @@ -2258,7 +2298,7 @@ pub fn build_test_parts(
};

let userland = USERLAND.get_or_build(root_image_key, || {
build_and_assemble(root, &config, &env, extra_files, quiet, arch, plan.machines)
build_and_assemble(root, &config, &env, extra_files, &plan.root_omits, quiet, arch, plan.machines)
});

drop(building);
Expand Down Expand Up @@ -3194,13 +3234,32 @@ mod tests {
parsed.boot.start,
);
assert!(
parsed.programs.contains_key("logkeeper"),
"{config} starts `logkeeper` and has no `[programs.logkeeper]` row to say what it holds",
parsed.programs.get("logkeeper").is_some_and(|row| row.holds.iter().any(|h| h == toyos_logstream::ORIGINS)),
"{config} starts `logkeeper` and no `[programs.logkeeper]` row holds `{}`, so no program's ring reaches it",
toyos_logstream::ORIGINS,
);
// The UART carries nothing past the kernel's hand-over but what
// its driver puts on it. The diagnostic image is for a machine with
// no UART, and claims no device (`no_diag_program_claims_the_screen`).
let wire = toyos_logstream::WIRE_HOLDER;
assert!(
*config == "images/diag.toml"
|| parsed.boot.start.iter().any(|p| p == wire)
&& parsed.programs.get(wire).is_some_and(|row| {
row.devices.iter().any(|d| d == "uart")
&& row.holds.iter().any(|h| h == toyos_logstream::CONSOLE_INPUT)
}),
"{config} runs `logkeeper` and does not start `{wire}` holding the `uart` claim and the console's \
input, so its console UART says nothing from the kernel's hand-over to the machine's stop",
);
for (name, program) in &parsed.programs {
let holds = program.syscap.iter().any(|s| s == "logread");
if name == "logkeeper" {
assert!(holds, "{config}: `logkeeper` writes the file and must read the cursor");
assert!(
program.syscap.iter().any(|s| s == "console"),
"{config}: `logkeeper` feeds the console and must say what it spoke"
);
continue;
}
assert!(
Expand Down Expand Up @@ -3442,6 +3501,17 @@ mod tests {
assert!(held_by_their_holders_alone(&sshserver).is_err());
let apps: SystemConfig = toml::from_str("[apps]\nreceives = [\"swap\"]\n").unwrap();
assert!(held_by_their_holders_alone(&apps).is_err());
let origins: SystemConfig = toml::from_str("[programs.shell]\nholds = [\"log-origins\"]\n").unwrap();
assert!(held_by_their_holders_alone(&origins).is_err());
let input: SystemConfig = toml::from_str("[programs.shell]\nholds = [\"console-input\"]\n").unwrap();
assert!(held_by_their_holders_alone(&input).is_err());
let console: SystemConfig = toml::from_str("[programs.test-runner]\nsyscap = [\"logread\", \"console\"]\n").unwrap();
assert!(held_by_their_holders_alone(&console).is_err());
let held: SystemConfig = toml::from_str(
"[programs.logkeeper]\nholds = [\"log-origins\"]\n[programs.uart]\nholds = [\"console-input\"]\n",
)
.unwrap();
assert_eq!(held_by_their_holders_alone(&held), Ok(()));
let slots: SystemConfig = toml::from_str("[programs.shell]\nslots = true\n").unwrap();
assert!(held_by_their_holders_alone(&slots).is_err());
let booted: SystemConfig =
Expand Down
7 changes: 0 additions & 7 deletions build/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,6 @@ const REGISTERED: &[Verdict] = &[
/// Every negative control a model crate declares; `build/build.rs`'s
/// `every_model_control_is_run` holds this against the manifests.
pub(crate) const CONTROLS: &[Control] = &[
red(KERNEL_LOOM, "wake-fence-off", Some("log_wake"), &[
Fails("a_commit_and_an_arm_cannot_both_miss"),
]),
red(KERNEL_LOOM, "lock-acquire-off", Some("ticket_lock"), &[
Fails("try_lock_observes_the_previous_owners_writes"),
]),
Expand Down Expand Up @@ -590,10 +587,6 @@ pub(crate) const CONTROLS: &[Control] = &[
Fails("a_post_and_a_recheck_answer_a_poll_once"),
Fails("a_withdrawal_and_a_post_never_both_take_a_poll"),
]),
red(KERNEL_LOOM, "sleeplock-acquire-off", Some("sleep_lock"), &[
Fails("a_parking_contender_observes_the_holders_writes"),
Fails("two_holders_never_overlap"),
]),
red(KERNEL_LOOM, "device-irq-lossy", Some("device_irq"), &[
Fails("every_message_is_counted_once"),
]),
Expand Down
2 changes: 1 addition & 1 deletion build/kernelkeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub const DECLARED: &[Declared] = &[
file: "kernel/src/process.rs",
ty: "HashMap<Pid, ProcessEntry>",
keys: "the pid of the entry's `ProcessObject`, which only `toyos_proclife::Pids::take` issues, \
at a spawn's admission or a kernel thread's start",
at a spawn's admission",
},
];

Expand Down
32 changes: 22 additions & 10 deletions build/vmconsole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use std::process::Child;
use std::time::{Duration, Instant};

use toyos_logstream::death::{died, Died};
use toyos_logstream::Showing;
use toyos_abi::log::KERNEL_TAKES_THE_UART;
use toyos_logstream::{Showing, CARRIED_ELSEWHERE};
use toyos_virtio_serial::{CONSOLE_PORT, MAX_PORTS, PORT_ID};

/// The port's QEMU device id, which a test unplugs it by.
Expand Down Expand Up @@ -78,19 +79,16 @@ impl Painter {
}
}

/// What the kernel puts on the UART as the console's carrier takes the log
/// (`kernel/src/log/console.rs`): every UART line before it the console port
/// carries too, and the ones after it are the UART's alone.
pub const CARRIED_ELSEWHERE: &str = "console: the log is carried elsewhere from here";

/// Which of a virtio machine's UART lines are shown beside its console port:
/// the loader, the early boot, and the lines the port cannot carry — the
/// stop's, a fatal path's, and the whole log again once the console's carrier
/// is gone or has stalled.
///
/// **Its lines up to [`CARRIED_ELSEWHERE`] are the console port's too**, so
/// they are not shown, but for a kernel's death, which no other channel will
/// carry; every line after either is.
/// carry; every line after either is, and after the kernel taking the UART
/// back for the stop or a fatal path ([`KERNEL_TAKES_THE_UART`]), which may
/// come before its driver said the first.
#[derive(Default)]
pub struct Uart {
pending: Vec<u8>,
Expand All @@ -109,7 +107,7 @@ impl Uart {
self.live = true;
continue;
}
self.live |= died(text.trim_end()) == Some(Died::Kernel);
self.live |= died(text.trim_end()) == Some(Died::Kernel) || text.contains(KERNEL_TAKES_THE_UART);
if self.live {
shown.push(line);
}
Expand Down Expand Up @@ -481,15 +479,15 @@ mod tests {
assert!(shown == want, "the terminal was shown other bytes than the {length} painted");
}

const QUIET: &str = "[ 6.459 cpu0 kernel] console: the log is carried elsewhere from here; the UART takes the stop's and a fatal path's lines\n";
const QUIET: &str = "[ 6.459 logkeeper] console: the log is carried elsewhere from here; the UART takes the stop's and a fatal path's lines\n";

/// The UART's lines before the quiet line are the port's too and are kept
/// back; the quiet line itself says nothing the operator needs, and every
/// line after it is shown, however the bytes are cut.
#[test]
fn the_uart_is_shown_from_the_carriers_word_on() {
let early = "[ 0.001 cpu0 kernel] boot: early\n[ 4.000 supervisor] supervisor: started logkeeper\n";
let late = "[ 9.000 cpu0 kernel] console: the UART carries the log again\n[ 9.100 supervisor] supervisor: x ended\n";
let late = "[ 9.000 logkeeper] console: the UART carries the log again\n[ 9.100 supervisor] supervisor: x ended\n";
let stream = format!("{early}{QUIET}{late}");
for cut in [1, 7, stream.len()] {
let mut uart = Uart::default();
Expand All @@ -510,6 +508,20 @@ mod tests {
assert_eq!(String::from_utf8(shown).expect("UTF-8"), death);
}

/// **A stop that takes the UART from a driver still behind the log** is
/// shown from the kernel's word on: its driver never reached the quiet
/// line, and what it was still sending is the port's.
#[test]
fn the_kernels_taking_the_uart_is_shown_from() {
let behind = "[ 2.035 cpu0 kernel] pcidev: PCI 00:01.";
let stop = format!("\n{KERNEL_TAKES_THE_UART}\n[ 2.531 cpu0 kernel] mmio: x\n[ 2.551 cpu0 kernel] Shutting down.\n");
let mut uart = Uart::default();
let shown: Vec<u8> = uart.pass(format!("{behind}{stop}").as_bytes()).concat();
let shown = String::from_utf8(shown).expect("UTF-8");
assert!(shown.starts_with(KERNEL_TAKES_THE_UART), "{shown:?}");
assert!(shown.ends_with("Shutting down.\n"), "{shown:?}");
}

/// **The launch's merge**: the port's lines in order, then the UART's from
/// the carrier's word on, the port drained before each UART read; the
/// port's last unended line at its end; and what the UART says after the
Expand Down
15 changes: 11 additions & 4 deletions images/console.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ assets = ["assets"]
memory-floor-mib = 96

[boot]
start = ["logkeeper", "diskserver", "fileserver", "console", "acpiserver", "ps2server"]
start = ["logkeeper", "uart", "diskserver", "fileserver", "console", "acpiserver", "ps2server"]

# `/system/bin/console` owns the screen and provides the surface its shell and the
# shell's children inherit. No compositor here, so nothing receives one.
Expand All @@ -33,13 +33,21 @@ start = ["logkeeper", "diskserver", "fileserver", "console", "acpiserver", "ps2s
# Rights::WAIT` on a `SysCap` duplicate, and serves `log` to the console.
[programs.logkeeper]
service = true
syscap = ["logread"]
serves = ["log"]
syscap = ["logread", "console"]
serves = ["log", "log-wire"]
holds = ["log-origins"]

[programs.uart]
devices = ["uart"]
holds = ["console-input"]
receives = ["log-wire"]
restart = true

# The machine's ACPI fixed hardware, as `images/system.toml` serves it: `shutdown`
# powers this machine off with the sleep type this program reads out of the
# firmware's tables and hands the kernel, which refuses a power-off without
# one. The claim hands it the firmware's own access, as there.

[programs.acpiserver]
service = true
devices = ["acpi"]
Expand Down Expand Up @@ -70,7 +78,6 @@ receives = ["input"]
devices = ["isa:0060,0064:1,12"]
memory-floor-mib = 24


# `power` because `bin/shutdown` below is this binary, and on the machine this
# image exists for — no serial port, a prompt on the panel — there is no other
# way to turn it off: it asks the supervisor, which has `logkeeper` make the log whole first.
Expand Down
Loading