1*53ee8cc1Swenshuai.xi /* User functions for run-time dynamic loading. 2*53ee8cc1Swenshuai.xi Copyright (C) 1995-1999,2000,2001,2003,2004,2006 3*53ee8cc1Swenshuai.xi Free Software Foundation, Inc. 4*53ee8cc1Swenshuai.xi This file is part of the GNU C Library. 5*53ee8cc1Swenshuai.xi 6*53ee8cc1Swenshuai.xi The GNU C Library is free software; you can redistribute it and/or 7*53ee8cc1Swenshuai.xi modify it under the terms of the GNU Lesser General Public 8*53ee8cc1Swenshuai.xi License as published by the Free Software Foundation; either 9*53ee8cc1Swenshuai.xi version 2.1 of the License, or (at your option) any later version. 10*53ee8cc1Swenshuai.xi 11*53ee8cc1Swenshuai.xi The GNU C Library is distributed in the hope that it will be useful, 12*53ee8cc1Swenshuai.xi but WITHOUT ANY WARRANTY; without even the implied warranty of 13*53ee8cc1Swenshuai.xi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14*53ee8cc1Swenshuai.xi Lesser General Public License for more details. 15*53ee8cc1Swenshuai.xi 16*53ee8cc1Swenshuai.xi You should have received a copy of the GNU Lesser General Public 17*53ee8cc1Swenshuai.xi License along with the GNU C Library; if not, write to the Free 18*53ee8cc1Swenshuai.xi Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19*53ee8cc1Swenshuai.xi 02111-1307 USA. */ 20*53ee8cc1Swenshuai.xi 21*53ee8cc1Swenshuai.xi #ifndef _DLFCN_H 22*53ee8cc1Swenshuai.xi #define _DLFCN_H 1 23*53ee8cc1Swenshuai.xi 24*53ee8cc1Swenshuai.xi #include <features.h> 25*53ee8cc1Swenshuai.xi #define __need_size_t 26*53ee8cc1Swenshuai.xi #include <stddef.h> 27*53ee8cc1Swenshuai.xi 28*53ee8cc1Swenshuai.xi /* Collect various system dependent definitions and declarations. */ 29*53ee8cc1Swenshuai.xi #include <bits/dlfcn.h> 30*53ee8cc1Swenshuai.xi 31*53ee8cc1Swenshuai.xi 32*53ee8cc1Swenshuai.xi #ifdef __USE_GNU 33*53ee8cc1Swenshuai.xi /* If the first argument of `dlsym' or `dlvsym' is set to RTLD_NEXT 34*53ee8cc1Swenshuai.xi the run-time address of the symbol called NAME in the next shared 35*53ee8cc1Swenshuai.xi object is returned. The "next" relation is defined by the order 36*53ee8cc1Swenshuai.xi the shared objects were loaded. */ 37*53ee8cc1Swenshuai.xi # define RTLD_NEXT ((void *) -1l) 38*53ee8cc1Swenshuai.xi 39*53ee8cc1Swenshuai.xi /* If the first argument to `dlsym' or `dlvsym' is set to RTLD_DEFAULT 40*53ee8cc1Swenshuai.xi the run-time address of the symbol called NAME in the global scope 41*53ee8cc1Swenshuai.xi is returned. */ 42*53ee8cc1Swenshuai.xi # define RTLD_DEFAULT ((void *) 0) 43*53ee8cc1Swenshuai.xi 44*53ee8cc1Swenshuai.xi 45*53ee8cc1Swenshuai.xi /* Type for namespace indeces. */ 46*53ee8cc1Swenshuai.xi typedef long int Lmid_t; 47*53ee8cc1Swenshuai.xi 48*53ee8cc1Swenshuai.xi /* Special namespace ID values. */ 49*53ee8cc1Swenshuai.xi # define LM_ID_BASE 0 /* Initial namespace. */ 50*53ee8cc1Swenshuai.xi # define LM_ID_NEWLM -1 /* For dlmopen: request new namespace. */ 51*53ee8cc1Swenshuai.xi #endif 52*53ee8cc1Swenshuai.xi 53*53ee8cc1Swenshuai.xi 54*53ee8cc1Swenshuai.xi __BEGIN_DECLS 55*53ee8cc1Swenshuai.xi 56*53ee8cc1Swenshuai.xi /* Open the shared object FILE and map it in; return a handle that can be 57*53ee8cc1Swenshuai.xi passed to `dlsym' to get symbol values from it. */ 58*53ee8cc1Swenshuai.xi extern void *dlopen (__const char *__file, int __mode) __THROW; 59*53ee8cc1Swenshuai.xi 60*53ee8cc1Swenshuai.xi /* Unmap and close a shared object opened by `dlopen'. 61*53ee8cc1Swenshuai.xi The handle cannot be used again after calling `dlclose'. */ 62*53ee8cc1Swenshuai.xi extern int dlclose (void *__handle) __THROW __nonnull ((1)); 63*53ee8cc1Swenshuai.xi 64*53ee8cc1Swenshuai.xi /* Find the run-time address in the shared object HANDLE refers to 65*53ee8cc1Swenshuai.xi of the symbol called NAME. */ 66*53ee8cc1Swenshuai.xi extern void *dlsym (void *__restrict __handle, 67*53ee8cc1Swenshuai.xi __const char *__restrict __name) __THROW __nonnull ((2)); 68*53ee8cc1Swenshuai.xi 69*53ee8cc1Swenshuai.xi #ifdef __USE_GNU 70*53ee8cc1Swenshuai.xi /* Like `dlopen', but request object to be allocated in a new namespace. */ 71*53ee8cc1Swenshuai.xi extern void *dlmopen (Lmid_t __nsid, __const char *__file, int __mode) __THROW; 72*53ee8cc1Swenshuai.xi 73*53ee8cc1Swenshuai.xi /* Find the run-time address in the shared object HANDLE refers to 74*53ee8cc1Swenshuai.xi of the symbol called NAME with VERSION. */ 75*53ee8cc1Swenshuai.xi extern void *dlvsym (void *__restrict __handle, 76*53ee8cc1Swenshuai.xi __const char *__restrict __name, 77*53ee8cc1Swenshuai.xi __const char *__restrict __version) 78*53ee8cc1Swenshuai.xi __THROW __nonnull ((2, 3)); 79*53ee8cc1Swenshuai.xi #endif 80*53ee8cc1Swenshuai.xi 81*53ee8cc1Swenshuai.xi /* When any of the above functions fails, call this function 82*53ee8cc1Swenshuai.xi to return a string describing the error. Each call resets 83*53ee8cc1Swenshuai.xi the error string so that a following call returns null. */ 84*53ee8cc1Swenshuai.xi extern char *dlerror (void) __THROW; 85*53ee8cc1Swenshuai.xi 86*53ee8cc1Swenshuai.xi 87*53ee8cc1Swenshuai.xi #ifdef __USE_GNU 88*53ee8cc1Swenshuai.xi /* Structure containing information about object searched using 89*53ee8cc1Swenshuai.xi `dladdr'. */ 90*53ee8cc1Swenshuai.xi typedef struct 91*53ee8cc1Swenshuai.xi { 92*53ee8cc1Swenshuai.xi __const char *dli_fname; /* File name of defining object. */ 93*53ee8cc1Swenshuai.xi void *dli_fbase; /* Load address of that object. */ 94*53ee8cc1Swenshuai.xi __const char *dli_sname; /* Name of nearest symbol. */ 95*53ee8cc1Swenshuai.xi void *dli_saddr; /* Exact value of nearest symbol. */ 96*53ee8cc1Swenshuai.xi } Dl_info; 97*53ee8cc1Swenshuai.xi 98*53ee8cc1Swenshuai.xi /* Fill in *INFO with the following information about ADDRESS. 99*53ee8cc1Swenshuai.xi Returns 0 iff no shared object's segments contain that address. */ 100*53ee8cc1Swenshuai.xi extern int dladdr (__const void *__address, Dl_info *__info) 101*53ee8cc1Swenshuai.xi __THROW __nonnull ((2)); 102*53ee8cc1Swenshuai.xi 103*53ee8cc1Swenshuai.xi /* Same as `dladdr', but additionally sets *EXTRA_INFO according to FLAGS. */ 104*53ee8cc1Swenshuai.xi extern int dladdr1 (__const void *__address, Dl_info *__info, 105*53ee8cc1Swenshuai.xi void **__extra_info, int __flags) __THROW __nonnull ((2)); 106*53ee8cc1Swenshuai.xi 107*53ee8cc1Swenshuai.xi /* These are the possible values for the FLAGS argument to `dladdr1'. 108*53ee8cc1Swenshuai.xi This indicates what extra information is stored at *EXTRA_INFO. 109*53ee8cc1Swenshuai.xi It may also be zero, in which case the EXTRA_INFO argument is not used. */ 110*53ee8cc1Swenshuai.xi enum 111*53ee8cc1Swenshuai.xi { 112*53ee8cc1Swenshuai.xi /* Matching symbol table entry (const ElfNN_Sym *). */ 113*53ee8cc1Swenshuai.xi RTLD_DL_SYMENT = 1, 114*53ee8cc1Swenshuai.xi 115*53ee8cc1Swenshuai.xi /* The object containing the address (struct link_map *). */ 116*53ee8cc1Swenshuai.xi RTLD_DL_LINKMAP = 2 117*53ee8cc1Swenshuai.xi }; 118*53ee8cc1Swenshuai.xi 119*53ee8cc1Swenshuai.xi 120*53ee8cc1Swenshuai.xi /* Get information about the shared object HANDLE refers to. 121*53ee8cc1Swenshuai.xi REQUEST is from among the values below, and determines the use of ARG. 122*53ee8cc1Swenshuai.xi 123*53ee8cc1Swenshuai.xi On success, returns zero. On failure, returns -1 and records an error 124*53ee8cc1Swenshuai.xi message to be fetched with `dlerror'. */ 125*53ee8cc1Swenshuai.xi extern int dlinfo (void *__restrict __handle, 126*53ee8cc1Swenshuai.xi int __request, void *__restrict __arg) 127*53ee8cc1Swenshuai.xi __THROW __nonnull ((1, 3)); 128*53ee8cc1Swenshuai.xi 129*53ee8cc1Swenshuai.xi /* These are the possible values for the REQUEST argument to `dlinfo'. */ 130*53ee8cc1Swenshuai.xi enum 131*53ee8cc1Swenshuai.xi { 132*53ee8cc1Swenshuai.xi /* Treat ARG as `lmid_t *'; store namespace ID for HANDLE there. */ 133*53ee8cc1Swenshuai.xi RTLD_DI_LMID = 1, 134*53ee8cc1Swenshuai.xi 135*53ee8cc1Swenshuai.xi /* Treat ARG as `struct link_map **'; 136*53ee8cc1Swenshuai.xi store the `struct link_map *' for HANDLE there. */ 137*53ee8cc1Swenshuai.xi RTLD_DI_LINKMAP = 2, 138*53ee8cc1Swenshuai.xi 139*53ee8cc1Swenshuai.xi RTLD_DI_CONFIGADDR = 3, /* Unsupported, defined by Solaris. */ 140*53ee8cc1Swenshuai.xi 141*53ee8cc1Swenshuai.xi /* Treat ARG as `Dl_serinfo *' (see below), and fill in to describe the 142*53ee8cc1Swenshuai.xi directories that will be searched for dependencies of this object. 143*53ee8cc1Swenshuai.xi RTLD_DI_SERINFOSIZE fills in just the `dls_cnt' and `dls_size' 144*53ee8cc1Swenshuai.xi entries to indicate the size of the buffer that must be passed to 145*53ee8cc1Swenshuai.xi RTLD_DI_SERINFO to fill in the full information. */ 146*53ee8cc1Swenshuai.xi RTLD_DI_SERINFO = 4, 147*53ee8cc1Swenshuai.xi RTLD_DI_SERINFOSIZE = 5, 148*53ee8cc1Swenshuai.xi 149*53ee8cc1Swenshuai.xi /* Treat ARG as `char *', and store there the directory name used to 150*53ee8cc1Swenshuai.xi expand $ORIGIN in this shared object's dependency file names. */ 151*53ee8cc1Swenshuai.xi RTLD_DI_ORIGIN = 6, 152*53ee8cc1Swenshuai.xi 153*53ee8cc1Swenshuai.xi RTLD_DI_PROFILENAME = 7, /* Unsupported, defined by Solaris. */ 154*53ee8cc1Swenshuai.xi RTLD_DI_PROFILEOUT = 8, /* Unsupported, defined by Solaris. */ 155*53ee8cc1Swenshuai.xi 156*53ee8cc1Swenshuai.xi /* Treat ARG as `size_t *', and store there the TLS module ID 157*53ee8cc1Swenshuai.xi of this object's PT_TLS segment, as used in TLS relocations; 158*53ee8cc1Swenshuai.xi store zero if this object does not define a PT_TLS segment. */ 159*53ee8cc1Swenshuai.xi RTLD_DI_TLS_MODID = 9, 160*53ee8cc1Swenshuai.xi 161*53ee8cc1Swenshuai.xi /* Treat ARG as `void **', and store there a pointer to the calling 162*53ee8cc1Swenshuai.xi thread's TLS block corresponding to this object's PT_TLS segment. 163*53ee8cc1Swenshuai.xi Store a null pointer if this object does not define a PT_TLS 164*53ee8cc1Swenshuai.xi segment, or if the calling thread has not allocated a block for it. */ 165*53ee8cc1Swenshuai.xi RTLD_DI_TLS_DATA = 10, 166*53ee8cc1Swenshuai.xi 167*53ee8cc1Swenshuai.xi RTLD_DI_MAX = 10, 168*53ee8cc1Swenshuai.xi }; 169*53ee8cc1Swenshuai.xi 170*53ee8cc1Swenshuai.xi 171*53ee8cc1Swenshuai.xi /* This is the type of elements in `Dl_serinfo', below. 172*53ee8cc1Swenshuai.xi The `dls_name' member points to space in the buffer passed to `dlinfo'. */ 173*53ee8cc1Swenshuai.xi typedef struct 174*53ee8cc1Swenshuai.xi { 175*53ee8cc1Swenshuai.xi char *dls_name; /* Name of library search path directory. */ 176*53ee8cc1Swenshuai.xi unsigned int dls_flags; /* Indicates where this directory came from. */ 177*53ee8cc1Swenshuai.xi } Dl_serpath; 178*53ee8cc1Swenshuai.xi 179*53ee8cc1Swenshuai.xi /* This is the structure that must be passed (by reference) to `dlinfo' for 180*53ee8cc1Swenshuai.xi the RTLD_DI_SERINFO and RTLD_DI_SERINFOSIZE requests. */ 181*53ee8cc1Swenshuai.xi typedef struct 182*53ee8cc1Swenshuai.xi { 183*53ee8cc1Swenshuai.xi size_t dls_size; /* Size in bytes of the whole buffer. */ 184*53ee8cc1Swenshuai.xi unsigned int dls_cnt; /* Number of elements in `dls_serpath'. */ 185*53ee8cc1Swenshuai.xi Dl_serpath dls_serpath[1]; /* Actually longer, dls_cnt elements. */ 186*53ee8cc1Swenshuai.xi } Dl_serinfo; 187*53ee8cc1Swenshuai.xi #endif /* __USE_GNU */ 188*53ee8cc1Swenshuai.xi 189*53ee8cc1Swenshuai.xi 190*53ee8cc1Swenshuai.xi __END_DECLS 191*53ee8cc1Swenshuai.xi 192*53ee8cc1Swenshuai.xi #endif /* dlfcn.h */ 193