Skip to main content

go_lib/runtime/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Goroutine scheduler internals.
3//!
4//! Ported from `src/runtime/` in <https://github.com/golang/go>.  Each submodule
5//! maps to the Go source file(s) shown below.
6//!
7//! ## v0.2.0 additions
8//!
9//! | New module / symbol | Purpose |
10//! |----|-----|
11//! | `stack` — `newstack`, `copystack`, `sigsegv_handler` | Dynamic goroutine stack growth (Step 3) |
12//! | `m` — `pthread_id`, `setup_sigaltstack` | Per-M thread ID + 64 KiB alternate signal stack (Step 4) |
13//! | `sched` — `async_preempt2`, `sigurg_handler` | Non-cooperative goroutine preemption via SIGURG (Step 4) |
14//! | `asm_amd64`/`asm_arm64` — `async_preempt_trampoline` | Save/restore all registers around the preemption yield (Step 4) |
15//! | `sysmon` — `pthread_kill(SIGURG)` in `preemptone` | Signal delivery for async preemption (Step 4) |
16//! | `netpoll` | epoll (Linux) / kqueue (macOS) / IOCP (Windows) I/O backend (Step 5) |
17//!
18//! ## v0.3.0 additions
19//!
20//! | New module / symbol | Purpose |
21//! |----|-----|
22//! | `g` — `casgstatus`, `castogscanstatus`, `casfrom_gscanstatus`, `readgstatus` | Centralised atomic G state-transition helpers (mirrors Go's `casgstatus`) |
23//! | `g` — `scan_stack` | GSCAN freeze/unfreeze scaffolding for a future GC stack scanner |
24//! | `syscall` — `entersyscall`/`exitsyscall` | G transitions to/from `GSYSCALL` state |
25//! | `stack` — `copystack` | G transitions through `GCOPYSTACK` during stack-copy |
26//! | `sched` — `preemptm` | G transitions through `GPREEMPTED` (Go 1.14+ async-preempt protocol) |
27//! | `park` — `goready` | Accepts `GPREEMPTED` as well as `GWAITING` when readying a G |
28//! | `asm_amd64`/`asm_arm64` — `systemstack`, `systemstack_call` | Runs a closure on the M's g0 stack via a naked RSP/SP switch |
29//!
30//! | This module   | Go source                                                   |
31//! |---------------|-------------------------------------------------------------|
32//! | `g`           | `runtime/runtime2.go`                                       |
33//! | `m`           | `runtime/runtime2.go`, `runtime/proc.go`                    |
34//! | `p`           | `runtime/runtime2.go`, `runtime/proc.go`                    |
35//! | `sched`       | `runtime/proc.go`, `runtime/preempt.go`                     |
36//! | `stack`       | `runtime/stack.go`, `runtime/signal_unix.go`                |
37//! | `netpoll`     | `runtime/netpoll_epoll.go`, `runtime/netpoll_kqueue.go`, `runtime/netpoll_windows.go` |
38//! | `park`        | `runtime/proc.go` (gopark / goready)                        |
39//! | `sudog`       | `runtime/runtime2.go`, `runtime/proc.go`                    |
40//! | `syscall`     | `runtime/proc.go` (entersyscall / exitsyscall)              |
41//! | `sysmon`      | `runtime/proc.go` (sysmon / retake)                         |
42//! | `time`        | `runtime/time.go`                                           |
43//! | `asm_amd64`   | `runtime/asm_amd64.s`, `runtime/preempt_amd64.s`           |
44//! | `asm_arm64`   | `runtime/asm_arm64.s`, `runtime/preempt_arm64.s`           |
45
46
47pub(crate) mod g;
48pub(crate) mod m;
49pub(crate) mod rawmutex;
50pub(crate) mod netpoll;
51pub(crate) mod p;
52pub(crate) mod park;
53pub(crate) mod sched;
54pub(crate) mod stack;
55pub(crate) mod sudog;
56pub(crate) mod syscall;
57pub(crate) mod sysmon;
58pub(crate) mod time;
59
60#[cfg(target_arch = "x86_64")]
61pub(crate) mod asm_amd64;
62#[cfg(target_arch = "aarch64")]
63pub(crate) mod asm_arm64;
64
65// Re-export the three context-switch primitives from the correct asm module
66// so the rest of the runtime uses `crate::runtime::{gogo, mcall, systemstack}`
67// without caring about the target architecture.
68#[cfg(target_arch = "aarch64")]
69pub(crate) use asm_arm64::{gogo, mcall, systemstack};