getauxval.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Copyright (C) 2022 Ramin Seyed Moussavi
  2. * An getauxval() function compatible with the glibc auxv.h
  3. * that is used by uClibc-ng.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public
  16. * License along with this library; if not, see
  17. * <http://www.gnu.org/licenses/>.
  18. */
  19. #include <errno.h>
  20. #include <ldso.h>
  21. #include <sys/auxv.h>
  22. unsigned long int __getauxval (unsigned long int __type)
  23. {
  24. // Requested value part of cached subset of auxiliary vector?
  25. if (__type < AUX_MAX_AT_ID) {
  26. if (_dl_auxvt[__type].a_type == __type)
  27. return _dl_auxvt[__type].a_un.a_val;
  28. __set_errno (ENOENT);
  29. return 0;
  30. }
  31. // Otherwise we have to iterate the auxiliary vector.
  32. for (ElfW(auxv_t) *entry = _dl_auxv_start; entry->a_type != AT_NULL; entry++)
  33. if (entry->a_type == __type)
  34. return entry->a_un.a_val;
  35. __set_errno (ENOENT);
  36. return 0;
  37. }
  38. weak_alias(__getauxval, getauxval)