RAS(9)
πΈ RAS(9) β restastable atomic sequences, bestie β¨
okay so this is from the Kernel Developer's Manual (that's the 9 in RAS(9) β kernel peeps only, we're in the big leagues now π
), and it's literally all about these lil things called restartable atomic sequences. no cap, it's giving systems-programming main character energy π
β¨ NAME β¨
ras_lookup, ras_fork, ras_purgeall β restartable atomic sequences π
π¦ SYNOPSIS π¦
#include <sys/types.h>
#include <sys/proc.h>
#include <sys/ras.h>
void *
ras_lookup(struct proc *p, void *addr);
int
ras_fork(struct proc *p1, struct proc *p2);
int
ras_purgeall(struct proc *p);
π DESCRIPTION π
So bestie, picture this: restartable atomic sequences are these user code sequences that are guaranteed to execute without preemption. like, nobody's gonna interrupt your lil moment, periodt β
The way this is assured? By checking the set of restartable atomic sequences registered for a process during cpu_switchto(9). and if a process is found to have been preempted during a restartable sequence β plot twist π β then its execution is rolled back to the start of the sequence by resetting its program counter saved in its process control block (the PCB, iykyk).
The RAS functionality is provided by a combination of:
- the machine-independent routines discussed in this page, plus
- a machine-dependent component in
cpu_switchto(9).
A port that supports restartable atomic sequences will define __HAVE_RAS in <machine/types.h> so machine-independent code can conditionally provide RAS support π«Ά
β οΈ okay so here's a complicated side-effect y'all need to know about: restartable atomic sequences interact with the machine-dependent ptrace(2) support. Specifically, single-step traps and/or the emulation of single-stepping must carefully consider the effect on restartable atomic sequences. A general solution is to ignore these traps or disable them within restartable atomic sequences. lowkey a big deal π
π₯ FUNCTIONS π₯
The functions which operate on restartable atomic sequences are:
ras_lookup(p, addr)β this function searches the registered restartable atomic sequences for process p which contain the user address addr. If the address addr is found within a RAS, then the restart address of the RAS is returned, otherwise-1is returned. so like, found it β here's where you restart, didn't find it β-1, simple as π«Άras_fork(p1, p2)β this function is used to copy all registered restartable atomic sequences for process p1 to process p2. It's primarily called fromfork1(9)when the sequences are inherited from the parent by the child. passing the RAS lore down to the next generation, iconic πras_purgeall(p)β this function is used to remove all registered restartable atomic sequences for process p. It's primarily used to remove all registered restartable atomic sequences for a process duringexec(3)and byrasctl(2). it's a whole cleanse, we love a fresh start β¨
π§ CODE REFERENCES π§
The RAS framework itself is implemented within the file sys/kern/kern_ras.c. Data structures and function prototypes for the framework are located in <sys/ras.h>. Machine-dependent portions are implemented within cpu_switchto(9) in the machine-dependent file sys/arch/<arch>/<arch>/locore.S. go read the source, bestie, it's all there π
πΈ SEE ALSO πΈ
rasctl(2)cpu_switchto(9)fork1(9)
And also this absolute legend of a paper β Gregory McGarry, βAn Implementation of User-level Restartable Atomic Sequences on the NetBSD Operating Systemβ, Proceedings of the FREENIX Track: 2003 USENIX Annual Technical Conference, USENIX Association, http://www.usenix.org/publications/library/proceedings/usenix03/tech/freenix03/full_papers/mcgarry/mcgarry.pdf, 311-322, June 9-14, 2003 π
β HISTORY β
The RAS functionality first appeared in NetBSD 2.0. she's been serving looks since day one π
and that's the whole page, bestie β this one shipped on Debian back on April 17, 2010, so like, vintage but still ate π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2002 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms