Skip to content

Commit 75c73f9

Browse files
std: update comments on gcc personality fn
1 parent 9d6d5da commit 75c73f9

File tree

1 file changed

+30
-10
lines changed
  • library/std/src/sys/personality

1 file changed

+30
-10
lines changed

library/std/src/sys/personality/gcc.rs

+30-10
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ cfg_if::cfg_if! {
9898
not(all(target_vendor = "apple", not(target_os = "watchos"))),
9999
not(target_os = "netbsd"),
100100
))] {
101-
// ARM EHABI personality routine.
102-
// https://web.archive.org/web/20190728160938/https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
103-
//
104-
// Apple 32-bit ARM (but not watchOS) uses the default routine instead
105-
// since it uses SjLj unwinding.
101+
/// personality fn called by [ARM EHABI]
102+
///
103+
/// Apple 32-bit ARM (but not watchOS) uses the default routine instead
104+
/// since it uses "setjmp-longjmp" unwinding.
105+
///
106+
/// [ARM EHABI]: https://web.archive.org/web/20190728160938/https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
106107
#[lang = "eh_personality"]
107108
unsafe extern "C" fn rust_eh_personality(
108109
state: uw::_Unwind_State,
@@ -198,8 +199,8 @@ cfg_if::cfg_if! {
198199
}
199200
}
200201
} else {
201-
// Default personality routine, which is used directly on most targets
202-
// and indirectly on Windows x86_64 via SEH.
202+
/// Default personality routine, which is used directly on most targets
203+
/// and indirectly on Windows x86_64 and AArch64 via SEH.
203204
unsafe extern "C" fn rust_eh_personality_impl(
204205
version: c_int,
205206
actions: uw::_Unwind_Action,
@@ -244,8 +245,10 @@ cfg_if::cfg_if! {
244245

245246
cfg_if::cfg_if! {
246247
if #[cfg(all(windows, any(target_arch = "aarch64", target_arch = "x86_64"), target_env = "gnu"))] {
247-
// On x86_64 MinGW targets, the unwinding mechanism is SEH however the unwind
248-
// handler data (aka LSDA) uses GCC-compatible encoding.
248+
/// personality fn called by Windows SEH
249+
///
250+
/// On x86_64 and AArch64 MinGW targets, the unwinding mechanism is SEH,
251+
/// however the unwind handler data (aka LSDA) uses GCC-compatible encoding
249252
#[lang = "eh_personality"]
250253
#[allow(nonstandard_style)]
251254
unsafe extern "C" fn rust_eh_personality(
@@ -254,6 +257,9 @@ cfg_if::cfg_if! {
254257
contextRecord: *mut uw::CONTEXT,
255258
dispatcherContext: *mut uw::DISPATCHER_CONTEXT,
256259
) -> uw::EXCEPTION_DISPOSITION {
260+
// SAFETY: the cfg is still target_os = "windows" and target_env = "gnu",
261+
// which means that this is the correct function to call, passing our impl fn
262+
// as the callback which gets actually used
257263
unsafe {
258264
uw::_GCC_specific_handler(
259265
exceptionRecord,
@@ -265,7 +271,19 @@ cfg_if::cfg_if! {
265271
}
266272
}
267273
} else {
268-
// The personality routine for most of our targets.
274+
/// personality fn called by [Itanium C++ ABI Exception Handling][itanium-eh]
275+
///
276+
/// The personality routine for most non-Windows targets. This will be called by
277+
/// the unwinding library:
278+
/// - "In the search phase, the framework repeatedly calls the personality routine,
279+
/// with the _UA_SEARCH_PHASE flag as described below, first for the current PC
280+
/// and register state, and then unwinding a frame to a new PC at each step..."
281+
/// - "If the search phase reports success, the framework restarts in the cleanup
282+
/// phase. Again, it repeatedly calls the personality routine, with the
283+
/// _UA_CLEANUP_PHASE flag as described below, first for the current PC and
284+
/// register state, and then unwinding a frame to a new PC at each step..."i
285+
///
286+
/// [itanium-eh]: https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
269287
#[lang = "eh_personality"]
270288
unsafe extern "C" fn rust_eh_personality(
271289
version: c_int,
@@ -274,6 +292,8 @@ cfg_if::cfg_if! {
274292
exception_object: *mut uw::_Unwind_Exception,
275293
context: *mut uw::_Unwind_Context,
276294
) -> uw::_Unwind_Reason_Code {
295+
// SAFETY: the platform support must modify the cfg for the inner fn
296+
// if it needs something different than what is currently invoked.
277297
unsafe {
278298
rust_eh_personality_impl(
279299
version,

0 commit comments

Comments
 (0)