Skip to content

Commit 61b763a

Browse files
committed
Updating to include some fixes I lost in the last update
At some point I lost the changes to loadAndAuthenticateLinkRegister I also updated schema names in libunwind to be more consistent Finally while looking at the total diff I saw some places that the formatting could be improved.
1 parent e7f03a8 commit 61b763a

File tree

10 files changed

+106
-113
lines changed

10 files changed

+106
-113
lines changed

libcxxabi/include/__cxxabi_config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#define _LIBCXXABI_FUNC_VIS __declspec(dllimport)
4949
#define _LIBCXXABI_TYPE_VIS __declspec(dllimport)
5050
#endif
51-
5251
#else
5352
#if !defined(_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)
5453
#define _LIBCXXABI_HIDDEN __attribute__((__visibility__("hidden")))

libcxxabi/src/cxa_personality.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@ typedef void* __ptrauth_scan_results_landingpad landing_pad_ptr_t;
578578
struct scan_results
579579
{
580580
int64_t ttypeIndex; // > 0 catch handler, < 0 exception spec handler, == 0 a cleanup
581-
action_ptr_t actionRecord; // Currently unused. Retained to ease future maintenance.
582-
lsd_ptr_t languageSpecificData; // Needed only for __cxa_call_unexpected
583-
landing_pad_t landingPad; // null -> nothing found, else something found
581+
action_ptr_t actionRecord; // Currently unused. Retained to ease future maintenance.
582+
lsd_ptr_t languageSpecificData; // Needed only for __cxa_call_unexpected
583+
landing_pad_t landingPad; // null -> nothing found, else something found
584584
void* adjustedPtr; // Used in cxa_exception.cpp
585585
_Unwind_Reason_Code reason; // One of _URC_FATAL_PHASE1_ERROR,
586586
// _URC_FATAL_PHASE2_ERROR,
@@ -589,7 +589,7 @@ struct scan_results
589589
};
590590

591591
} // unnamed namespace
592-
}
592+
} // extern "C"
593593

594594
namespace {
595595
// The logical model for casting authenticated function pointers makes
@@ -632,16 +632,16 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
632632
_Unwind_SetGR(context, __builtin_eh_return_data_regno(1),
633633
static_cast<uintptr_t>(results.ttypeIndex));
634634
#if __has_feature(ptrauth_qualifier)
635-
auto stack_pointer = _Unwind_GetGR(context, UNW_REG_SP);
635+
auto stackPointer = _Unwind_GetGR(context, UNW_REG_SP);
636636
// We manually re-sign the IP as the __ptrauth qualifiers cannot
637637
// express the required relationship with the destination address
638638
const auto existingDiscriminator = ptrauth_blend_discriminator(
639639
&results.landingPad, __ptrauth_scan_results_landingpad_disc);
640-
unw_word_t newIP /* opaque __ptrauth(ptrauth_key_return_address, stack_pointer, 0) */ =
640+
unw_word_t newIP /* opaque __ptrauth(ptrauth_key_return_address, stackPointer, 0) */ =
641641
(unw_word_t)ptrauth_auth_and_resign(*(void**)&results.landingPad,
642642
__ptrauth_scan_results_landingpad_key,
643643
existingDiscriminator,
644-
ptrauth_key_return_address, stack_pointer);
644+
ptrauth_key_return_address, stackPointer);
645645
_Unwind_SetIP(context, newIP);
646646
#else
647647
_Unwind_SetIP(context, results.landingPad);

libunwind/include/libunwind.h

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -58,85 +58,86 @@
5858
#endif
5959

6060
// ptrauth_string_discriminator("unw_proc_info_t::handler") == 0x7405
61-
#define __ptrauth_unwind_personality_fn_disc 0x7405
61+
#define __ptrauth_unwind_upi_handler_disc 0x7405
6262

63-
#define __ptrauth_unwind_personality_fn \
64-
__ptrauth(ptrauth_key_function_pointer, 1, __ptrauth_unwind_personality_fn_disc)
63+
#define __ptrauth_unwind_upi_handler \
64+
__ptrauth(ptrauth_key_function_pointer, 1, __ptrauth_unwind_upi_handler_disc)
6565

66-
#define __ptrauth_unwind_personality_fn_intptr \
67-
__unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 1, __ptrauth_unwind_personality_fn_disc)
66+
#define __ptrauth_unwind_upi_handler_intptr \
67+
__unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 1,\
68+
__ptrauth_unwind_upi_handler_disc)
6869

6970
// ptrauth_string_discriminator("unw_proc_info_t::start_ip") == 0xCA2C
70-
#define __ptrauth_unwind_proc_startip \
71+
#define __ptrauth_unwind_upi_startip \
7172
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_independent_code, 1, 0xCA2C)
7273

7374
// ptrauth_string_discriminator("unw_proc_info_t::end_ip") == 0xE183
74-
#define __ptrauth_unwind_proc_endip \
75+
#define __ptrauth_unwind_upi_endip \
7576
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_independent_code, 1, 0xE183)
7677

7778
// ptrauth_string_discriminator("unw_proc_info_t::lsda") == 0x83DE
78-
#define __ptrauth_unwind_proc_lsda \
79+
#define __ptrauth_unwind_upi_lsda \
7980
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x83DE)
8081

8182
// ptrauth_string_discriminator("unw_proc_info_t::flags") == 0x79A1
82-
#define __ptrauth_unwind_proc_flags \
83+
#define __ptrauth_unwind_upi_flags \
8384
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x79A1)
8485

8586
// ptrauth_string_discriminator("unw_proc_info_t::unwind_info") == 0xC20C
86-
#define __ptrauth_unwind_proc_info \
87+
#define __ptrauth_unwind_upi_info \
8788
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0xC20C)
8889

8990
// ptrauth_string_discriminator("unw_proc_info_t::extra") == 0x03DF
90-
#define __ptrauth_unwind_proc_extra \
91+
#define __ptrauth_unwind_upi_extra \
9192
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x03DF)
9293

9394
// ptrauth_string_discriminator("Registers_arm64::link_reg_t") == 0x8301
94-
#define __ptrauth_unwind_arm64_link_reg \
95+
#define __ptrauth_unwind_registers_arm64_link_reg \
9596
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_code, 1, 0x8301)
9697

9798
// ptrauth_string_discriminator("UnwindInfoSections::dso_base") == 0x4FF5
98-
#define __ptrauth_unwind_info_section_dso_base \
99+
#define __ptrauth_unwind_uis_dso_base \
99100
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x4FF5)
100101

101102
// ptrauth_string_discriminator("UnwindInfoSections::dwarf_section") == 0x4974
102-
#define __ptrauth_unwind_info_dwarf_section \
103+
#define __ptrauth_unwind_uis_dwarf_section \
103104
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x4974)
104105

105106
// ptrauth_string_discriminator("UnwindInfoSections::dwarf_section_length") == 0x2A9A
106-
#define __ptrauth_unwind_info_dwarf_section_length \
107+
#define __ptrauth_unwind_uis_dwarf_section_length \
107108
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x2A9A)
108109

109110
// ptrauth_string_discriminator("UnwindInfoSections::compact_unwind_section") == 0xA27B
110-
#define __ptrauth_unwind_info_compact_unwind_section \
111+
#define __ptrauth_unwind_uis_compact_unwind_section \
111112
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0xA27B)
112113

113114
// ptrauth_string_discriminator("UnwindInfoSections::compact_unwind_section_length") == 0x5D0A
114-
#define __ptrauth_unwind_info_compact_unwind_section_length \
115+
#define __ptrauth_unwind_uis_compact_unwind_section_length \
115116
__unwind_ptrauth_restricted_intptr(ptrauth_key_process_dependent_data, 1, 0x5D0A)
116117

117118
// ptrauth_string_discriminator("CIE_Info::personality") == 0x6A40
118-
#define __ptrauth_unwind_cfi_personality_disc 0x6A40
119-
#define __ptrauth_unwind_cfi_personality \
119+
#define __ptrauth_unwind_cie_info_personality_disc 0x6A40
120+
#define __ptrauth_unwind_cie_info_personality \
120121
__unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 1, \
121-
__ptrauth_unwind_cfi_personality_disc)
122+
__ptrauth_unwind_cie_info_personality_disc)
122123

123124
#else
124125

125-
#define __ptrauth_unwind_personality_fn
126-
#define __ptrauth_unwind_personality_fn_intptr
127-
#define __ptrauth_unwind_proc_startip
128-
#define __ptrauth_unwind_proc_endip
129-
#define __ptrauth_unwind_proc_lsda
130-
#define __ptrauth_unwind_proc_flags
131-
#define __ptrauth_unwind_proc_info
132-
#define __ptrauth_unwind_proc_extra
133-
#define __ptrauth_unwind_arm64_link_reg
134-
#define __ptrauth_unwind_info_section_dso_base
135-
#define __ptrauth_unwind_info_dwarf_section
136-
#define __ptrauth_unwind_info_dwarf_section_length
137-
#define __ptrauth_unwind_info_compact_unwind_section
138-
#define __ptrauth_unwind_info_compact_unwind_section_length
139-
#define __ptrauth_unwind_cfi_personality
126+
#define __ptrauth_unwind_upi_handler
127+
#define __ptrauth_unwind_upi_handler_intptr
128+
#define __ptrauth_unwind_upi_startip
129+
#define __ptrauth_unwind_upi_endip
130+
#define __ptrauth_unwind_upi_lsda
131+
#define __ptrauth_unwind_upi_flags
132+
#define __ptrauth_unwind_upi_info
133+
#define __ptrauth_unwind_upi_extra
134+
#define __ptrauth_unwind_registers_arm64_link_reg
135+
#define __ptrauth_unwind_uis_dso_base
136+
#define __ptrauth_unwind_uis_dwarf_section
137+
#define __ptrauth_unwind_uis_dwarf_section_length
138+
#define __ptrauth_unwind_uis_compact_unwind_section
139+
#define __ptrauth_unwind_uis_compact_unwind_section_length
140+
#define __ptrauth_unwind_cie_info_personality
140141

141142
#endif
142143

@@ -185,18 +186,18 @@ typedef double unw_fpreg_t;
185186
#endif
186187

187188
struct unw_proc_info_t {
188-
unw_word_t __ptrauth_unwind_proc_startip start_ip; /* start address of function */
189-
unw_word_t __ptrauth_unwind_proc_endip end_ip; /* address after end of function */
190-
unw_word_t __ptrauth_unwind_proc_lsda lsda; /* address of language specific data area, */
191-
/* or zero if not used */
189+
unw_word_t __ptrauth_unwind_upi_startip start_ip; /* start address of function */
190+
unw_word_t __ptrauth_unwind_upi_endip end_ip; /* address after end of function */
191+
unw_word_t __ptrauth_unwind_upi_lsda lsda; /* address of language specific data area, */
192+
/* or zero if not used */
192193

193-
unw_word_t __ptrauth_unwind_personality_fn_intptr handler;
194-
unw_word_t gp; /* not used */
195-
unw_word_t __ptrauth_unwind_proc_flags flags; /* not used */
196-
uint32_t format; /* compact unwind encoding, or zero if none */
197-
uint32_t unwind_info_size; /* size of DWARF unwind info, or zero if none */
198-
unw_word_t __ptrauth_unwind_proc_info unwind_info; /* address of DWARF unwind info, or zero */
199-
unw_word_t __ptrauth_unwind_proc_extra extra; /* mach_header of mach-o image containing func */
194+
unw_word_t __ptrauth_unwind_upi_handler_intptr handler;
195+
unw_word_t gp; /* not used */
196+
unw_word_t __ptrauth_unwind_upi_flags flags; /* not used */
197+
uint32_t format; /* compact unwind encoding, or zero if none */
198+
uint32_t unwind_info_size; /* size of DWARF unwind info, or zero if none */
199+
unw_word_t __ptrauth_unwind_upi_info unwind_info; /* address of DWARF unwind info, or zero */
200+
unw_word_t __ptrauth_unwind_upi_extra extra; /* mach_header of mach-o image containing func */
200201
};
201202
typedef struct unw_proc_info_t unw_proc_info_t;
202203

libunwind/src/AddressSpace.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,31 @@ struct UnwindInfoSections {
129129
defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND) || \
130130
defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
131131
// No dso_base for SEH.
132-
uintptr_t __ptrauth_unwind_info_section_dso_base dso_base = 0;
132+
uintptr_t __ptrauth_unwind_uis_dso_base
133+
dso_base = 0;
133134
#endif
134135
#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
135-
size_t text_segment_length = 0;
136+
size_t text_segment_length;
136137
#endif
137138
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
138-
uintptr_t __ptrauth_unwind_info_dwarf_section dwarf_section = 0;
139-
size_t __ptrauth_unwind_info_dwarf_section_length dwarf_section_length = 0;
139+
uintptr_t __ptrauth_unwind_uis_dwarf_section
140+
dwarf_section = 0;
141+
size_t __ptrauth_unwind_uis_dwarf_section_length
142+
dwarf_section_length = 0;
140143
#endif
141144
#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
142-
uintptr_t dwarf_index_section = 0;
143-
size_t dwarf_index_section_length = 0;
145+
uintptr_t dwarf_index_section;
146+
size_t dwarf_index_section_length;
144147
#endif
145148
#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
146-
uintptr_t __ptrauth_unwind_info_compact_unwind_section compact_unwind_section = 0;
147-
size_t __ptrauth_unwind_info_compact_unwind_section_length compact_unwind_section_length = 0;
149+
uintptr_t __ptrauth_unwind_uis_compact_unwind_section
150+
compact_unwind_section = 0;
151+
size_t __ptrauth_unwind_uis_compact_unwind_section_length
152+
compact_unwind_section_length = 0;
148153
#endif
149154
#if defined(_LIBUNWIND_ARM_EHABI)
150-
uintptr_t arm_section = 0;
151-
size_t arm_section_length = 0;
155+
uintptr_t arm_section;
156+
size_t arm_section_length;
152157
#endif
153158
};
154159

libunwind/src/DwarfParser.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ template <typename A>
3737
class CFI_Parser {
3838
public:
3939
typedef typename A::pint_t pint_t;
40-
typedef pint_t __ptrauth_unwind_cfi_personality personality_t;
40+
typedef pint_t __ptrauth_unwind_cie_info_personality personality_t;
4141

4242
/// Information encoded in a CIE (Common Information Entry)
4343
struct CIE_Info {
@@ -409,7 +409,7 @@ const char *CFI_Parser<A>::parseCIE(A &addressSpace, pint_t cie,
409409
// could avoid this by simply giving resultAddr the correct ptrauth
410410
// schema and performing an assignment.
411411
const auto discriminator = ptrauth_blend_discriminator(
412-
&cieInfo->personality, __ptrauth_unwind_cfi_personality_disc);
412+
&cieInfo->personality, __ptrauth_unwind_cie_info_personality_disc);
413413
void *signedPtr = ptrauth_auth_and_resign(
414414
(void *)personality, ptrauth_key_function_pointer, resultAddr,
415415
ptrauth_key_function_pointer, discriminator);

libunwind/src/Registers.hpp

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ class _LIBUNWIND_HIDDEN Registers_x86 {
100100

101101
typedef uint32_t reg_t;
102102
typedef uint32_t link_reg_t;
103-
void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
104-
link_reg_t *dstLinkRegister) {
105-
*dstLinkRegister = srcLinkRegister;
106-
}
107103

108104
private:
109105
struct GPRs {
@@ -325,10 +321,6 @@ class _LIBUNWIND_HIDDEN Registers_x86_64 {
325321

326322
typedef uint64_t reg_t;
327323
typedef uint64_t link_reg_t;
328-
void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
329-
link_reg_t *dstLinkRegister) {
330-
*dstLinkRegister = srcLinkRegister;
331-
}
332324

333325
private:
334326
struct GPRs {
@@ -643,10 +635,6 @@ class _LIBUNWIND_HIDDEN Registers_ppc {
643635

644636
typedef uint32_t reg_t;
645637
typedef uint32_t link_reg_t;
646-
void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
647-
link_reg_t *dstLinkRegister) {
648-
*dstLinkRegister = srcLinkRegister;
649-
}
650638

651639
private:
652640
struct ppc_thread_state_t {
@@ -1903,28 +1891,20 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
19031891
void setFP(uint64_t value) { _registers.__fp = value; }
19041892

19051893
typedef uint64_t reg_t;
1906-
typedef uint64_t __ptrauth_unwind_arm64_link_reg link_reg_t;
1894+
typedef uint64_t __ptrauth_unwind_registers_arm64_link_reg link_reg_t;
19071895

1896+
#if __has_feature(ptrauth_calls)
19081897
void
19091898
loadAndAuthenticateLinkRegister(reg_t inplaceAuthedLinkRegister,
19101899
link_reg_t *referenceAuthedLinkRegister) {
1911-
#if __has_feature(ptrauth_calls)
19121900
// If we are in an arm64/arm64e frame, then the PC should have been signed
19131901
// with the SP
1914-
*referenceAuthedLinkRegister = (uint64_t)ptrauth_auth_data(
1915-
(void *)inplaceAuthedLinkRegister,
1916-
ptrauth_key_return_address,
1917-
_registers.__sp);
1918-
#else
1919-
*referenceAuthedLinkRegister = inplaceAuthedLinkRegister;
1920-
#endif
1921-
}
1922-
1923-
// arm64_32 and i386 simulator hack
1924-
void loadAndAuthenticateLinkRegister(uint32_t srcLinkRegister,
1925-
uint32_t *dstLinkRegister) {
1926-
*dstLinkRegister = srcLinkRegister;
1902+
*referenceAuthedLinkRegister =
1903+
(uint64_t)ptrauth_auth_data((void *)inplaceAuthedLinkRegister,
1904+
ptrauth_key_return_address,
1905+
_registers.__sp);
19271906
}
1907+
#endif
19281908

19291909
private:
19301910
uint64_t lazyGetVG() const;
@@ -1966,14 +1946,14 @@ inline Registers_arm64::Registers_arm64(const void *registers) {
19661946
static_cast<const uint8_t *>(registers) + sizeof(GPRs),
19671947
sizeof(_vectorHalfRegisters));
19681948
#if __has_feature(ptrauth_calls)
1949+
// We have to do some pointer authentication fixups after this copy,
1950+
// and as part of that we need to load the source pc without
1951+
// authenticating so that we maintain the signature for the resigning
1952+
// performed by setIP.
19691953
uint64_t pcRegister = 0;
19701954
memcpy(&pcRegister, ((uint8_t *)&_registers) + offsetof(GPRs, __pc),
19711955
sizeof(pcRegister));
19721956
setIP(pcRegister);
1973-
uint64_t fpRegister = 0;
1974-
memcpy(&fpRegister, ((uint8_t *)&_registers) + offsetof(GPRs, __fp),
1975-
sizeof(fpRegister));
1976-
setFP(fpRegister);
19771957
#endif
19781958
}
19791959

@@ -1986,8 +1966,9 @@ inline Registers_arm64& Registers_arm64::operator=(const Registers_arm64& other)
19861966
memcpy(_vectorHalfRegisters, &other._vectorHalfRegisters,
19871967
sizeof(_vectorHalfRegisters));
19881968
#if __has_feature(ptrauth_calls)
1969+
// We perform this step to ensure that we correctly authenticate and re-sign
1970+
// the pc after the bitwise copy.
19891971
setIP(other.getIP());
1990-
setFP(other.getFP());
19911972
#endif
19921973
return *this;
19931974
}
@@ -2275,10 +2256,6 @@ class _LIBUNWIND_HIDDEN Registers_arm {
22752256

22762257
typedef uint32_t reg_t;
22772258
typedef uint32_t link_reg_t;
2278-
void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,
2279-
link_reg_t *dstLinkRegister) {
2280-
*dstLinkRegister = srcLinkRegister;
2281-
}
22822259

22832260
void saveVFPAsX() {
22842261
assert(_use_X_for_vfp_save || !_saved_vfp_d0_d15);

0 commit comments

Comments
 (0)