10
10
#include " AArch64RegisterInfo.h"
11
11
12
12
#if defined(__aarch64__) && defined(__linux__)
13
+ #include < errno.h>
13
14
#include < linux/prctl.h> // For PR_PAC_* constants
14
15
#include < sys/prctl.h>
15
16
#ifndef PR_PAC_SET_ENABLED_KEYS
@@ -199,6 +200,11 @@ class ExegesisAArch64Target : public ExegesisTarget {
199
200
PM.add (createAArch64ExpandPseudoPass ());
200
201
}
201
202
203
+ static long prctl_wrapper (int op, long arg2 = 0 , long arg3 = 0 , long arg4 = 0 ,
204
+ long arg5 = 0 ) {
205
+ return prctl (op, arg2, arg3, arg4, arg5);
206
+ }
207
+
202
208
const char *getIgnoredOpcodeReasonOrNull (const LLVMState &State,
203
209
unsigned Opcode) const override {
204
210
if (const char *Reason =
@@ -213,20 +219,30 @@ class ExegesisAArch64Target : public ExegesisTarget {
213
219
// For systems without PAC, this is a No-op but with PAC, it is
214
220
// safer to check the existing key state and then disable/enable them.
215
221
// Hence the guard for switching.
216
- unsigned long PacKeys = 0 ;
217
- if (prctl (PR_PAC_GET_ENABLED_KEYS, &PacKeys, 0 , 0 , 0 ) < 0 ) {
222
+ errno = 0 ;
223
+ unsigned long PacKeys = prctl_wrapper (PR_PAC_GET_ENABLED_KEYS,
224
+ 0 , // unused
225
+ 0 , // unused
226
+ 0 , // unused
227
+ 0 ); // unused
228
+ if ((long )PacKeys < 0 ) {
229
+ if (errno == EINVAL) {
230
+ return " PAuth not supported on this system" ;
231
+ }
218
232
return " Failed to get PAC key status" ;
219
233
}
220
234
221
235
// Disable all PAC keys. Note that while we expect the measurements to
222
236
// be the same with PAC keys disabled, they could potentially be lower
223
237
// since authentication checks are bypassed.
224
- if (PacKeys != 0 ) {
225
- if (prctl (PR_PAC_SET_ENABLED_KEYS,
226
- PR_PAC_APIAKEY | PR_PAC_APIBKEY | PR_PAC_APDAKEY |
227
- PR_PAC_APDBKEY, // all keys
228
- 0 , // disable all
229
- 0 , 0 ) < 0 ) {
238
+ if ((long )PacKeys != 0 ) {
239
+ if (prctl_wrapper (PR_PAC_SET_ENABLED_KEYS,
240
+ PR_PAC_APIAKEY | PR_PAC_APIBKEY | PR_PAC_APDAKEY |
241
+ PR_PAC_APDBKEY, // all keys
242
+ 0 , // disable all
243
+ 0 , // unused
244
+ 0 ) // unused
245
+ < 0 ) {
230
246
return " Failed to disable PAC keys" ;
231
247
}
232
248
}
0 commit comments