@@ -72,8 +72,25 @@ macro_rules! rtunwrap {
7272// Runs before `main`.
7373// SAFETY: must be called only once during runtime initialization.
7474// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
75- // The extra parameter `sigpipe` allows rustc to generate code that instructs std whether
76- // or not to ignore `SIGPIPE`.
75+ //
76+ // # The `sigpipe` parameter
77+ //
78+ // Since 2014, the Rust runtime on Unix has set the `SIGPIPE` handler to
79+ // `SIG_IGN`. Applications have good reasons to want a different behavior
80+ // though, so there is a `#[unix_sigpipe = "..."]` attribute on `fn main()` that
81+ // can be used to select how `SIGPIPE` shall be setup (if changed at all) before
82+ // `fn main()` is called. See <https://github.com/rust-lang/rust/issues/97889>
83+ // for more info.
84+ //
85+ // The `sigpipe` parameter to this function gets its value via the code that
86+ // rustc generates to invoke `fn lang_start()`. The reason we have `sigpipe` for
87+ // all platforms and not only Unix, is because std is not allowed to have `cfg`
88+ // directives as this high level. See the module docs in
89+ // `src/tools/tidy/src/pal.rs` for more info. On all other platforms, `sigpipe`
90+ // has a value, but its value is ignored.
91+ //
92+ // Even though it is an `u8`, it only ever has 3 values. These are documented in
93+ // `compiler/rustc_session/src/config/sigpipe.rs`.
7794#[ cfg_attr( test, allow( dead_code) ) ]
7895unsafe fn init ( argc : isize , argv : * const * const u8 , sigpipe : u8 ) {
7996 unsafe {
0 commit comments