Skip to content

Commit 258a5d4

Browse files
committed
[ORC][arm64e] Add PAC signing/stripping support to ExecutorAddr toPtr/fromPtr.
On arm64e, uses the "wrap" and "unwrap" operations introduced in f14cb49 to sign and strip pointers by default. Signing / striping can be overriden at the toPtr / fromPtr callside by passing an explicit wrap / unwrap operation.
1 parent 4056d93 commit 258a5d4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "llvm/Support/raw_ostream.h"
2121

2222
#include <cassert>
23+
#if __has_feature(ptrauth_calls)
24+
#include <ptrauth.h>
25+
#endif
2326
#include <type_traits>
2427

2528
namespace llvm {
@@ -33,12 +36,40 @@ class ExecutorAddr {
3336
/// A wrap/unwrap function that leaves pointers unmodified.
3437
template <typename T> using rawPtr = llvm::identity<T *>;
3538

39+
#if __has_feature(ptrauth_calls)
40+
template <typename T> class PtrauthSignDefault {
41+
public:
42+
constexpr T *operator()(T *P) {
43+
if (std::is_function_v<T>)
44+
return ptrauth_sign_unauthenticated(P, ptrauth_key_function_pointer, 0);
45+
else
46+
return P;
47+
}
48+
};
49+
50+
template <typename T> class PtrauthStripDefault {
51+
public:
52+
constexpr T *operator()(T *P) {
53+
return ptrauth_strip(P, ptrauth_key_function_pointer);
54+
}
55+
};
56+
57+
/// Default wrap function to use on this host.
58+
template <typename T> using defaultWrap = PtrauthSignDefault<T>;
59+
60+
/// Default unwrap function to use on this host.
61+
template <typename T> using defaultUnwrap = PtrauthStripDefault<T>;
62+
63+
#else
64+
3665
/// Default wrap function to use on this host.
3766
template <typename T> using defaultWrap = rawPtr<T>;
3867

3968
/// Default unwrap function to use on this host.
4069
template <typename T> using defaultUnwrap = rawPtr<T>;
4170

71+
#endif
72+
4273
/// Merges a tag into the raw address value:
4374
/// P' = P | (TagValue << TagOffset).
4475
class Tag {

0 commit comments

Comments
 (0)