Repository navigation
std: don't clean up the main thread's altstack #161037
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| #![cfg_attr(test, allow(dead_code))] | ||
|
|
||
| pub use self::imp::{cleanup, init}; | ||
| pub use self::imp::init; | ||
| use self::imp::{drop_handler, make_handler}; | ||
|
|
||
| pub struct Handler { | ||
|
|
@@ -143,6 +143,12 @@ mod imp { | |
| } | ||
|
|
||
| static PAGE_SIZE: Atomic<usize> = AtomicUsize::new(0); | ||
| // Store a pointer to the allocation for the main thread's altstack so that | ||
| // tools like valgrind don't complain about a leaked unreachable allocation. | ||
| // | ||
| // If the main thread exits, the process will terminate so there's no use in | ||
| // freeing resources. It also means that the altstack is still installed | ||
| // while TLS destructors are run on the main thread (c.f. #111272). | ||
| static MAIN_ALTSTACK: Atomic<*mut libc::c_void> = AtomicPtr::new(ptr::null_mut()); | ||
| static NEED_ALTSTACK: Atomic<bool> = AtomicBool::new(false); | ||
|
|
||
|
|
@@ -190,18 +196,6 @@ mod imp { | |
| } | ||
| } | ||
|
|
||
| /// # Safety | ||
| /// Must be called only once | ||
| #[forbid(unsafe_op_in_unsafe_fn)] | ||
| pub unsafe fn cleanup() { | ||
| if cfg!(panic = "immediate-abort") { | ||
| return; | ||
| } | ||
| // FIXME: I probably cause more bugs than I'm worth! | ||
| // see https://github.com/rust-lang/rust/issues/111272 | ||
| unsafe { drop_handler(MAIN_ALTSTACK.load(Ordering::Relaxed)) }; | ||
|
Contributor
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. Other than unmapping the main thread's sigalt stack,
Contributor
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. Looking at the code for this, effectively the worst-case scenario here appears to be leaking a a. isn't called for every thread on exit, leaking memory no matter what, or So, this isn't really worth cancelling this change for, but you're welcome to file an issue and propose a separate fix for that.
Contributor
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. They do seem minor. Thanks for taking a look at this. |
||
| } | ||
|
|
||
| unsafe fn get_stack() -> libc::stack_t { | ||
| // OpenBSD requires this flag for stack mapping | ||
| // otherwise the said mapping will fail as a no-op on most systems | ||
|
|
@@ -651,8 +645,6 @@ mod imp { | |
| mod imp { | ||
| pub unsafe fn init() {} | ||
|
|
||
| pub unsafe fn cleanup() {} | ||
|
|
||
| pub unsafe fn make_handler(_main_thread: bool) -> super::Handler { | ||
| super::Handler::null() | ||
| } | ||
|
|
@@ -735,8 +727,6 @@ mod imp { | |
| reserve_stack(); | ||
| } | ||
|
|
||
| pub unsafe fn cleanup() {} | ||
|
|
||
| pub unsafe fn make_handler(main_thread: bool) -> super::Handler { | ||
| if !main_thread { | ||
| reserve_stack(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: since we can generate private docs these should probably just be doc comments.
View changes since the review