garage44.eu/jeroen/pinnacle

logclone: git clone https://garage44.eu/jeroen/pinnacle.git

.. /std

README.md

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 stdOn Pinnacle
Heaprt's heap: size classes in arenas, large blocks as pages (map_memory)
Threadsthread, a stack from map_memory; join waits on a futex the thread sets as it ends
Mutex, Condvar, RwLock, Once, parkingstd's futex-based ones, on the kernel's futex_wait / futex_wake
Thread-localsA table per thread, found through TPIDR_EL0, which the kernel keeps per thread
InstantThe virtual counter, read by the program itself (no system call)
SystemTimeThe board's clock (clock), carried forward by that counter
Randomnessrandom
FilesA 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 networkTcpStream, 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)
ProcessesCommand 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, environmentWhat the starter gave in that message; the environment is kept in the program
stdin, stdout, stderrChannels 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.