aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/powerpc/pmu/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/selftests/powerpc/pmu/lib.c')
-rw-r--r--tools/testing/selftests/powerpc/pmu/lib.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/testing/selftests/powerpc/pmu/lib.c b/tools/testing/selftests/powerpc/pmu/lib.c
index 11e26e8cf33a..9768dea37bf3 100644
--- a/tools/testing/selftests/powerpc/pmu/lib.c
+++ b/tools/testing/selftests/powerpc/pmu/lib.c
@@ -5,10 +5,15 @@
5 5
6#define _GNU_SOURCE /* For CPU_ZERO etc. */ 6#define _GNU_SOURCE /* For CPU_ZERO etc. */
7 7
8#include <elf.h>
8#include <errno.h> 9#include <errno.h>
10#include <fcntl.h>
11#include <link.h>
9#include <sched.h> 12#include <sched.h>
10#include <setjmp.h> 13#include <setjmp.h>
11#include <stdlib.h> 14#include <stdlib.h>
15#include <sys/stat.h>
16#include <sys/types.h>
12#include <sys/wait.h> 17#include <sys/wait.h>
13 18
14#include "utils.h" 19#include "utils.h"
@@ -250,3 +255,46 @@ out_close:
250out: 255out:
251 return rc; 256 return rc;
252} 257}
258
259static char auxv[4096];
260
261void *get_auxv_entry(int type)
262{
263 ElfW(auxv_t) *p;
264 void *result;
265 ssize_t num;
266 int fd;
267
268 fd = open("/proc/self/auxv", O_RDONLY);
269 if (fd == -1) {
270 perror("open");
271 return NULL;
272 }
273
274 result = NULL;
275
276 num = read(fd, auxv, sizeof(auxv));
277 if (num < 0) {
278 perror("read");
279 goto out;
280 }
281
282 if (num > sizeof(auxv)) {
283 printf("Overflowed auxv buffer\n");
284 goto out;
285 }
286
287 p = (ElfW(auxv_t) *)auxv;
288
289 while (p->a_type != AT_NULL) {
290 if (p->a_type == type) {
291 result = (void *)p->a_un.a_val;
292 break;
293 }
294
295 p++;
296 }
297out:
298 close(fd);
299 return result;
300}