Skip to content

Commit c9cd4a6

Browse files
std: update comments on gcc personality fn
1 parent 2c7ae38 commit c9cd4a6

File tree

1 file changed

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

1 file changed

+32
-10
lines changed

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

+32-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][armeabi-eh]
102+
///
103+
/// Apple 32-bit ARM (but not watchOS) uses the default routine instead
104+
/// since it uses "setjmp-longjmp" unwinding.
105+
///
106+
/// [armeabi-eh]: 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,
@@ -200,8 +201,8 @@ cfg_if::cfg_if! {
200201
}
201202
}
202203
} else {
203-
// Default personality routine, which is used directly on most targets
204-
// and indirectly on Windows x86_64 via SEH.
204+
/// Default personality routine, which is used directly on most targets
205+
/// and indirectly on Windows x86_64 and AArch64 via SEH.
205206
unsafe extern "C" fn rust_eh_personality_impl(
206207
version: c_int,
207208
actions: uw::_Unwind_Action,
@@ -246,8 +247,12 @@ cfg_if::cfg_if! {
246247

247248
cfg_if::cfg_if! {
248249
if #[cfg(all(windows, any(target_arch = "aarch64", target_arch = "x86_64"), target_env = "gnu"))] {
249-
// On x86_64 MinGW targets, the unwinding mechanism is SEH however the unwind
250-
// handler data (aka LSDA) uses GCC-compatible encoding.
250+
/// personality fn called by [Windows Structured Exception Handling][windows-eh]
251+
///
252+
/// On x86_64 and AArch64 MinGW targets, the unwinding mechanism is SEH,
253+
/// however the unwind handler data (aka LSDA) uses GCC-compatible encoding
254+
///
255+
/// [windows-eh]: https://learn.microsoft.com/en-us/cpp/cpp/structured-exception-handling-c-cpp?view=msvc-170
251256
#[lang = "eh_personality"]
252257
#[allow(nonstandard_style)]
253258
unsafe extern "C" fn rust_eh_personality(
@@ -256,6 +261,9 @@ cfg_if::cfg_if! {
256261
contextRecord: *mut uw::CONTEXT,
257262
dispatcherContext: *mut uw::DISPATCHER_CONTEXT,
258263
) -> uw::EXCEPTION_DISPOSITION {
264+
// SAFETY: the cfg is still target_os = "windows" and target_env = "gnu",
265+
// which means that this is the correct function to call, passing our impl fn
266+
// as the callback which gets actually used
259267
unsafe {
260268
uw::_GCC_specific_handler(
261269
exceptionRecord,
@@ -267,7 +275,19 @@ cfg_if::cfg_if! {
267275
}
268276
}
269277
} else {
270-
// The personality routine for most of our targets.
278+
/// personality fn called by [Itanium C++ ABI Exception Handling][itanium-eh]
279+
///
280+
/// The personality routine for most non-Windows targets. This will be called by
281+
/// the unwinding library:
282+
/// - "In the search phase, the framework repeatedly calls the personality routine,
283+
/// with the _UA_SEARCH_PHASE flag as described below, first for the current PC
284+
/// and register state, and then unwinding a frame to a new PC at each step..."
285+
/// - "If the search phase reports success, the framework restarts in the cleanup
286+
/// phase. Again, it repeatedly calls the personality routine, with the
287+
/// _UA_CLEANUP_PHASE flag as described below, first for the current PC and
288+
/// register state, and then unwinding a frame to a new PC at each step..."i
289+
///
290+
/// [itanium-eh]: https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
271291
#[lang = "eh_personality"]
272292
unsafe extern "C" fn rust_eh_personality(
273293
version: c_int,
@@ -276,6 +296,8 @@ cfg_if::cfg_if! {
276296
exception_object: *mut uw::_Unwind_Exception,
277297
context: *mut uw::_Unwind_Context,
278298
) -> uw::_Unwind_Reason_Code {
299+
// SAFETY: the platform support must modify the cfg for the inner fn
300+
// if it needs something different than what is currently invoked.
279301
unsafe {
280302
rust_eh_personality_impl(
281303
version,

0 commit comments

Comments
 (0)