summaryrefslogtreecommitdiff
path: root/libphobos/libdruntime/core/sys/freebsd/dlfcn.d
blob: e390743692dff427d4569d3c35dfc11f1a1994d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
 * D header file for FreeBSD.
 *
 * Copyright: Copyright Martin Nowak 2012.
 * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
 * Authors:   Martin Nowak
 */
module core.sys.freebsd.dlfcn;

public import core.sys.posix.dlfcn;

version (FreeBSD):
extern (C):
nothrow:
@nogc:

enum __BSD_VISIBLE = true;

/*
 * Modes and flags for dlopen().
 */
static assert(RTLD_LAZY   == 1);
static assert(RTLD_NOW    == 2);
enum RTLD_MODEMASK        =  0x3;
static assert(RTLD_GLOBAL == 0x100);
static assert(RTLD_LOCAL  == 0);
enum RTLD_TRACE           =  0x200;
enum RTLD_NODELETE        =  0x01000;
enum RTLD_NOLOAD          =  0x02000;

/*
 * Request arguments for dlinfo().
 */
enum RTLD_DI_LINKMAP     = 2;    /* Obtain link map. */
enum RTLD_DI_SERINFO     = 4;    /* Obtain search path info. */
enum RTLD_DI_SERINFOSIZE = 5;    /*  ... query for required space. */
enum RTLD_DI_ORIGIN      = 6;    /* Obtain object origin */
enum RTLD_DI_MAX         = RTLD_DI_ORIGIN;

/*
 * Special handle arguments for dlsym()/dlinfo().
 */
enum RTLD_NEXT    = cast(void *)-1;    /* Search subsequent objects. */
enum RTLD_DEFAULT = cast(void *)-2;    /* Use default search algorithm. */
enum RTLD_SELF    = cast(void *)-3;    /* Search the caller itself. */

static if (__BSD_VISIBLE)
{
    /*
     * Structure filled in by dladdr().
     */
    struct Dl_info {
        const(char)     *dli_fname;     /* Pathname of shared object. */
        void            *dli_fbase;     /* Base address of shared object. */
        const(char)     *dli_sname;     /* Name of nearest symbol. */
        void            *dli_saddr;     /* Address of nearest symbol. */
    };

    /*-
     * The actual type declared by this typedef is immaterial, provided that
     * it is a function pointer.  Its purpose is to provide a return type for
     * dlfunc() which can be cast to a function pointer type without depending
     * on behavior undefined by the C standard, which might trigger a compiler
     * diagnostic.  We intentionally declare a unique type signature to force
     * a diagnostic should the application not cast the return value of dlfunc()
     * appropriately.
     */
    struct __dlfunc_arg {
        int     __dlfunc_dummy;
    };

    alias dlfunc_t = void function(__dlfunc_arg);

    /*
     * Structures, returned by the RTLD_DI_SERINFO dlinfo() request.
     */
    struct Dl_serpath {
        char *          dls_name;       /* single search path entry */
        uint            dls_flags;      /* path information */
    };

    struct Dl_serinfo {
        size_t          dls_size;       /* total buffer size */
        uint            dls_cnt;        /* number of path entries */
        Dl_serpath[1]   dls_serpath;    /* there may be more than one */
    };
}

private template __externC(RT, P...)
{
    alias __externC = extern(C) RT function(P) nothrow @nogc;
}

/* XSI functions first. */
static assert(is(typeof(&dlclose) == __externC!(int, void*)));
static assert(is(typeof(&dlerror) == __externC!(char*)));
static assert(is(typeof(&dlopen)  == __externC!(void*, const char*, int)));
static assert(is(typeof(&dlsym)   == __externC!(void*, void*, const char*)));

static if (__BSD_VISIBLE)
{
    void*    fdlopen(int, int);
    int      dladdr(const(void)*, Dl_info*);
    dlfunc_t dlfunc(void*, const(char)*);
    int      dlinfo(void*, int, void*);
    void     dllockinit(void* _context,
        void* function(void* _context) _lock_create,
        void  function(void* _lock)    _rlock_acquire,
        void  function(void* _lock)    _wlock_acquire,
        void  function(void* _lock)    _lock_release,
        void  function(void* _lock)    _lock_destroy,
        void  function(void* _context) _context_destroy);
    void*    dlvsym(void*, const(char)*, const(char)*);
}