Skip to content

Commit 7dde4a4

Browse files
committed
add einval condition and reviews
1 parent 2a9af0f commit 7dde4a4

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

llvm/tools/llvm-exegesis/lib/AArch64/Target.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "AArch64RegisterInfo.h"
1111

1212
#if defined(__aarch64__) && defined(__linux__)
13+
#include <errno.h>
1314
#include <linux/prctl.h> // For PR_PAC_* constants
1415
#include <sys/prctl.h>
1516
#ifndef PR_PAC_SET_ENABLED_KEYS
@@ -199,6 +200,11 @@ class ExegesisAArch64Target : public ExegesisTarget {
199200
PM.add(createAArch64ExpandPseudoPass());
200201
}
201202

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+
202208
const char *getIgnoredOpcodeReasonOrNull(const LLVMState &State,
203209
unsigned Opcode) const override {
204210
if (const char *Reason =
@@ -213,20 +219,30 @@ class ExegesisAArch64Target : public ExegesisTarget {
213219
// For systems without PAC, this is a No-op but with PAC, it is
214220
// safer to check the existing key state and then disable/enable them.
215221
// 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+
}
218232
return "Failed to get PAC key status";
219233
}
220234

221235
// Disable all PAC keys. Note that while we expect the measurements to
222236
// be the same with PAC keys disabled, they could potentially be lower
223237
// 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) {
230246
return "Failed to disable PAC keys";
231247
}
232248
}

0 commit comments

Comments
 (0)