diff options
author | jca <> | 2024-07-14 09:48:48 +0000 |
---|---|---|
committer | jca <> | 2024-07-14 09:48:48 +0000 |
commit | 6e4e3468814a1cc69459616c847470c795145c56 (patch) | |
tree | 5b5768ccd48696ee654af644197e062397b95943 | |
parent | 1865a7dd7998fa67b6effbc9e1ae22f019dc22c8 (diff) | |
download | openbsd-6e4e3468814a1cc69459616c847470c795145c56.tar.gz openbsd-6e4e3468814a1cc69459616c847470c795145c56.tar.bz2 openbsd-6e4e3468814a1cc69459616c847470c795145c56.zip |
Add elf_aux_info(3)
Designed to let userland peek at AT_HWCAP and AT_HWCAP2 using an already
existing interface coming from FreeBSD. Headers bits were snatched from
there. Input & ok kettenis@
libc bump and sets sync will follow soon
-rw-r--r-- | src/regress/lib/libc/Makefile | 3 | ||||
-rw-r--r-- | src/regress/lib/libc/elf_aux_info/Makefile | 3 | ||||
-rw-r--r-- | src/regress/lib/libc/elf_aux_info/elf_aux_info.c | 54 |
3 files changed, 59 insertions, 1 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile index 8b5e4d4503..3cd970e49d 100644 --- a/src/regress/lib/libc/Makefile +++ b/src/regress/lib/libc/Makefile | |||
@@ -1,10 +1,11 @@ | |||
1 | # $OpenBSD: Makefile,v 1.58 2021/08/31 09:58:17 jasper Exp $ | 1 | # $OpenBSD: Makefile,v 1.59 2024/07/14 09:48:48 jca Exp $ |
2 | 2 | ||
3 | SUBDIR+= _setjmp | 3 | SUBDIR+= _setjmp |
4 | SUBDIR+= alloca arc4random-fork atexit | 4 | SUBDIR+= alloca arc4random-fork atexit |
5 | SUBDIR+= basename | 5 | SUBDIR+= basename |
6 | SUBDIR+= cephes cxa-atexit | 6 | SUBDIR+= cephes cxa-atexit |
7 | SUBDIR+= db dirname | 7 | SUBDIR+= db dirname |
8 | SUBDIR+= elf_aux_info | ||
8 | SUBDIR+= env explicit_bzero | 9 | SUBDIR+= env explicit_bzero |
9 | SUBDIR+= ffs fmemopen fnmatch fpclassify fread | 10 | SUBDIR+= ffs fmemopen fnmatch fpclassify fread |
10 | SUBDIR+= gcvt getaddrinfo getcap getopt getopt_long glob | 11 | SUBDIR+= gcvt getaddrinfo getcap getopt getopt_long glob |
diff --git a/src/regress/lib/libc/elf_aux_info/Makefile b/src/regress/lib/libc/elf_aux_info/Makefile new file mode 100644 index 0000000000..2885fb1851 --- /dev/null +++ b/src/regress/lib/libc/elf_aux_info/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | PROG=elf_aux_info | ||
2 | |||
3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/elf_aux_info/elf_aux_info.c b/src/regress/lib/libc/elf_aux_info/elf_aux_info.c new file mode 100644 index 0000000000..481085d6d9 --- /dev/null +++ b/src/regress/lib/libc/elf_aux_info/elf_aux_info.c | |||
@@ -0,0 +1,54 @@ | |||
1 | #include <sys/auxv.h> | ||
2 | |||
3 | #include <errno.h> | ||
4 | #include <stdio.h> | ||
5 | |||
6 | int | ||
7 | main(void) | ||
8 | { | ||
9 | int ret = 0; | ||
10 | int a; | ||
11 | unsigned long b; | ||
12 | |||
13 | |||
14 | /* Should always succeed */ | ||
15 | if (elf_aux_info(AT_PAGESZ, &a, sizeof(a))) | ||
16 | ret |= 1; | ||
17 | else | ||
18 | fprintf(stderr, "AT_PAGESZ %d\n", a); | ||
19 | |||
20 | /* Wrong size */ | ||
21 | if (elf_aux_info(AT_PAGESZ, &b, sizeof(b)) != EINVAL) | ||
22 | ret |= 2; | ||
23 | |||
24 | /* Invalid request */ | ||
25 | if (elf_aux_info(-1, &a, sizeof(a)) != EINVAL) | ||
26 | ret |= 4; | ||
27 | |||
28 | /* Should either succeed or fail with ENOENT if not supported */ | ||
29 | switch (elf_aux_info(AT_HWCAP, &b, sizeof(b))) { | ||
30 | case 0: | ||
31 | fprintf(stderr, "AT_HWCAP %lx\n", b); | ||
32 | break; | ||
33 | case ENOENT: | ||
34 | break; | ||
35 | default: | ||
36 | ret |= 8; | ||
37 | } | ||
38 | |||
39 | /* Should either succeed or fail with ENOENT if not supported */ | ||
40 | switch (elf_aux_info(AT_HWCAP2, &b, sizeof(b))) { | ||
41 | case 0: | ||
42 | fprintf(stderr, "AT_HWCAP2 %lx\n", b); | ||
43 | break; | ||
44 | case ENOENT: | ||
45 | break; | ||
46 | default: | ||
47 | ret |= 16; | ||
48 | } | ||
49 | |||
50 | if (ret) | ||
51 | fprintf(stderr, "FAILED (status %x)\n", ret); | ||
52 | |||
53 | return ret; | ||
54 | } | ||