Skip to content

Commit 0d10ee4

Browse files
add always inline attribute to the update_pc.
also move define the descriminator instead of magic value.
1 parent b40594b commit 0d10ee4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

libunwind/src/Registers.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,8 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
18291829
struct GPRs;
18301830

18311831
private:
1832+
#define PAC_DISCRIMINATOR ((uint16_t)0xFACEU)
1833+
18321834
#if defined(_LIBUNWIND_AARCH64_PC_PROTECTION)
18331835
/// The program counter is effectively used as a return address when the
18341836
/// context is restored; therefore, it should be protected with PAC to prevent
@@ -1901,14 +1903,13 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
19011903
__libunwind_ptrauth_auth_data(pointer, oldKey, oldDiscriminator),
19021904
newKey, newDiscriminator);
19031905
}
1904-
#define __libunwind_ptrauth_blend_discriminator(__ptr, __data) \
1905-
ptrauth_blend_discriminator(__ptr, __data)
1906-
#endif
19071906
inline uint64_t
1908-
__libunwind_ptrauth_blend_discriminator(uint64_t __ptr,
1907+
__libunwind_ptrauth_blend_discriminator(const void *__ptr,
19091908
uint16_t __data) const {
1910-
return (__ptr & (~0 >> 16)) | ((uint64_t)__data << 48);
1909+
return (reinterpret_cast<uint64_t>(__ptr) & (~0 >> 16)) |
1910+
((uint64_t)__data << 48);
19111911
}
1912+
#endif
19121913
// Authenticate the currently stored PC and return it's raw value.
19131914
inline uint64_t authPC(const struct GPRs *gprs,
19141915
uint64_t discriminator) const {
@@ -1920,7 +1921,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
19201921
}
19211922

19221923
// Sign and store the new PC.
1923-
inline void updatePC(uint64_t value) {
1924+
inline void updatePC(uint64_t value) __attribute__((always_inline)) {
19241925
_registers.__pc = (uint64_t)__libunwind_ptrauth_sign_unauthenticated(
19251926
(void *)(value & (((uint64_t)~0) >> 32)), ptrauth_key_asia,
19261927
getDiscriminator());
@@ -1940,7 +1941,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
19401941
}
19411942
#else //! defined(_LIBUNWIND_AARCH64_PC_PROTECTION))
19421943
inline uint64_t
1943-
__libunwind_ptrauth_blend_discriminator(uint64_t __ptr,
1944+
__libunwind_ptrauth_blend_discriminator(const void *__ptr,
19441945
uint16_t __data) const {
19451946
(void)__data;
19461947
return __ptr;
@@ -1956,8 +1957,7 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
19561957
#endif
19571958

19581959
inline uint64_t getDiscriminator() const {
1959-
return __libunwind_ptrauth_blend_discriminator(
1960-
reinterpret_cast<uint64_t>(this), 0xface);
1960+
return __libunwind_ptrauth_blend_discriminator(this, PAC_DISCRIMINATOR);
19611961
}
19621962

19631963
public:
@@ -2030,8 +2030,8 @@ inline Registers_arm64::Registers_arm64(const void *registers) {
20302030
"expected VFP registers to be at offset 272");
20312031
#endif
20322032
// getcontext signs the PC with the base address of the context.
2033-
resignPC(__libunwind_ptrauth_blend_discriminator(
2034-
reinterpret_cast<uint64_t>(registers), 0xface));
2033+
resignPC(
2034+
__libunwind_ptrauth_blend_discriminator(registers, PAC_DISCRIMINATOR));
20352035
memcpy(_vectorHalfRegisters,
20362036
static_cast<const uint8_t *>(registers) + sizeof(GPRs),
20372037
sizeof(_vectorHalfRegisters));

0 commit comments

Comments
 (0)