Skip to content

Commit 8d7e526

Browse files
committed
Addressing myriad feedback
1 parent 0d482fa commit 8d7e526

File tree

7 files changed

+21
-22
lines changed

7 files changed

+21
-22
lines changed

libunwind/include/__libunwind_config.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,11 @@
7373
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC
7474
# elif defined(__aarch64__)
7575
# define _LIBUNWIND_TARGET_AARCH64 1
76-
# if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
77-
# define _LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING 1
78-
# elif __has_feature(ptrauth_calls) != __has_feature(ptrauth_returns)
79-
# #error "Either both or none of ptrauth_calls and ptrauth_returns is allowed to be enabled"
80-
# endif
81-
#define _LIBUNWIND_CONTEXT_SIZE 67
76+
# define _LIBUNWIND_CONTEXT_SIZE 67
8277
# if defined(__SEH__)
8378
# define _LIBUNWIND_CURSOR_SIZE 164
8479
# else
85-
#define _LIBUNWIND_CURSOR_SIZE 79
80+
# define _LIBUNWIND_CURSOR_SIZE 79
8681
# endif
8782
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64
8883
# elif defined(__arm__)
@@ -217,4 +212,11 @@
217212
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 287
218213
#endif // _LIBUNWIND_IS_NATIVE_ONLY
219214

215+
#if __has_feature(ptrauth_calls) && __has_feature(ptrauth_returns)
216+
# define _LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING 1
217+
#elif __has_feature(ptrauth_calls) != __has_feature(ptrauth_returns)
218+
# error "Either both or none of ptrauth_calls and ptrauth_returns "\
219+
"is allowed to be enabled"
220+
#endif
221+
220222
#endif // ____LIBUNWIND_CONFIG_H__

libunwind/include/libunwind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#define LIBUNWIND_AVAIL
4444
#endif
4545

46-
#if __has_feature(ptrauth_calls)
46+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
4747

4848
#include <ptrauth.h>
4949

libunwind/src/DwarfParser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ const char *CFI_Parser<A>::parseCIE(A &addressSpace, pint_t cie,
398398
pint_t personality = addressSpace.getEncodedP(
399399
p, cieContentEnd, cieInfo->personalityEncoding,
400400
/*datarelBase=*/0, &resultAddr);
401-
#if __has_feature(ptrauth_calls)
401+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
402402
if (personality) {
403403
// The GOT for the personality function was signed address
404404
// authenticated. Manually re-sign with the CIE_Info::personality

libunwind/src/Registers.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
18651865
void setSP(uint64_t value) { _registers.__sp = value; }
18661866
uint64_t getIP() const {
18671867
uint64_t value = _registers.__pc;
1868-
#if __has_feature(ptrauth_calls)
1868+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
18691869
// Note the value of the PC was signed to its address in the register state
18701870
// but everyone else expects it to be sign by the SP, so convert on return.
18711871
value = (uint64_t)ptrauth_auth_and_resign((void *)_registers.__pc,
@@ -1877,7 +1877,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
18771877
return value;
18781878
}
18791879
void setIP(uint64_t value) {
1880-
#if __has_feature(ptrauth_calls)
1880+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
18811881
// Note the value which was set should have been signed with the SP.
18821882
// We then resign with the slot we are being stored in to so that both SP
18831883
// and LR can't be spoofed at the same time.
@@ -1892,7 +1892,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
18921892
uint64_t getFP() const { return _registers.__fp; }
18931893
void setFP(uint64_t value) { _registers.__fp = value; }
18941894

1895-
#if __has_feature(ptrauth_calls)
1895+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
18961896
void
18971897
loadAndAuthenticateLinkRegister(reg_t inplaceAuthedLinkRegister,
18981898
link_reg_t *referenceAuthedLinkRegister) {
@@ -1944,7 +1944,7 @@ inline Registers_arm64::Registers_arm64(const void *registers) {
19441944
memcpy(_vectorHalfRegisters,
19451945
static_cast<const uint8_t *>(registers) + sizeof(GPRs),
19461946
sizeof(_vectorHalfRegisters));
1947-
#if __has_feature(ptrauth_calls)
1947+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
19481948
// We have to do some pointer authentication fixups after this copy,
19491949
// and as part of that we need to load the source pc without
19501950
// authenticating so that we maintain the signature for the resigning
@@ -1965,7 +1965,7 @@ Registers_arm64::operator=(const Registers_arm64 &other) {
19651965
memcpy(&_registers, &other._registers, sizeof(_registers));
19661966
memcpy(_vectorHalfRegisters, &other._vectorHalfRegisters,
19671967
sizeof(_vectorHalfRegisters));
1968-
#if __has_feature(ptrauth_calls)
1968+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
19691969
// We perform this step to ensure that we correctly authenticate and re-sign
19701970
// the pc after the bitwise copy.
19711971
setIP(other.getIP());

libunwind/src/UnwindCursor.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ class UnwindCursor : public AbstractUnwindCursor{
10511051
const UnwindInfoSections &sects,
10521052
uint32_t fdeSectionOffsetHint = 0);
10531053
int stepWithDwarfFDE(bool stage2) {
1054-
#if __has_feature(ptrauth_calls)
1054+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
10551055
typename R::reg_t rawPC = this->getReg(UNW_REG_IP);
10561056
typename R::link_reg_t pc;
10571057
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);
@@ -1995,7 +1995,7 @@ bool UnwindCursor<A, R>::getInfoFromCompactEncodingSection(
19951995
personalityIndex * sizeof(uint32_t));
19961996
pint_t personalityPointer = sects.dso_base + (pint_t)personalityDelta;
19971997
personality = _addressSpace.getP(personalityPointer);
1998-
#if __has_feature(ptrauth_calls)
1998+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
19991999
// The GOT for the personality function was signed address authenticated.
20002000
// Resign it as a regular function pointer.
20012001
const auto discriminator = ptrauth_blend_discriminator(
@@ -2680,7 +2680,7 @@ void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
26802680
#endif
26812681

26822682
typename R::link_reg_t pc;
2683-
#if __has_feature(ptrauth_calls)
2683+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
26842684
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);
26852685
#else
26862686
pc = rawPC;
@@ -3235,7 +3235,7 @@ void UnwindCursor<A, R>::getInfo(unw_proc_info_t *info) {
32353235
template <typename A, typename R>
32363236
bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,
32373237
unw_word_t *offset) {
3238-
#if __has_feature(ptrauth_calls)
3238+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
32393239
typename R::reg_t rawPC = this->getReg(UNW_REG_IP);
32403240
typename R::link_reg_t pc;
32413241
_registers.loadAndAuthenticateLinkRegister(rawPC, &pc);

libunwind/src/UnwindLevel1.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ static _Unwind_Personality_Fn get_handler_function(unw_proc_info_t *frameInfo) {
110110
// _Unwind_Personality_Fn typed local - this avoids any confused
111111
// re-signing of values that already have a signature.
112112
_Unwind_Personality_Fn handler;
113-
uintptr_t __unwind_ptrauth_restricted_intptr(ptrauth_key_function_pointer, 0,
114-
ptrauth_function_pointer_type_discriminator(_Unwind_Personality_Fn))
115-
f;
116113
memcpy(&handler, (void *)&reauthenticatedIntegerHandler,
117114
sizeof(_Unwind_Personality_Fn));
118115

libunwind/src/libunwind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ _LIBUNWIND_HIDDEN int __unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
127127

128128
pint_t sp = (pint_t)co->getReg(UNW_REG_SP);
129129

130-
#if __has_feature(ptrauth_calls)
130+
#if defined(_LIBUNWIND_TARGET_AARCH64_AUTHENTICATED_UNWINDING)
131131
{
132132
// It is only valid to set the IP within the current function.
133133
// This is important for ptrauth, otherwise the IP cannot be correctly

0 commit comments

Comments
 (0)