dlopenold.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Load a shared object at run time.
  2. Copyright (C) 1995-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 <stddef.h>
  17. #include <unistd.h>
  18. #include <ldsodefs.h>
  19. /* This file is for compatibility with glibc 2.0. Compile it only if
  20. versioning is used. */
  21. #include <shlib-compat.h>
  22. #if OTHER_SHLIB_COMPAT (libdl, GLIBC_2_0, GLIBC_2_1)
  23. struct dlopen_args
  24. {
  25. /* The arguments for dlopen_doit. */
  26. const char *file;
  27. int mode;
  28. /* The return value of dlopen_doit. */
  29. void *new;
  30. /* Address of the caller. */
  31. const void *caller;
  32. };
  33. /* Non-shared code has no support for multiple namespaces. */
  34. #ifdef SHARED
  35. # define NS __LM_ID_CALLER
  36. #else
  37. # define NS LM_ID_BASE
  38. #endif
  39. static void
  40. dlopen_doit (void *a)
  41. {
  42. struct dlopen_args *args = (struct dlopen_args *) a;
  43. args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,
  44. args->caller,
  45. args->file == NULL ? LM_ID_BASE : NS,
  46. __libc_argc, __libc_argv, __environ);
  47. }
  48. extern void *__dlopen_nocheck (const char *file, int mode);
  49. void *
  50. __dlopen_nocheck (const char *file, int mode)
  51. {
  52. struct dlopen_args args;
  53. args.file = file;
  54. args.caller = RETURN_ADDRESS (0);
  55. if ((mode & RTLD_BINDING_MASK) == 0)
  56. /* By default assume RTLD_LAZY. */
  57. mode |= RTLD_LAZY;
  58. args.mode = mode;
  59. if (GLRO (dl_dlfcn_hook) != NULL)
  60. return GLRO (dl_dlfcn_hook)->dlopen (file, mode, RETURN_ADDRESS (0));
  61. return _dlerror_run (dlopen_doit, &args) ? NULL : args.new;
  62. }
  63. compat_symbol (libdl, __dlopen_nocheck, dlopen, GLIBC_2_0);
  64. #endif