summaryrefslogtreecommitdiff
path: root/libc/misc
diff options
context:
space:
mode:
authorGeorg Kotheimer <georg.kotheimer@kernkonzept.com>2025-03-03 16:41:14 +0100
committerWaldemar Brodkorb <wbx@openadk.org>2025-03-04 07:43:56 +0100
commit737a0edf4d2d52c6c2836ffe24c7143b63498123 (patch)
tree6eaa7464c70ef9a9bb088f36a20b8bda20b86174 /libc/misc
parent227b7c825b6c79479f7222be03e83991b927da26 (diff)
Support non-cached entries in getauxval
Previously the getauxval implementation was limited to the auxiliary vector entries cached in _dl_auxvt. To also support entries outside of that cached subset, store the start address of the auxiliary vector, and if an uncached entry type is encountered search the entire auxiliary vector. Signed-off-by: Marcus Haehnel <marcus.haehnel@kernkonzept.com>
Diffstat (limited to 'libc/misc')
-rwxr-xr-xlibc/misc/auxvt/getauxval.c30
-rw-r--r--libc/misc/elf/dl-support.c3
2 files changed, 16 insertions, 17 deletions
diff --git a/libc/misc/auxvt/getauxval.c b/libc/misc/auxvt/getauxval.c
index 2bdffaf2c..7610b7e5c 100755
--- a/libc/misc/auxvt/getauxval.c
+++ b/libc/misc/auxvt/getauxval.c
@@ -17,32 +17,28 @@
* <http://www.gnu.org/licenses/>.
*/
-#include "errno.h"
-#include "ldso.h"
-#include "sys/auxv.h"
+#include <errno.h>
+#include <ldso.h>
+#include <sys/auxv.h>
-
-/*
- *
- * aarch64 gcc 11 uses __getauxval() in init_have_lse_atomics()
- *
- */
unsigned long int __getauxval (unsigned long int __type)
{
- if ( __type >= AUX_MAX_AT_ID ){
+ // Requested value part of cached subset of auxiliary vector?
+ if (__type < AUX_MAX_AT_ID) {
+ if (_dl_auxvt[__type].a_type == __type)
+ return _dl_auxvt[__type].a_un.a_val;
+
__set_errno (ENOENT);
return 0;
}
- if ( _dl_auxvt[__type].a_type == __type){
- return _dl_auxvt[__type].a_un.a_val;
- }
+ // Otherwise we have to iterate the auxiliary vector.
+ for (ElfW(auxv_t) *entry = _dl_auxv_start; entry->a_type != AT_NULL; entry++)
+ if (entry->a_type == __type)
+ return entry->a_un.a_val;
__set_errno (ENOENT);
return 0;
}
-unsigned long int getauxval (unsigned long int __type){
- return __getauxval( __type );
-}
-
+weak_alias(__getauxval, getauxval)
diff --git a/libc/misc/elf/dl-support.c b/libc/misc/elf/dl-support.c
index 81c78fa55..09cbefc18 100644
--- a/libc/misc/elf/dl-support.c
+++ b/libc/misc/elf/dl-support.c
@@ -33,10 +33,13 @@ size_t _dl_phnum;
size_t _dl_pagesize;
ElfW(auxv_t) _dl_auxvt[AUX_MAX_AT_ID];
+ElfW(auxv_t) *_dl_auxv_start;
void internal_function _dl_aux_init (ElfW(auxv_t) *av);
void internal_function _dl_aux_init (ElfW(auxv_t) *av)
{
+ _dl_auxv_start = av;
+
memset(_dl_auxvt, 0x00, sizeof(_dl_auxvt));
for (; av->a_type != AT_NULL; av++)
{