2 * Check decoding of perf_event_open syscall.
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016-2018 The strace developers.
8 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include <asm/unistd.h>
14 #if defined(__NR_perf_event_open) && defined(HAVE_LINUX_PERF_EVENT_H)
20 # include <linux/perf_event.h>
23 # include "xlat/perf_event_open_flags.h"
25 #if ULONG_MAX > UINT_MAX
26 #define LONG_STR_PREFIX "ffffffff"
28 #define LONG_STR_PREFIX ""
31 static const char *printaddr(void *ptr)
33 static char buf[sizeof("0x") + sizeof(void *) * 2];
38 snprintf(buf, sizeof(buf), "%#lx", (unsigned long)ptr);
46 TAIL_ALLOC_OBJECT_CONST_PTR(struct perf_event_attr, attr);
48 attr->type = PERF_TYPE_HARDWARE;
49 attr->size = sizeof(*attr);
52 struct perf_event_attr *attr;
57 const char *flags_str;
59 { NULL, 0xfacef00d, 0xbadabba7, -1,
60 (unsigned long) 0xFFFFFFFFFFFFFFFFLLU,
61 "PERF_FLAG_FD_NO_GROUP|PERF_FLAG_FD_OUTPUT|"
62 "PERF_FLAG_PID_CGROUP|PERF_FLAG_FD_CLOEXEC|"
63 "0x" LONG_STR_PREFIX "fffffff0"
68 PERF_FLAG_FD_CLOEXEC, "PERF_FLAG_FD_CLOEXEC" },
69 { attr - 1, -100, 100, 0xface1e55,
70 PERF_FLAG_FD_NO_GROUP | PERF_FLAG_FD_OUTPUT |
71 PERF_FLAG_PID_CGROUP | PERF_FLAG_FD_CLOEXEC,
72 "PERF_FLAG_FD_NO_GROUP|PERF_FLAG_FD_OUTPUT|"
73 "PERF_FLAG_PID_CGROUP|PERF_FLAG_FD_CLOEXEC" },
78 for (i = 0; i < ARRAY_SIZE(args); i++) {
79 rc = syscall(__NR_perf_event_open, args[i].attr, args[i].pid,
80 args[i].cpu, args[i].group_fd, args[i].flags);
81 printf("perf_event_open(%s, %d, %d, %d, %s) = %s\n",
82 printaddr(args[i].attr), args[i].pid, args[i].cpu,
83 args[i].group_fd, args[i].flags_str, sprintrc(rc));
86 puts("+++ exited with 0 +++");
92 SKIP_MAIN_UNDEFINED("__NR_perf_event_open && HAVE_LINUX_PERF_EVENT_H");