Rust's std on Pinnacle
Programs can be written against Rust's standard library, not only rt:
Pinnacle is an operating system Rust knows, aarch64-unknown-pinnacle
(target_os = "pinnacle"), with a std of its own. That std is Rust's,
from the nightly named in STD_TOOLCHAIN (xtask), with
library.patch applied: the platform layer for Pinnacle, as Rust's other
operating systems have theirs (Motor OS and Xous were the models).
| Part of std | On Pinnacle |
|---|---|
| Heap | rt's heap: size classes in arenas, large blocks as pages (map_memory) |
| Threads | thread, a stack from map_memory; join waits on a futex the thread sets as it ends |
Mutex, Condvar, RwLock, Once, parking | std's futex-based ones, on the kernel's futex_wait / futex_wake |
| Thread-locals | A table per thread, found through TPIDR_EL0, which the kernel keeps per thread |
Instant | The virtual counter, read by the program itself (no system call) |
SystemTime | The board's clock (clock), carried forward by that counter |
| Randomness | random |
| Files | A File is its path and a position: each read or write one read_at / write_at; folders listed whole (list); rename of a file is a copy, since the file system cannot move one yet; no links, permissions or times set by hand |
| The network | TcpStream, TcpListener, UdpSocket and name lookups on the kernel's sockets, which are channels; TCP and names over IPv4 and IPv6, UDP over IPv4; timeouts and non-blocking reads; an accepted connection's peer is not known (the unspecified address) |
| Processes | Command starts a program by name (built in, or an installed app), watched: its exit code arrives on a channel as it ends (spawn's SPAWN_WATCH); wait, try_wait, kill; its arguments, environment and standard streams travel in a start message on its handle 1 (argument STD_START), and piped streams are channels; no current directory |
Pinnacle's own (std::os::pinnacle) | The system calls (syscall, abi), random, the channel behind a socket or pipe (AsRawHandle), and wait: which of several channels has a message, without taking it (what poll is elsewhere), for event loops like mio's |
| Arguments, environment | What the starter gave in that message; the environment is kept in the program |
stdin, stdout, stderr | Channels from the starter, or the console (stdin then empty) |
cargo xtask builds it on the way (build_std): it copies the toolchain's
library source into target/std-src/library, applies the patch, writes the
abi crate in as sys/pal/pinnacle/abi.rs (one source of the system call
numbers), and builds the programs in std/ with -Zbuild-std against it.
They are linked where the kernel loads programs (programs/link.ld) and
built into the kernel beside the system programs. check/ is the
self-check's: "std ok" at every boot.
No C anywhere: no libc, and nothing in this std calls one.
Changing it, and a newer nightly
The patch is made from a git copy of the library: copy the toolchain's
lib/rustlib/src/rust/library somewhere, git init and commit it, apply
library.patch, change what you need, then git add -N . && git diff > library.patch. For a newer nightly, do the same from its library and bring
each hunk across; set STD_TOOLCHAIN to it.