Skip to content

Glossary

AST (Asynchronous System Trap)

The per-thread polling-point mechanism XNU uses to deliver preemption, signals, and other asynchronous work without breaking into running code mid-instruction.

An AST — Asynchronous System Trap — is XNU's mechanism for queueing work that needs to happen to a thread at a safe point, rather than interrupting it arbitrarily.

Each thread has an AST mask stored alongside its kernel-state. When something wants the thread's attention — a signal arrived, the scheduler preemption timer fired, dtrace wants to record an event, BSD wants the thread to notice a deferred io completion — the requester sets the appropriate bit in the AST mask.

The bits get checked at every well-defined entry/exit point of the kernel: returning from a syscall, returning from an interrupt, on context switch, on return to userspace. Whatever is found pending runs then.

apple-oss-distributions/xnuosfmk/kern/ast.cThe AST dispatcher — every kernel exit goes through one of these.View on GitHub(line ) apple-oss-distributions/xnuosfmk/kern/ast.hThe AST bit definitions: AST_PREEMPT, AST_BSD, AST_DTRACE, …View on GitHub(line )

Why this design:

  • It's deterministic: you know exactly when delivery can happen (kernel exits), so locks held across delivery are known to be safe to drop.
  • It's cheap: a single mask check on the hot path, almost always zero, branch-predicted out.
  • It composes: multiple bits can be set and the dispatcher runs each handler in turn.

The signals article and the context-switch walkthrough both bottom out in AST — see signals in XNU and the context switch walkthrough.

See also: thread, Mach.