From 6e4e3468814a1cc69459616c847470c795145c56 Mon Sep 17 00:00:00 2001 From: jca <> Date: Sun, 14 Jul 2024 09:48:48 +0000 Subject: 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 --- src/regress/lib/libc/Makefile | 3 +- src/regress/lib/libc/elf_aux_info/Makefile | 3 ++ src/regress/lib/libc/elf_aux_info/elf_aux_info.c | 54 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/regress/lib/libc/elf_aux_info/Makefile create mode 100644 src/regress/lib/libc/elf_aux_info/elf_aux_info.c (limited to 'src') 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 @@ -# $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/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 @@ +PROG=elf_aux_info + +.include 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 @@ +#include + +#include +#include + +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; +} -- cgit v1.2.3-55-g6feb