diff --git a/apps/nesinit/src/session.rs b/apps/nesinit/src/session.rs index fadc9a43..2958350d 100644 --- a/apps/nesinit/src/session.rs +++ b/apps/nesinit/src/session.rs @@ -266,7 +266,12 @@ where } booted = true; - // The overlays, then the shares, then the services. + // The images, then the overlays, then the shares, then the + // services. + // + // **An image is the base the rest may sit on**, so it goes + // first, and its failure is reported the way an overlay's is: + // it is a filesystem this end mounts itself. // // **Overlays first, and one `Mounted` between them.** An // overlay is a filesystem this end mounts itself, so a share @@ -275,7 +280,10 @@ where // content where the descriptor said" and there is one answer to // that -- sending it twice made the host read the second as a // reply to something it had not asked. - if let Err(failure) = workload.mount_overlays(&descriptor.overlays) { + let stacked = workload + .mount_images(&descriptor.images) + .and_then(|()| workload.mount_overlays(&descriptor.overlays)); + if let Err(failure) = stacked { // Said before it is returned. `Refused` ends the session // either way; without the message the host sees a box that // stopped and has to guess between an overlay, a share and a @@ -517,6 +525,7 @@ mod tests { ro: false, }], overlays: Vec::new(), + images: Vec::new(), video: Default::default(), } } @@ -1173,6 +1182,66 @@ mod tests { assert!(workload.started.is_empty()); } + /// The compatibility layer is the base the rest of a box is built on, so it + /// is mounted before anything that could sit inside it, and a box whose + /// image will not mount is refused rather than carried on with. + #[tokio::test] + async fn images_are_mounted_before_overlays_and_shares() { + let (guest, host) = tokio::io::duplex(4096); + let mut caller = Caller::new(host); + let session = spawn(guest, Given::new(Double::exits_when_stopped(Exit::code(0)))); + + let mut given = descriptor(); + given.images = vec![nesprotocol::lifecycle::Image { + device: "/dev/vdd".into(), + at: "/nestri/compat".into(), + }]; + + caller.expect_ready().await; + caller + .say(&HostToGuest::Boot { + descriptor: Box::new(given.clone()), + }) + .await; + caller.expect_booted().await; + caller.say(&HostToGuest::Shutdown).await; + + let (_, workload, _) = session.await.unwrap(); + assert_eq!(workload.images, vec![given.images]); + assert_eq!(workload.order, vec!["images", "overlays", "shares"]); + } + + #[tokio::test] + async fn an_image_that_will_not_mount_refuses_the_box_before_anything_else_is_mounted() { + let (guest, host) = tokio::io::duplex(4096); + let mut caller = Caller::new(host); + let mut workload = Double::exits_at_once(Exit::code(0)); + workload.image_failure = Some(Failure::new("/nestri/compat: the image /dev/vdd: EINVAL")); + let session = spawn(guest, Given::new(workload)); + + caller.expect_ready().await; + caller + .say(&HostToGuest::Boot { + descriptor: Box::new(descriptor()), + }) + .await; + + assert_eq!( + caller.expect().await, + GuestToHost::MountFailed { + reason: "/nestri/compat: the image /dev/vdd: EINVAL".into() + }, + ); + let (outcome, workload, services) = session.await.unwrap(); + assert!(matches!(outcome, Outcome::Refused(_))); + assert_eq!( + workload.order, + vec!["images"], + "something was mounted after the failure" + ); + assert_eq!(services.brought_up, 0); + } + /// A box whose own services will not come up cannot be launched into, so it /// is refused — and said with its own message, because a share that did not /// appear and a box that could not be made want different things looked at. diff --git a/apps/nesinit/src/workload.rs b/apps/nesinit/src/workload.rs index a32845b4..08be10ca 100644 --- a/apps/nesinit/src/workload.rs +++ b/apps/nesinit/src/workload.rs @@ -11,7 +11,7 @@ use std::future::Future; use std::io; use std::pin::Pin; -use nesprotocol::lifecycle::{Exec, Exit, Mount, Overlay}; +use nesprotocol::lifecycle::{Exec, Exit, Image, Mount, Overlay}; use std::os::unix::process::CommandExt; @@ -41,6 +41,12 @@ pub trait Workload { /// Make the shares the descriptor names, where it says to put them. fn mount(&mut self, mounts: &[Mount]) -> Result<(), Failure>; + /// Mount each read-only image the descriptor names, where it says. + /// + /// Before the overlays and the shares: an image is the base other mount + /// points may be inside of, and nothing mounted yet can be under it. + fn mount_images(&mut self, images: &[Image]) -> Result<(), Failure>; + /// Stack each overlay the descriptor names: its build image, its writable /// layer, and the two together where it says. fn mount_overlays(&mut self, overlays: &[Overlay]) -> Result<(), Failure>; @@ -133,6 +139,13 @@ impl Workload for Process { Ok(()) } + fn mount_images(&mut self, images: &[Image]) -> Result<(), Failure> { + for image in images { + mount_image(image)?; + } + Ok(()) + } + fn mount_overlays(&mut self, overlays: &[Overlay]) -> Result<(), Failure> { for overlay in overlays { mount_overlay(overlay)?; @@ -392,6 +405,55 @@ fn mount_overlay(overlay: &Overlay) -> Result<(), Failure> { Ok(()) } +/// What mounting a read-only image is given, worked out before anything is +/// attempted, for the reason an overlay's plan is: the part worth asserting is +/// the part that needs no privilege. +/// +/// `nosuid` and `nodev` like every other layer, and not `noexec`: what is in an +/// image is run from it. +#[derive(Debug)] +struct ImagePlan { + device: CString, + at: CString, + flags: libc::c_ulong, +} + +impl ImagePlan { + fn new(image: &Image) -> Result { + // Nothing at all is mounted over the root, and a relative mount point + // would land wherever the init's working directory happens to be. + let at = std::path::Path::new(&image.at); + if !at.is_absolute() || at.parent().is_none() { + return Err(Failure::new(format!( + "an image cannot be mounted at {:?}: the mount point has to be an \ + absolute path below the root", + image.at + ))); + } + Ok(Self { + device: c_string(&image.device, "the image device")?, + at: c_string(&image.at, "the image mount point")?, + flags: libc::MS_NOSUID | libc::MS_NODEV | libc::MS_RDONLY, + }) + } + + /// The mount point and the device, in the operating system's words. + fn failed(&self, error: io::Error) -> Failure { + Failure::new(format!( + "{}: the image {}: {error}", + self.at.to_string_lossy(), + self.device.to_string_lossy() + )) + } +} + +/// Mount one read-only image where the descriptor says. +fn mount_image(image: &Image) -> Result<(), Failure> { + let plan = ImagePlan::new(image)?; + mount_one(&plan.device, &plan.at, c"erofs", plan.flags, None) + .map_err(|error| plan.failed(error)) +} + /// Mount one filesystem, creating its mount point first. fn mount_one( source: &std::ffi::CStr, @@ -710,6 +772,51 @@ mod tests { assert_eq!(flags & libc::MS_RDONLY, 0); } + fn image(at: &str) -> Image { + Image { + device: "/dev/vdd".into(), + at: at.into(), + } + } + + /// Read-only, guarded like every other layer, and runnable: what is in it + /// is a program. + #[test] + fn an_image_is_mounted_read_only_without_devices_or_setuid_but_can_execute() { + let plan = ImagePlan::new(&image("/nestri/compat")).unwrap(); + assert_eq!(plan.device.to_str().unwrap(), "/dev/vdd"); + assert_eq!(plan.at.to_str().unwrap(), "/nestri/compat"); + assert_eq!(plan.flags & libc::MS_RDONLY, libc::MS_RDONLY); + assert_eq!(plan.flags & libc::MS_NOSUID, libc::MS_NOSUID); + assert_eq!(plan.flags & libc::MS_NODEV, libc::MS_NODEV); + assert_eq!(plan.flags & libc::MS_NOEXEC, 0); + } + + #[test] + fn an_image_that_cannot_be_placed_is_refused_before_anything_mounts() { + for at in ["/", "nestri/compat", "", "/nestri/co\0mpat"] { + assert!(ImagePlan::new(&image(at)).is_err(), "{at:?} was accepted"); + } + let nul_device = Image { + device: "/dev/v\0dd".into(), + at: "/nestri/compat".into(), + }; + assert!(ImagePlan::new(&nul_device).is_err()); + } + + #[test] + fn a_failed_image_names_the_mount_point_and_the_device() { + let plan = ImagePlan::new(&image("/nestri/compat")).unwrap(); + let failure = plan.failed(io::Error::from_raw_os_error(libc::EINVAL)); + assert!( + failure + .reason + .starts_with("/nestri/compat: the image /dev/vdd: "), + "{}", + failure.reason + ); + } + fn overlay(at: &str) -> Overlay { Overlay { lower: "/dev/vdb".into(), @@ -840,9 +947,13 @@ pub mod double { pub struct Double { pub mounted: Vec>, pub overlays: Vec>, + pub images: Vec>, + /// Which kind of mount was asked for, in the order it was asked. + pub order: Vec<&'static str>, pub started: Vec, pub stops: usize, pub mount_failure: Option, + pub image_failure: Option, pub start_failure: Option, exit: Exit, on_stop: Option>, @@ -864,9 +975,12 @@ pub mod double { Self { mounted: Vec::new(), overlays: Vec::new(), + images: Vec::new(), + order: Vec::new(), started: Vec::new(), stops: 0, mount_failure: None, + image_failure: None, start_failure: None, exit, on_stop: None, @@ -877,6 +991,7 @@ pub mod double { impl Workload for Double { fn mount(&mut self, mounts: &[Mount]) -> Result<(), Failure> { + self.order.push("shares"); self.mounted.push(mounts.to_vec()); match &self.mount_failure { Some(failure) => Err(failure.clone()), @@ -884,7 +999,17 @@ pub mod double { } } + fn mount_images(&mut self, images: &[Image]) -> Result<(), Failure> { + self.order.push("images"); + self.images.push(images.to_vec()); + match &self.image_failure { + Some(failure) => Err(failure.clone()), + None => Ok(()), + } + } + fn mount_overlays(&mut self, overlays: &[Overlay]) -> Result<(), Failure> { + self.order.push("overlays"); self.overlays.push(overlays.to_vec()); match &self.mount_failure { Some(failure) => Err(failure.clone()), diff --git a/build/Containerfile b/build/Containerfile index 9f316440..d7ed697b 100644 --- a/build/Containerfile +++ b/build/Containerfile @@ -13,12 +13,15 @@ # this image is plain Arch rather than a distribution chosen for its init. # ref(d-0064) # -# Proton is here, and it is not a closed component: it is proton-ge built -# from source wow64-only, which is what removes the need for a whole 32-bit -# host stack. Valve's steamclient.so is a different thing and is NOT -# here — that one is closed, and nestri/CLAUDE.md is explicit that nothing -# closed enters this repo. Whatever layers it on top of runtime_prod is a -# closed build outside this repo — see build/README.md. +# Proton is NOT in this image any more. It reaches a box as a read-only +# image the host attaches, so a different one can be tried without +# rebuilding this. What stays here is everything Proton needs *around* it — +# its interpreter and its libraries — and the `compat_check` stage below +# proves a given Proton still has them. Valve's steamclient.so is a +# different thing and is NOT here either — that one is closed, and +# nestri/CLAUDE.md is explicit that nothing closed enters this repo. +# Whatever layers it on top of runtime_prod is a closed build outside this +# repo — see build/README.md. # # Build from the repo root, not from build/: # docker build -f build/Containerfile --target runtime_prod -t nestri-guest . @@ -165,22 +168,27 @@ RUN --mount=type=cache,target=/root/.cargo/registry \ # ─────────────────────────────────────────────────────────── -# Proton — pulled, not built here +# Proton — pulled to be checked, not shipped # # Building it takes hours and it changes only when its own tag moves, so it # has a cadence of its own and an image of its own. The published image is # `FROM scratch` over the tree, so its root *is* the tree and there is nothing # in it to run — only something to copy from. # -# Built wow64-only, which is the whole reason it is a build of ours rather -# than a released one. wow64 runs 32-bit Windows code inside a 64-bit unix -# process, so a box needs no lib32 anything: no 32-bit glibc, no second Mesa -# for i686, and — the one that matters most here — no -# second capture layer, because the game is a 64-bit process and loads the -# 64-bit Vulkan loader the existing layer already sits in. The released builds -# carry a 32-bit unix side, which is exactly why they need lib32-*. +# It is copied into the `compat_check` stage and nowhere else. A box gets its +# Proton from the host, as an image attached at run time; this is only the +# Proton this rootfs is verified against, and any other can be checked the same +# way by overriding it. # -# Override to build it yourself; the tag is a version and moves deliberately. +# Built wow64-only, which is the whole reason it is a build of ours rather +# than a released one at the time. wow64 runs 32-bit Windows code inside a +# 64-bit unix process, so a box needs no lib32 anything: no 32-bit glibc, no +# second Mesa for i686, and — the one that matters most here — no second +# capture layer, because the game is a 64-bit process and loads the 64-bit +# Vulkan loader the existing layer already sits in. Upstream Wine defaults to +# it from Proton 11, so a released build needs no more than ours does. +# +# Override to check another; the tag is a version and moves deliberately. # ─────────────────────────────────────────────────────────── FROM ${PROTON_IMAGE} AS proton @@ -375,15 +383,9 @@ RUN cat /tmp/mesa.manifest /tmp/nestri.manifest > /tmp/.strip-manifest && \ COPY --from=mesa-build /artifacts/mesa / COPY --from=nestri-build /artifacts/nestri / -# The Proton tree, whose image root is the tree, so this lands it at -# /usr/share/steam/compatibilitytools.d/proton-ge. -# -# Deliberately not in the strip manifest above: that list is our own build -# output, and the two stripping decisions are not the same one. Proton ships -# a Windows toolchain's worth of PE binaries that `strip` has no business -# touching, and its unix side is already built the way its own packaging -# builds it. -COPY --from=proton / / +# **No Proton here.** It is attached to a box at run time, mounted at +# /nestri/compat, so this image has no Proton path for a launch to fall back to +# and a box started without one fails saying where it looked. RUN ldconfig @@ -456,8 +458,9 @@ RUN for intruder in /usr/lib/systemd/systemd /sbin/openrc-init /usr/bin/openrc-i # JACK output, libdecor's GTK backend — and every one of those was already # unresolved before this stage existed. A check that reports a dozen things # nobody intends to load is a check the next person deletes. This list is what -# the image is *for*: the components, the services init starts, the chain -# between a workload and the GPU, and Wine's own core. +# the image is *for*: the components, the services init starts, and the chain +# between a workload and the GPU. Wine's own core is checked by the +# `compat_check` stage, against the Proton it is actually going to run. # # **Wine was added after it was missed**, and then narrowed twice, which is # worth recording so nobody widens it again. @@ -503,9 +506,7 @@ RUN failed=0; \ /usr/bin/dbus-daemon /usr/bin/pipewire \ /usr/bin/wireplumber /usr/bin/ip \ /usr/lib/libgallium-*.so /usr/lib/libEGL_mesa.so.0 \ - /usr/lib/libvulkan_*.so /usr/lib/dri/*.so /usr/lib/gbm/*.so \ - /usr/share/steam/compatibilitytools.d/proton-cachyos/files/bin/* \ - /usr/share/steam/compatibilitytools.d/proton-cachyos/files/lib*/wine/*-unix/ntdll.so; do \ + /usr/lib/libvulkan_*.so /usr/lib/dri/*.so /usr/lib/gbm/*.so; do \ [ -e "$f" ] || continue; \ libs="$(LD_LIBRARY_PATH="${f%/*}" ldd "$f" 2>/dev/null | awk '/not found/ { print $1 }')"; \ [ -n "$libs" ] || continue; \ @@ -524,32 +525,88 @@ RUN failed=0; \ RUN for required in /usr/bin/nesinit /usr/bin/nescope /usr/bin/neshub /usr/bin/neswire \ /usr/bin/nesgamepad /usr/lib/libSDL2-2.0.so.0 \ /usr/bin/dbus-daemon /usr/bin/pipewire \ - /usr/bin/wireplumber /usr/bin/ip /usr/bin/python3 \ - /usr/share/steam/compatibilitytools.d/proton-cachyos/proton; do \ + /usr/bin/wireplumber /usr/bin/ip /usr/bin/python3; do \ test -x "$required" || { echo "the image is missing $required" >&2; exit 1; }; \ done +# ─────────────────────────────────────────────────────────── +# compat_check — does this rootfs still carry what a Proton needs? +# +# Proton is not part of the image, so what used to be checked by having it +# there is checked here, against the Proton named by PROTON_IMAGE: that every +# library its programs and Wine's core link is present, and that its entry +# point has an interpreter. A rootfs that loses one of them otherwise finds out +# as a game that starts and never draws. +# +# Not a stage anything runs. The leaf stages copy a one-line marker out of it +# so that a build cannot skip it as unused, which is also what records which +# Proton the image was verified against. +# +# Check any other Proton the same way: +# make PROTON_IMAGE= build +# where is an image whose root is a Proton tree, or a tree under +# `usr/share/steam/compatibilitytools.d//`. +# ─────────────────────────────────────────────────────────── +FROM runtime AS compat_check +ARG PROTON_IMAGE +COPY --from=proton / /opt/compat-check/ + +# The Proton root is the directory that holds `proton`, wherever the image put +# it: a tree directly, or under compatibilitytools.d as the published one does. +# Exactly one is expected, and anything else is refused -- picking the first of +# several is how the wrong Proton gets verified and the right one never is. +RUN set -eu; \ + found="$(find /opt/compat-check -maxdepth 6 -name proton -type f)"; \ + [ "$(printf '%s\n' "$found" | grep -c .)" = 1 ] \ + || { echo "expected one Proton in ${PROTON_IMAGE}, found:" >&2; echo "$found" >&2; exit 1; }; \ + dirname "$found" > /tmp/proton-root; \ + root="$(cat /tmp/proton-root)"; \ + test -x "$root/proton" || { echo "$root/proton is not executable" >&2; exit 1; }; \ + test -d "$root/files" || { echo "$root has no files/ directory" >&2; exit 1; } + +# The libraries, by the method the runtime stage documents: the programs in +# `bin/`, which resolve normally, and `ntdll.so`, which is Wine's first load and +# the one that linked the library once found missing. Each file is resolved with +# its own directory on the library path, because Wine's unix objects link each +# other by soname. +RUN root="$(cat /tmp/proton-root)"; failed=0; : > /tmp/missing-libs; \ + for f in "$root"/files/bin/* "$root"/files/lib*/wine/*-unix/ntdll.so; do \ + [ -e "$f" ] || continue; \ + libs="$(LD_LIBRARY_PATH="${f%/*}" ldd "$f" 2>/dev/null | awk '/not found/ { print $1 }')"; \ + [ -n "$libs" ] || continue; \ + failed=1; \ + printf ' %s\n' "$f" >&2; \ + printf ' %s\n' $libs >&2; \ + printf '%s\n' $libs >> /tmp/missing-libs; \ + done; \ + if [ "$failed" != 0 ]; then \ + echo "" >&2; \ + echo " every library above, once each -- this is the list to install:" >&2; \ + sort -u /tmp/missing-libs | sed 's/^/ /' >&2; \ + exit 1; \ + fi + # An entry point that is executable is not an entry point that runs. # -# The check above passed on an image whose compatibility tool was a Python -# script with no interpreter behind it: `test -x` says the file may be -# executed, and the kernel then fails to find what the shebang names. A session -# got as far as launching a game and ended with -# `env: 'python3': No such file or directory`. +# A check that only asked `test -x` passed on an image whose compatibility tool +# was a Python script with no interpreter behind it: the kernel then fails to +# find what the shebang names, and a session got as far as launching a game and +# ended with `env: 'python3': No such file or directory`. # -# So every script this image promises resolves its own interpreter. `env` is -# unwrapped where it is used, because a shebang of `#!/usr/bin/env python3` -# names `env` and the thing that is actually missing is the argument. -RUN for script in /usr/share/steam/compatibilitytools.d/proton-cachyos/proton; do \ - head -c 2 "$script" | grep -q '#!' || continue; \ - shebang="$(head -1 "$script" | sed 's/^#!//')"; \ - interpreter="${shebang%% *}"; \ - case "$interpreter" in \ - */env) argument="${shebang#* }"; interpreter="$(command -v "${argument%% *}" || true)";; \ - esac; \ - test -n "$interpreter" && test -x "$interpreter" \ - || { echo "$script needs an interpreter the image does not have: $shebang" >&2; exit 1; }; \ - done +# So the entry point resolves its own interpreter. `env` is unwrapped where it +# is used, because a shebang of `#!/usr/bin/env python3` names `env` and the +# thing that is actually missing is the argument. +RUN script="$(cat /tmp/proton-root)/proton"; \ + head -c 2 "$script" | grep -q '#!' || exit 0; \ + shebang="$(head -1 "$script" | sed 's/^#!//')"; \ + interpreter="${shebang%% *}"; \ + case "$interpreter" in \ + */env) argument="${shebang#* }"; interpreter="$(command -v "${argument%% *}" || true)";; \ + esac; \ + test -n "$interpreter" && test -x "$interpreter" \ + || { echo "$script needs an interpreter the image does not have: $shebang" >&2; exit 1; } + +RUN echo "${PROTON_IMAGE}" > /compat-verified # ─────────────────────────────────────────────────────────── @@ -557,6 +614,10 @@ RUN for script in /usr/share/steam/compatibilitytools.d/proton-cachyos/proton; d # ─────────────────────────────────────────────────────────── FROM runtime AS runtime_prod +# Which Proton this image was verified against, and the reason the check stage +# is built at all. See `compat_check`. +COPY --from=compat_check /compat-verified /usr/share/nestri/compat-verified + # No console is offered by either flavour: `nesinit` spawns no getty, because # the way into a guest that will not boot is `init=/bin/bash` on the kernel # command line, which needs nothing from the image but a shell. So the locked @@ -581,6 +642,8 @@ RUN echo "NESTRI_STAGE=runtime_prod" >> /etc/os-release # ─────────────────────────────────────────────────────────── FROM runtime AS runtime_debug +COPY --from=compat_check /compat-verified /usr/share/nestri/compat-verified + # `-Sy` and not `-Syu`: a full upgrade here can pull a package back in as # somebody's dependency, and the one that matters is systemd. The check below # catches it either way, but a debug image that fails to build is worse than diff --git a/build/README.md b/build/README.md index 955a6058..bf2f583e 100644 --- a/build/README.md +++ b/build/README.md @@ -60,28 +60,31 @@ source, not a dependency, not a directory that 'looked convenient'."* That one is closed, so whatever layers it on top is a build outside this repo — not something this repo names, links to, or depends on. -**Proton is here, and this paragraph used to say it was not.** The old wording -put Proton and `steamclient.so` together and called both closed, which is -wrong about Proton: it is compiled from source, which is not a thing you can -do with closed software. Keeping it out cost a box the only way it has to run -a Windows title, for a rule that did not apply to it. +**Proton is not in the image.** It used to be, at a cost of about 1.4 GB, and +it is attached to a box at run time now: a read-only EROFS image of a Proton +tree, mounted at `/nestri/compat`, chosen per session by whatever starts the +box. That is what makes trying another Proton (GE's releases, a newer build of +ours) a matter of attaching a different image rather than rebuilding this one. -What it is: **proton-ge built wow64-only**, pulled by tag as a -published image rather than rebuilt here, because it takes hours and moves -only when its own tag does. `PROTON_IMAGE` overrides the tag, and it has to be -declared before the first `FROM`: an `ARG` a `FROM` expands is global or it -is nothing, and getting that wrong fails with `no FROM statement found`, which -says nothing about the actual mistake. wow64 is the whole reason it is a build -of ours and not a released one. It runs 32-bit Windows code inside a 64-bit -unix process, so a box needs no lib32 glibc, no second Mesa for i686, and no -second capture layer for 32-bit titles to be captured. The released builds -carry a 32-bit unix side, which is exactly why they need `lib32-*`. +What stays here is everything Proton needs around itself: the interpreter for its +entry point and every library its programs and Wine's core link. The +`compat_check` stage in the `Containerfile` is what keeps that true. It copies a +Proton tree in (the published one by default) and fails the build when a library +is missing or the entry point has no interpreter, then leaves a one-line marker +in the image naming the Proton it was checked against +(`/usr/share/nestri/compat-verified`). Check another one with +`make PROTON_IMAGE= build`. The check cannot be skipped as an unused +stage, because the leaf stages copy that marker out of it. -It costs about 1.4 GB of image, and it is the one thing in here that is -payload-shaped: a compatibility layer for Windows games in an image that is -otherwise indifferent to what it runs. The guest components stay indifferent -regardless — none of them branches on it, and the init does not know it -exists. What names it is the command a caller sends. +The image holds no Proton path, so a box started without one fails saying where +it looked instead of quietly using something stale. + +What the published Proton is: **proton-ge built wow64-only**, as a published +image rather than rebuilt here, because it takes hours and moves only when its +own tag does. wow64 runs 32-bit Windows code inside a 64-bit unix process, so a +box needs no lib32 glibc, no second Mesa for i686, and no second capture layer +for 32-bit titles to be captured. Upstream Wine defaults to it from Proton 11, +so a released build needs no more than ours does. `runtime_prod` from this Containerfile — tagged `ghcr.io/nestrilabs/nestri/base:latest` — is a complete, bootable guest image, @@ -191,9 +194,9 @@ a package list says that; the check below is what said it. ## Proton has its own cadence, and its own Containerfile -`make build` **pulls** Proton by tag; it does not build it. Building it takes -hours and it changes only when its tag moves, so it is one image published -once and copied into every guest image after that. `make proton-image` is +`make build` **pulls** Proton by tag to check it against; it does not build it +and does not ship it. Building it takes hours and it changes only when its tag +moves, so it is one image published once. `make proton-image` is that build, and it lives here so the published tag stays reproducible from this tree rather than from somebody's laptop. diff --git a/crates/nesprotocol/src/lifecycle.rs b/crates/nesprotocol/src/lifecycle.rs index b69f707f..bc974ec1 100644 --- a/crates/nesprotocol/src/lifecycle.rs +++ b/crates/nesprotocol/src/lifecycle.rs @@ -62,7 +62,14 @@ pub const CONTROL_PORT: u32 = 7000; /// /// Version 4 replaced the descriptor's `drives` with `overlays`: a build is a /// read-only image now, and a box writes into a layer of its own over it. -pub const CONTROL_VERSION: u32 = 4; +/// +/// Version 5 added `images`: a read-only image mounted on its own, which is how +/// the compatibility layer reaches a box now that the guest image no longer +/// carries one. It is a bump although it is only a field, because the +/// descriptor refuses fields it does not know and a guest image without that +/// layer is useless to a host that does not send one: the mismatch should be +/// named at the handshake and not found as a launch that cannot start. +pub const CONTROL_VERSION: u32 = 5; /// The command to run, and who runs it. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -130,6 +137,24 @@ pub struct Overlay { pub at: String, } +/// A read-only filesystem image, mounted where the descriptor says. +/// +/// What reaches a box this way is something every box on a host shares and none +/// of them writes: the compatibility layer a Windows title runs under. Unlike +/// an [`Overlay`] there is no writable layer over it, so anything that writes +/// into its own directory fails, and that is the point -- two boxes cannot +/// disagree about what is in it. +/// +/// Mounted as EROFS, with the same guards every layer has (`nosuid`, `nodev`) +/// and without `noexec`, because the programs in it are what gets run. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Image { + /// The block device, as the guest names it. + pub device: String, + /// Where it lands inside the guest. + pub at: String, +} + /// Names one launch, for as long as anything has something to say about it. /// /// Minted by the caller and only ever echoed by the guest. A guest that @@ -196,6 +221,10 @@ pub struct BootDescriptor { pub mounts: Vec, #[serde(default)] pub overlays: Vec, + /// Read-only images with nothing over them. Left out of the wire form when + /// there are none, so a descriptor that needs none reads the same as before. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub images: Vec, /// What the box may spend on video. /// /// Here rather than on a launch because its consumer is `neshub`, which is @@ -441,6 +470,7 @@ mod tests { ro: true, }], overlays: Vec::new(), + images: Vec::new(), video: VideoLimits::default(), } } @@ -704,6 +734,7 @@ mod video_limits_tests { let d = BootDescriptor { mounts: Vec::new(), overlays: Vec::new(), + images: Vec::new(), video: VideoLimits::default(), }; let json = serde_json::to_string(&d).unwrap(); @@ -715,6 +746,7 @@ mod video_limits_tests { let d = BootDescriptor { mounts: Vec::new(), overlays: Vec::new(), + images: Vec::new(), video: VideoLimits { bitrate_kbps: Some(8_000), }, @@ -745,3 +777,33 @@ mod video_limits_tests { assert!(r.is_err(), "an unknown video limit must not be ignored"); } } + +#[cfg(test)] +mod image_tests { + use super::*; + + #[test] + fn a_descriptor_with_no_images_reads_and_writes_as_it_always_did() { + let d: BootDescriptor = serde_json::from_str(r#"{"mounts":[],"overlays":[]}"#).unwrap(); + assert!(d.images.is_empty()); + let json = serde_json::to_string(&d).unwrap(); + assert!(!json.contains("images"), "{json}"); + } + + #[test] + fn an_image_survives_the_round_trip() { + let d = BootDescriptor { + mounts: Vec::new(), + overlays: Vec::new(), + images: vec![Image { + device: "/dev/vdd".into(), + at: "/nestri/compat".into(), + }], + video: VideoLimits::default(), + }; + let json = serde_json::to_string(&d).unwrap(); + assert!(json.contains(r#""images":[{"device":"/dev/vdd","at":"/nestri/compat"}]"#)); + let back: BootDescriptor = serde_json::from_str(&json).unwrap(); + assert_eq!(back, d); + } +}