[libcxx-commits] [compiler-rt] [libcxxabi] [libunwind] [runtimes][PAC] Harden unwinding when possible (#138571) (PR #143230)
Anatoly Trosinenko via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 30 06:40:42 PDT 2025
================
@@ -43,6 +43,130 @@
#define LIBUNWIND_AVAIL
#endif
+#if __has_extension(ptrauth_qualifier)
+
+ #if __has_include(<ptrauth.h>)
+ #include <ptrauth.h>
+ #endif
+
+ #if __has_extension(ptrauth_restricted_intptr_qualifier)
+ #define __unwind_ptrauth_restricted_intptr(...) \
+ __ptrauth_restricted_intptr(__VA_ARGS__)
+ #else
+ #define __unwind_ptrauth_restricted_intptr(...) \
+ __ptrauth(__VA_ARGS__)
+ #endif
+
+// ptrauth_string_discriminator("unw_proc_info_t::handler") == 0x7405
+ #define __ptrauth_unwind_personality_fn_disc 0x7405
+
+ #define __ptrauth_unwind_personality_fn \
+ __ptrauth(ptrauth_key_function_pointer, 1, __ptrauth_unwind_personality_fn_disc)
+
+ #define __ptrauth_unwind_personality_fn_intptr \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 1, __ptrauth_unwind_personality_fn_disc)
+
+// ptrauth_string_discriminator("unw_proc_info_t::start_ip") == 0xCA2C
+ #define __ptrauth_unwind_proc_startip \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_independent_code, 1, 0xCA2C)
+
+// ptrauth_string_discriminator("unw_proc_info_t::end_ip") == 0xE183
+ #define __ptrauth_unwind_proc_endip \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_independent_code, 1, 0xE183)
+
+// ptrauth_string_discriminator("unw_proc_info_t::lsda") == 0x83DE
+ #define __ptrauth_unwind_proc_lsda \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x83DE)
+
+// ptrauth_string_discriminator("unw_proc_info_t::flags") == 0x79A1
+ #define __ptrauth_unwind_proc_flags \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x79A1)
+
+// ptrauth_string_discriminator("unw_proc_info_t::unwind_info") == 0xC20C
+ #define __ptrauth_unwind_proc_info \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0xC20C)
+
+// ptrauth_string_discriminator("unw_proc_info_t::extra") == 0x03DF
+ #define __ptrauth_unwind_proc_extra \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x03DF)
+
+// ptrauth_string_discriminator("Registers_arm64::link_reg_t") == 0x8301
+ #define __ptrauth_unwind_arm64_link_reg \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_code, 1, 0x8301)
+
+// ptrauth_string_discriminator("UnwindInfoSections::dso_base") == 0x4FF5
+ #define __ptrauth_unwind_info_section_dso_base \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x4FF5)
+
+// ptrauth_string_discriminator("UnwindInfoSections::dwarf_section") == 0x4974
+ #define __ptrauth_unwind_info_dwarf_section \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x4974)
+
+// ptrauth_string_discriminator("UnwindInfoSections::dwarf_section_length") == 0x2A9A
+ #define __ptrauth_unwind_info_dwarf_section_length \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x2A9A)
+
+// ptrauth_string_discriminator("UnwindInfoSections::compact_unwind_section") == 0xA27B
+ #define __ptrauth_unwind_info_compact_unwind_section \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0xA27B)
+
+// ptrauth_string_discriminator("UnwindInfoSections::compact_unwind_section_length") == 0x5D0A
+ #define __ptrauth_unwind_info_compact_unwind_section_length \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x5D0A)
+
+// ptrauth_string_discriminator("CIE_Info::personality") == 0x6A40
+ #define __ptrauth_unwind_cfi_personality_disc 0x6A40
+ #define __ptrauth_unwind_cfi_personality \
+ __unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 1, \
+ __ptrauth_unwind_cfi_personality_disc)
+
+#else
+
+ #define __ptrauth_unwind_personality_fn
+ #define __ptrauth_unwind_personality_fn_intptr
+ #define __ptrauth_unwind_proc_startip
+ #define __ptrauth_unwind_proc_endip
+ #define __ptrauth_unwind_proc_lsda
+ #define __ptrauth_unwind_proc_flags
+ #define __ptrauth_unwind_proc_info
+ #define __ptrauth_unwind_proc_extra
+ #define __ptrauth_unwind_arm64_link_reg
+ #define __ptrauth_unwind_info_section_dso_base
+ #define __ptrauth_unwind_info_dwarf_section
+ #define __ptrauth_unwind_info_dwarf_section_length
+ #define __ptrauth_unwind_info_compact_unwind_section
+ #define __ptrauth_unwind_info_compact_unwind_section_length
+ #define __ptrauth_unwind_cfi_personality
+
+#endif
+
+// Helper wrappers for pointer auth qualifiers because we use a lot of variants
+// Suffixes:
+// * RI_*: __ptrauth_restricted_intptr
+// * PDD : ptrauth_key_process_dependent_data
+// * PIC : ptrauth_key_process_independent_code
+// * PDC : ptrauth_key_process_dependent_code
+// * FN : ptrauth_key_function_pointer
+#define __LIBUNWIND_PTRAUTH_RI_PDD(__discriminator) \
+ _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_data, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
+#define __LIBUNWIND_PTRAUTH_RI_PIC(__discriminator) \
+ _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_independent_code, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
+#define __LIBUNWIND_PTRAUTH_RI_PDC(__discriminator) \
+ _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_process_dependent_code, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
+#define __LIBUNWIND_PTRAUTH_RI_FN(__discriminator) \
+ _LIBUNWIND_PTRAUTH_RESTRICTED_INTPTR(ptrauth_key_function_pointer, \
+ /*__address_discriminated=*/1, \
+ __discriminator)
+#define __LIBUNWIND_PTRAUTH_FN(__discriminator) \
+ _LIBUNWIND_PTRAUTH(ptrauth_key_function_pointer, \
+ /*__address_discriminated=*/1, __discriminator)
+
----------------
atrosinenko wrote:
Not used anymore.
https://github.com/llvm/llvm-project/pull/143230
More information about the libcxx-commits
mailing list