Back to index

glibc  2.9
dlopenold.c
Go to the documentation of this file.
00001 /* Load a shared object at run time.
00002    Copyright (C) 1995-1999, 2000, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <dlfcn.h>
00021 #include <stddef.h>
00022 #include <unistd.h>
00023 #include <ldsodefs.h>
00024 
00025 /* This file is for compatibility with glibc 2.0.  Compile it only if
00026    versioning is used.  */
00027 #include <shlib-compat.h>
00028 #if SHLIB_COMPAT (libdl, GLIBC_2_0, GLIBC_2_1)
00029 
00030 struct dlopen_args
00031 {
00032   /* The arguments for dlopen_doit.  */
00033   const char *file;
00034   int mode;
00035   /* The return value of dlopen_doit.  */
00036   void *new;
00037   /* Address of the caller.  */
00038   const void *caller;
00039 };
00040 
00041 
00042 /* Non-shared code has no support for multiple namespaces.  */
00043 #ifdef SHARED
00044 # define NS __LM_ID_CALLER
00045 #else
00046 # define NS LM_ID_BASE
00047 #endif
00048 
00049 
00050 static void
00051 dlopen_doit (void *a)
00052 {
00053   struct dlopen_args *args = (struct dlopen_args *) a;
00054 
00055   args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,
00056                           args->caller,
00057                           args->file == NULL ? LM_ID_BASE : NS,
00058                           __dlfcn_argc, __dlfcn_argv, __environ);
00059 }
00060 
00061 extern void *__dlopen_nocheck (const char *file, int mode);
00062 void *
00063 __dlopen_nocheck (const char *file, int mode)
00064 {
00065   struct dlopen_args args;
00066   args.file = file;
00067   args.caller = RETURN_ADDRESS (0);
00068 
00069   if ((mode & RTLD_BINDING_MASK) == 0)
00070     /* By default assume RTLD_LAZY.  */
00071     mode |= RTLD_LAZY;
00072   args.mode = mode;
00073 
00074   if (__builtin_expect (_dlfcn_hook != NULL, 0))
00075     return _dlfcn_hook->dlopen (file, mode, RETURN_ADDRESS (0));
00076 
00077   return _dlerror_run (dlopen_doit, &args) ? NULL : args.new;
00078 }
00079 compat_symbol (libdl, __dlopen_nocheck, dlopen, GLIBC_2_0);
00080 #endif