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//! ## v2.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) fd-readiness backend (Step 5) |
17//!
18//! | This module   | Go source                                                   |
19//! |---------------|-------------------------------------------------------------|
20//! | `g`           | `runtime/runtime2.go`                                       |
21//! | `m`           | `runtime/runtime2.go`, `runtime/proc.go`                    |
22//! | `p`           | `runtime/runtime2.go`, `runtime/proc.go`                    |
23//! | `sched`       | `runtime/proc.go`, `runtime/preempt.go`                     |
24//! | `stack`       | `runtime/stack.go`, `runtime/signal_unix.go`                |
25//! | `netpoll`     | `runtime/netpoll_epoll.go`, `runtime/netpoll_kqueue.go`     |
26//! | `park`        | `runtime/proc.go` (gopark / goready)                        |
27//! | `sudog`       | `runtime/runtime2.go`, `runtime/proc.go`                    |
28//! | `syscall`     | `runtime/proc.go` (entersyscall / exitsyscall)              |
29//! | `sysmon`      | `runtime/proc.go` (sysmon / retake)                         |
30//! | `time`        | `runtime/time.go`                                           |
31//! | `asm_amd64`   | `runtime/asm_amd64.s`, `runtime/preempt_amd64.s`           |
32//! | `asm_arm64`   | `runtime/asm_arm64.s`, `runtime/preempt_arm64.s`           |
33
34// Faithful Go-runtime ports contain symbols that will be used when deferred
35// features land.  Suppress dead-code warnings across the whole runtime module.
36#![allow(dead_code)]
37
38pub(crate) mod g;
39pub(crate) mod m;
40pub(crate) mod rawmutex;
41pub(crate) mod netpoll;
42pub(crate) mod p;
43pub(crate) mod park;
44pub(crate) mod sched;
45pub(crate) mod stack;
46pub(crate) mod sudog;
47pub(crate) mod syscall;
48pub(crate) mod sysmon;
49pub(crate) mod time;
50
51#[cfg(target_arch = "x86_64")]
52pub(crate) mod asm_amd64;
53#[cfg(target_arch = "aarch64")]
54pub(crate) mod asm_arm64;
55
56// Re-export the three context-switch primitives from the correct asm module
57// so the rest of the runtime uses `crate::runtime::{gogo, mcall, systemstack}`
58// without caring about the target architecture.
59#[cfg(target_arch = "aarch64")]
60pub(crate) use asm_arm64::{gogo, mcall, systemstack};