Skip to content

[r+] Add note about libc::exit's unsafety. #21026

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4157,6 +4157,27 @@ pub mod funcs {
pub fn malloc(size: size_t) -> *mut c_void;
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
pub fn free(p: *mut c_void);

/// Exits the running program in a possibly dangerous manner.
///
/// # Unsafety
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last minor nit/question: Should this heading be Warning or something like that rather than Unsafety? I'm not sure how strict we want to be about the use of the term "unsafe" in documentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the function is an unsafe fn, I chose unsafety rather than something like "Warning".

///
/// While this forces your program to exit, it does so in a way that has
/// consequences. This will skip all unwinding code, which means that anything
/// relying on unwinding for cleanup (such as flushing and closing a buffer to a
/// file) may act in an unexpected way.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume panic! already has the same unsafety note? Given that panicking in destructors will skip unwinding too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure, but that's out of the scope of this ticket.

///
/// # Examples
///
/// ```no_run
/// extern crate libc;
///
/// fn main() {
/// unsafe {
/// libc::exit(1);
/// }
/// }
/// ```
pub fn exit(status: c_int) -> !;
pub fn _exit(status: c_int) -> !;
pub fn atexit(cb: extern fn()) -> c_int;
Expand Down