dlfcn-compat.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dl_info

Defines

#define dl_restrict
#define RTLD_LAZY   0x1
#define RTLD_NOW   0x2
#define RTLD_LOCAL   0x4
#define RTLD_GLOBAL   0x8
#define RTLD_NOLOAD   0x10
#define RTLD_NODELETE   0x80
#define RTLD_NEXT   ((void *) -1)
#define RTLD_DEFAULT   ((void *) -2)

Typedefs

typedef struct dl_info Dl_info

Functions

void * dlopen (const char *path, int mode)
void * dlsym (void *dl_restrict handle, const char *dl_restrict symbol)
const char * dlerror (void)
int dlclose (void *handle)
int dladdr (const void *dl_restrict, Dl_info *dl_restrict)


Define Documentation

#define dl_restrict

Definition at line 41 of file dlfcn-compat.h.

#define RTLD_DEFAULT   ((void *) -2)

Definition at line 71 of file dlfcn-compat.h.

#define RTLD_GLOBAL   0x8

Definition at line 63 of file dlfcn-compat.h.

#define RTLD_LAZY   0x1

Definition at line 60 of file dlfcn-compat.h.

#define RTLD_LOCAL   0x4

Definition at line 62 of file dlfcn-compat.h.

#define RTLD_NEXT   ((void *) -1)

Definition at line 70 of file dlfcn-compat.h.

#define RTLD_NODELETE   0x80

Definition at line 65 of file dlfcn-compat.h.

#define RTLD_NOLOAD   0x10

Definition at line 64 of file dlfcn-compat.h.

#define RTLD_NOW   0x2

Definition at line 61 of file dlfcn-compat.h.


Typedef Documentation

typedef struct dl_info Dl_info


Function Documentation

int dladdr ( const void *  dl_restrict,
Dl_info dl_restrict 
)

int dlclose ( void *  handle  ) 

Definition at line 1040 of file dlfcn.c.

01041 {
01042    struct dlstatus *dls = handle;
01043    dolock();
01044    resetdlerror();
01045    if (!isValidStatus(dls))
01046    {
01047       goto dlcloseerror;
01048    }
01049    if (dls->module == MAGIC_DYLIB_MOD)
01050    {
01051       const char *name;
01052       if (!dls->lib)
01053       {
01054          name = "global context";
01055       }
01056       else
01057       {
01058          name = get_lib_name(dls->lib);
01059       }
01060       warning("trying to close a .dylib!");
01061       error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
01062       goto dlcloseerror;
01063    }
01064    if (!dls->module)
01065    {
01066       error("module already closed");
01067       goto dlcloseerror;
01068    }
01069    
01070    if (dls->refs == 1)
01071    {
01072       unsigned long options = 0;
01073       void (*fini) (void);
01074       if ((fini = dlsymIntern(dls, "__fini", 0)))
01075       {
01076          debug("calling _fini()");
01077          fini();
01078       }
01079 #ifdef __ppc__
01080       options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
01081 #endif
01082 #if 1
01083 /*  Currently, if a module contains c++ static destructors and it is unloaded, we
01084  *  get a segfault in atexit(), due to compiler and dynamic loader differences of
01085  *  opinion, this works around that.
01086  *  I really need a way to figure out from code if this is still necessary.
01087  */
01088       if ((const struct section *)NULL !=
01089          getsectbynamefromheader(get_mach_header_from_NSModule(dls->module),
01090                            "__DATA", "__mod_term_func"))
01091       {
01092          options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
01093       }
01094 #endif
01095 #ifdef RTLD_NODELETE
01096       if (isFlagSet(dls->mode, RTLD_NODELETE))
01097          options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
01098 #endif
01099       if (!NSUnLinkModule(dls->module, options))
01100       {
01101          error("unable to unlink module");
01102          goto dlcloseerror;
01103       }
01104       dls->refs--;
01105       dls->module = 0;
01106       /* Note: the dlstatus struct dls is neither removed from the list
01107        * nor is the memory it occupies freed. This shouldn't pose a 
01108        * problem in mostly all cases, though.
01109        */
01110    }
01111    dounlock();
01112    return 0;
01113   dlcloseerror:
01114    dounlock();
01115    return 1;
01116 }

const char* dlerror ( void   ) 

Definition at line 1118 of file dlfcn.c.

01119 {
01120    struct dlthread  *tss;
01121    char * err_str;
01122    tss = pthread_getspecific(dlerror_key);
01123    err_str = tss->errstr;
01124    tss = pthread_getspecific(dlerror_key);
01125    if (tss->errset == 0)
01126       return 0;
01127    tss->errset = 0;  
01128    return (err_str );
01129 }

void* dlopen ( const char *  path,
int  mode 
)

Definition at line 896 of file dlfcn.c.

00897 {
00898    const struct stat *sbuf;
00899    struct dlstatus *dls;
00900    const char *fullPath;
00901    dlcompat_init_func();      /* Just in case */
00902    dolock();
00903    resetdlerror();
00904    if (!path)
00905    {
00906       dls = &mainStatus;
00907       goto dlopenok;
00908    }
00909    if (!(sbuf = findFile(path, &fullPath)))
00910    {
00911       error("file \"%s\" not found", path);
00912       goto dlopenerror;
00913    }
00914    /* Now checks that it hasn't been closed already */
00915    if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
00916    {
00917       /* debug("status found"); */
00918       dls = reference(dls, mode);
00919       goto dlopenok;
00920    }
00921 #ifdef   RTLD_NOLOAD
00922    if (isFlagSet(mode, RTLD_NOLOAD))
00923    {
00924       error("no existing handle and RTLD_NOLOAD specified");
00925       goto dlopenerror;
00926    }
00927 #endif
00928    if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
00929    {
00930       error("how can I load something both RTLD_LAZY and RTLD_NOW?");
00931       goto dlopenerror;
00932    }
00933    dls = loadModule(fullPath, sbuf, mode);
00934    
00935   dlopenok:
00936    dounlock();
00937    return (void *)dls;
00938   dlopenerror:
00939    dounlock();
00940    return NULL;
00941 }

void* dlsym ( void *dl_restrict  handle,
const char *dl_restrict  symbol 
)

Definition at line 944 of file dlfcn.c.

00945 {
00946    int sym_len = strlen(symbol);
00947    void *value = NULL;
00948    char *malloc_sym = NULL;
00949    dolock();
00950    malloc_sym = malloc(sym_len + 2);
00951    if (malloc_sym)
00952    {
00953       sprintf(malloc_sym, "_%s", symbol);
00954       value = dlsymIntern(handle, malloc_sym, 1);
00955       free(malloc_sym);
00956    }
00957    else
00958    {
00959       error("Unable to allocate memory");
00960       goto dlsymerror;
00961    }
00962    dounlock();
00963    return value;
00964   dlsymerror:
00965    dounlock();
00966    return NULL;
00967 }


Generated on Wed Oct 28 17:00:53 2009 for Asterisk by  doxygen 1.5.6