diff options
| author | Michael Ellerman <mpe@ellerman.id.au> | 2014-07-23 03:31:39 -0400 |
|---|---|---|
| committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2014-07-28 00:11:33 -0400 |
| commit | bd8bbd87f1e4226f576ddbc71d42541418d8f2d3 (patch) | |
| tree | 267c16df9fc3bc6158c0737c11216bf5b344bfb6 /tools | |
| parent | 985ac68eba4c6487754a67401909239e0505171a (diff) | |
selftests/powerpc: Add a routine for retrieving an AUXV entry
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/testing/selftests/powerpc/pmu/lib.c | 48 | ||||
| -rw-r--r-- | tools/testing/selftests/powerpc/pmu/lib.h | 1 |
2 files changed, 49 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: | |||
| 250 | out: | 255 | out: |
| 251 | return rc; | 256 | return rc; |
| 252 | } | 257 | } |
| 258 | |||
| 259 | static char auxv[4096]; | ||
| 260 | |||
| 261 | void *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 | } | ||
| 297 | out: | ||
| 298 | close(fd); | ||
| 299 | return result; | ||
| 300 | } | ||
diff --git a/tools/testing/selftests/powerpc/pmu/lib.h b/tools/testing/selftests/powerpc/pmu/lib.h index ca5d72ae3be6..0f0339c8a6f6 100644 --- a/tools/testing/selftests/powerpc/pmu/lib.h +++ b/tools/testing/selftests/powerpc/pmu/lib.h | |||
| @@ -29,6 +29,7 @@ extern int notify_parent(union pipe write_pipe); | |||
| 29 | extern int notify_parent_of_error(union pipe write_pipe); | 29 | extern int notify_parent_of_error(union pipe write_pipe); |
| 30 | extern pid_t eat_cpu(int (test_function)(void)); | 30 | extern pid_t eat_cpu(int (test_function)(void)); |
| 31 | extern bool require_paranoia_below(int level); | 31 | extern bool require_paranoia_below(int level); |
| 32 | extern void *get_auxv_entry(int type); | ||
| 32 | 33 | ||
| 33 | struct addr_range { | 34 | struct addr_range { |
| 34 | uint64_t first, last; | 35 | uint64_t first, last; |
