The OpenD Programming Language

1 /**
2  * D header file for FreeBSD.
3  *
4  * Copyright: Copyright Martin Nowak 2012.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Martin Nowak
7  */
8 module core.sys.freebsd.dlfcn;
9 
10 public import core.sys.posix.dlfcn;
11 
12 version (FreeBSD):
13 extern (C):
14 nothrow:
15 @nogc:
16 
17 enum __BSD_VISIBLE = true;
18 
19 /*
20  * Request arguments for dlinfo().
21  */
22 enum RTLD_DI_LINKMAP     = 2;    /* Obtain link map. */
23 enum RTLD_DI_SERINFO     = 4;    /* Obtain search path info. */
24 enum RTLD_DI_SERINFOSIZE = 5;    /*  ... query for required space. */
25 enum RTLD_DI_ORIGIN      = 6;    /* Obtain object origin */
26 enum RTLD_DI_MAX         = RTLD_DI_ORIGIN;
27 
28 /*
29  * Special handle arguments for dlsym()/dlinfo().
30  */
31 enum RTLD_NEXT    = cast(void *)-1;    /* Search subsequent objects. */
32 enum RTLD_DEFAULT = cast(void *)-2;    /* Use default search algorithm. */
33 enum RTLD_SELF    = cast(void *)-3;    /* Search the caller itself. */
34 
35 static if (__BSD_VISIBLE)
36 {
37     /*-
38      * The actual type declared by this typedef is immaterial, provided that
39      * it is a function pointer.  Its purpose is to provide a return type for
40      * dlfunc() which can be cast to a function pointer type without depending
41      * on behavior undefined by the C standard, which might trigger a compiler
42      * diagnostic.  We intentionally declare a unique type signature to force
43      * a diagnostic should the application not cast the return value of dlfunc()
44      * appropriately.
45      */
46     struct __dlfunc_arg {
47         int     __dlfunc_dummy;
48     }
49 
50     alias dlfunc_t = void function(__dlfunc_arg);
51 
52     /*
53      * Structures, returned by the RTLD_DI_SERINFO dlinfo() request.
54      */
55     struct Dl_serpath {
56         char *          dls_name;       /* single search path entry */
57         uint            dls_flags;      /* path information */
58     }
59 
60     struct Dl_serinfo {
61         size_t          dls_size;       /* total buffer size */
62         uint            dls_cnt;        /* number of path entries */
63         Dl_serpath[1]   dls_serpath;    /* there may be more than one */
64     }
65 }
66 
67 /* XSI functions first. */
68 extern(C) {
69     static assert(is(typeof(&dlclose) == int function(void*)));
70     static assert(is(typeof(&dlerror) == char* function()));
71     static assert(is(typeof(&dlopen)  == void* function(const scope char*, int)));
72     static assert(is(typeof(&dlsym)   == void* function(void*, const scope char*)));
73 }
74 
75 static if (__BSD_VISIBLE)
76 {
77     void*    fdlopen(int, int);
78     dlfunc_t dlfunc(void*, const(char)*);
79     int      dlinfo(void*, int, void*);
80     void     dllockinit(void* _context,
81         void* function(void* _context) _lock_create,
82         void  function(void* _lock)    _rlock_acquire,
83         void  function(void* _lock)    _wlock_acquire,
84         void  function(void* _lock)    _lock_release,
85         void  function(void* _lock)    _lock_destroy,
86         void  function(void* _context) _context_destroy);
87     void*    dlvsym(void*, const(char)*, const(char)*);
88 }