@@ -72,8 +72,25 @@ macro_rules! rtunwrap {
72
72
// Runs before `main`.
73
73
// SAFETY: must be called only once during runtime initialization.
74
74
// 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`.
77
94
#[ cfg_attr( test, allow( dead_code) ) ]
78
95
unsafe fn init ( argc : isize , argv : * const * const u8 , sigpipe : u8 ) {
79
96
unsafe {
0 commit comments