dlinfo.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* dlinfo -- Get information from the dynamic linker.
  2. Copyright (C) 2003-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <dlfcn.h>
  16. #include <link.h>
  17. #include <ldsodefs.h>
  18. #include <libintl.h>
  19. #include <dl-tls.h>
  20. #include <shlib-compat.h>
  21. struct dlinfo_args
  22. {
  23. void *handle;
  24. int request;
  25. void *arg;
  26. /* This is the value that is returned from dlinfo if no error is
  27. signaled. */
  28. int result;
  29. };
  30. static void
  31. dlinfo_doit (void *argsblock)
  32. {
  33. struct dlinfo_args *const args = argsblock;
  34. struct link_map *l = args->handle;
  35. switch (args->request)
  36. {
  37. case RTLD_DI_CONFIGADDR:
  38. default:
  39. args->result = -1;
  40. _dl_signal_error (0, NULL, NULL, N_("unsupported dlinfo request"));
  41. break;
  42. case RTLD_DI_LMID:
  43. *(Lmid_t *) args->arg = l->l_ns;
  44. break;
  45. case RTLD_DI_LINKMAP:
  46. *(struct link_map **) args->arg = l;
  47. break;
  48. case RTLD_DI_SERINFO:
  49. _dl_rtld_di_serinfo (l, args->arg, false);
  50. break;
  51. case RTLD_DI_SERINFOSIZE:
  52. _dl_rtld_di_serinfo (l, args->arg, true);
  53. break;
  54. case RTLD_DI_ORIGIN:
  55. strcpy (args->arg, l->l_origin);
  56. break;
  57. case RTLD_DI_TLS_MODID:
  58. *(size_t *) args->arg = 0;
  59. *(size_t *) args->arg = l->l_tls_modid;
  60. break;
  61. case RTLD_DI_TLS_DATA:
  62. {
  63. void *data = NULL;
  64. if (l->l_tls_modid != 0)
  65. data = GLRO(dl_tls_get_addr_soft) (l);
  66. *(void **) args->arg = data;
  67. break;
  68. }
  69. case RTLD_DI_PHDR:
  70. *(const ElfW(Phdr) **) args->arg = l->l_phdr;
  71. args->result = l->l_phnum;
  72. break;
  73. }
  74. }
  75. static int
  76. dlinfo_implementation (void *handle, int request, void *arg)
  77. {
  78. struct dlinfo_args args = { handle, request, arg };
  79. _dlerror_run (&dlinfo_doit, &args);
  80. return args.result;
  81. }
  82. #ifdef SHARED
  83. int
  84. ___dlinfo (void *handle, int request, void *arg)
  85. {
  86. if (GLRO (dl_dlfcn_hook) != NULL)
  87. return GLRO (dl_dlfcn_hook)->dlinfo (handle, request, arg);
  88. else
  89. return dlinfo_implementation (handle, request, arg);
  90. }
  91. versioned_symbol (libc, ___dlinfo, dlinfo, GLIBC_2_34);
  92. # if OTHER_SHLIB_COMPAT (libdl, GLIBC_2_3_3, GLIBC_2_34)
  93. compat_symbol (libc, ___dlinfo, dlinfo, GLIBC_2_3_3);
  94. # endif
  95. #else /* !SHARED */
  96. /* Also used with _dlfcn_hook. */
  97. int
  98. __dlinfo (void *handle, int request, void *arg)
  99. {
  100. return dlinfo_implementation (handle, request, arg);
  101. }
  102. weak_alias (__dlinfo, dlinfo)
  103. #endif