diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2024-07-14 09:48:50 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2024-07-14 09:48:50 +0000 |
commit | 5d97d781354fd9a672facbf67e35e6f5413c055b (patch) | |
tree | 2471113964071307bad212f25e1383074cb898ea /regress/lib/libc | |
parent | ca37f40c3a8a098c1b9c69645a39c675aeb5cac1 (diff) |
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
Diffstat (limited to 'regress/lib/libc')
-rw-r--r-- | regress/lib/libc/Makefile | 3 | ||||
-rw-r--r-- | regress/lib/libc/elf_aux_info/Makefile | 3 | ||||
-rw-r--r-- | regress/lib/libc/elf_aux_info/elf_aux_info.c | 54 |
3 files changed, 59 insertions, 1 deletions
diff --git a/regress/lib/libc/Makefile b/regress/lib/libc/Makefile index 8b5e4d45034..3cd970e49d5 100644 --- a/regress/lib/libc/Makefile +++ b/regress/lib/libc/Makefile @@ -1,10 +1,11 @@ -# $OpenBSD: Makefile,v 1.58 2021/08/31 09:58:17 jasper Exp $ +# $OpenBSD: Makefile,v 1.59 2024/07/14 09:48:48 jca Exp $ SUBDIR+= _setjmp SUBDIR+= alloca arc4random-fork atexit SUBDIR+= basename SUBDIR+= cephes cxa-atexit SUBDIR+= db dirname +SUBDIR+= elf_aux_info SUBDIR+= env explicit_bzero SUBDIR+= ffs fmemopen fnmatch fpclassify fread SUBDIR+= gcvt getaddrinfo getcap getopt getopt_long glob diff --git a/regress/lib/libc/elf_aux_info/Makefile b/regress/lib/libc/elf_aux_info/Makefile new file mode 100644 index 00000000000..2885fb18512 --- /dev/null +++ b/regress/lib/libc/elf_aux_info/Makefile @@ -0,0 +1,3 @@ +PROG=elf_aux_info + +.include <bsd.regress.mk> diff --git a/regress/lib/libc/elf_aux_info/elf_aux_info.c b/regress/lib/libc/elf_aux_info/elf_aux_info.c new file mode 100644 index 00000000000..481085d6d97 --- /dev/null +++ b/regress/lib/libc/elf_aux_info/elf_aux_info.c @@ -0,0 +1,54 @@ +#include <sys/auxv.h> + +#include <errno.h> +#include <stdio.h> + +int +main(void) +{ + int ret = 0; + int a; + unsigned long b; + + + /* Should always succeed */ + if (elf_aux_info(AT_PAGESZ, &a, sizeof(a))) + ret |= 1; + else + fprintf(stderr, "AT_PAGESZ %d\n", a); + + /* Wrong size */ + if (elf_aux_info(AT_PAGESZ, &b, sizeof(b)) != EINVAL) + ret |= 2; + + /* Invalid request */ + if (elf_aux_info(-1, &a, sizeof(a)) != EINVAL) + ret |= 4; + + /* Should either succeed or fail with ENOENT if not supported */ + switch (elf_aux_info(AT_HWCAP, &b, sizeof(b))) { + case 0: + fprintf(stderr, "AT_HWCAP %lx\n", b); + break; + case ENOENT: + break; + default: + ret |= 8; + } + + /* Should either succeed or fail with ENOENT if not supported */ + switch (elf_aux_info(AT_HWCAP2, &b, sizeof(b))) { + case 0: + fprintf(stderr, "AT_HWCAP2 %lx\n", b); + break; + case ENOENT: + break; + default: + ret |= 16; + } + + if (ret) + fprintf(stderr, "FAILED (status %x)\n", ret); + + return ret; +} |