-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix panic
when restricted-std
is enabled.
#104971
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 |
---|---|---|
|
@@ -336,20 +336,26 @@ pub mod panic_count { | |
pub fn increase() -> (bool, usize) { | ||
let global_count = GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed); | ||
let must_abort = global_count & ALWAYS_ABORT_FLAG != 0; | ||
let panics = if must_abort { | ||
global_count & !ALWAYS_ABORT_FLAG | ||
} else { | ||
LOCAL_PANIC_COUNT.with(|c| { | ||
let mut panics = global_count & !ALWAYS_ABORT_FLAG; | ||
|
||
// In a restricted_std environment, we likely don't have thread_local. | ||
// If we attempt to use LOCAL_PANIC_COUNT here, it is probable that another panic will | ||
// occur, sending us into an infinite panic loop that never calls the panic handler. | ||
#[cfg(not(feature = "restricted-std"))] | ||
if !must_abort { | ||
panics = LOCAL_PANIC_COUNT.with(|c| { | ||
Comment on lines
+341
to
+346
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. What does "likely" mean here? Your PR description says
Is that always the case when using restricted-std? and if not, when can the behavior be different? 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 it a bit more, it seems it's true most of the time, but not necessarily always. The restricted-std requirement is defined here if a platform match is not found, and since thread_local is unimplemented in sys/unsupported, a panic loop occurs. There do appear to be some cases where this may not always be true - i.e. in the case of I'm not really sure how big of an impact this would be; since |
||
let next = c.get() + 1; | ||
c.set(next); | ||
next | ||
}) | ||
}); | ||
}; | ||
|
||
(must_abort, panics) | ||
} | ||
|
||
pub fn decrease() { | ||
GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed); | ||
#[cfg(not(feature = "restricted-std"))] | ||
LOCAL_PANIC_COUNT.with(|c| { | ||
let next = c.get() - 1; | ||
c.set(next); | ||
|
Uh oh!
There was an error while loading. Please reload this page.