-
Notifications
You must be signed in to change notification settings - Fork 13.4k
aborts: Clarify documentation and comments #85377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a8bb7fa
aborts: Clarify documentation and comments
ijackson de19e4d
abort docs: Do not claim that intrinsics::abort is always a debug trap
ijackson 4e7c348
abort docs: Document buffer non-flushing
ijackson 44852e0
Talk about invalid instructions rather than debug traps
ijackson 19c347e
Talk about "terminate" rather than "die"
ijackson f73a555
Use american spelling for behaviour
m-ou-se 08d912f
s/die/terminate/ in abort documentation.
m-ou-se File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,13 +217,41 @@ pub fn cvt_nz(error: libc::c_int) -> crate::io::Result<()> { | |
if error == 0 { Ok(()) } else { Err(crate::io::Error::from_raw_os_error(error)) } | ||
} | ||
|
||
// On Unix-like platforms, libc::abort will unregister signal handlers | ||
// including the SIGABRT handler, preventing the abort from being blocked, and | ||
// fclose streams, with the side effect of flushing them so libc buffered | ||
// output will be printed. Additionally the shell will generally print a more | ||
// understandable error message like "Abort trap" rather than "Illegal | ||
// instruction" that intrinsics::abort would cause, as intrinsics::abort is | ||
// implemented as an illegal instruction. | ||
// libc::abort() will run the SIGABRT handler. That's fine because anyone who | ||
// installs a SIGABRT handler already has to expect it to run in Very Bad | ||
// situations (eg, malloc crashing). | ||
// | ||
// Current glibc's abort() function unblocks SIGABRT, raises SIGABRT, clears the | ||
// SIGABRT handler and raises it again, and then starts to get creative. | ||
// | ||
// See the public documentation for `intrinsics::abort()` and `process::abort()` | ||
// for further discussion. | ||
// | ||
// There is confusion about whether libc::abort() flushes stdio streams. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps mention it is implementation-defined as a first point (C18 7.22.4.1p1). |
||
// libc::abort() is required by ISO C 99 (7.14.1.1p5) to be async-signal-safe, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to point to C18 (it is still 7.14.1.1p5). |
||
// so flushing streams is at least extremely hard, if not entirely impossible. | ||
// | ||
// However, some versions of POSIX (eg IEEE Std 1003.1-2001) required abort to | ||
// do so. In 1003.1-2004 this was fixed. | ||
// | ||
// glibc's implementation did the flush, unsafely, before glibc commit | ||
// 91e7cf982d01 `abort: Do not flush stdio streams [BZ #15436]' by Florian | ||
// Weimer. According to glibc's NEWS: | ||
// | ||
// The abort function terminates the process immediately, without flushing | ||
// stdio streams. Previous glibc versions used to flush streams, resulting | ||
// in deadlocks and further data corruption. This change also affects | ||
// process aborts as the result of assertion failures. | ||
// | ||
// This is an accurate description of the problem. The only solution for | ||
// program with nontrivial use of C stdio is a fixed libc - one which does not | ||
// try to flush in abort - since even libc-internal errors, and assertion | ||
// failures generated from C, will go via abort(). | ||
// | ||
// On systems with old, buggy, libcs, the impact can be severe for a | ||
// multithreaded C program. It is much less severe for Rust, because Rust | ||
// stdlib doesn't use libc stdio buffering. In a typical Rust program, which | ||
// does not use C stdio, even a buggy libc::abort() is, in fact, safe. | ||
ijackson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub fn abort_internal() -> ! { | ||
unsafe { libc::abort() } | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.