1 /**
2  * D header file for GNU/Linux
3  *
4  * $(LINK2 http://sourceware.org/git/?p=glibc.git;a=blob;f=dlfcn/dlfcn.h, glibc dlfcn/dlfcn.h)
5  */
6 module core.sys.linux.dlfcn;
7 
8 version (linux):
9 extern (C):
10 nothrow:
11 @nogc:
12 
13 version (ARM)     version = ARM_Any;
14 version (AArch64) version = ARM_Any;
15 version (HPPA)    version = HPPA_Any;
16 version (MIPS32)  version = MIPS_Any;
17 version (MIPS64)  version = MIPS_Any;
18 version (PPC)     version = PPC_Any;
19 version (PPC64)   version = PPC_Any;
20 version (RISCV32) version = RISCV_Any;
21 version (RISCV64) version = RISCV_Any;
22 version (S390)    version = IBMZ_Any;
23 version (SPARC)   version = SPARC_Any;
24 version (SPARC64) version = SPARC_Any;
25 version (SystemZ) version = IBMZ_Any;
26 version (X86)     version = X86_Any;
27 version (X86_64)  version = X86_Any;
28 
29 public import core.sys.posix.dlfcn;
30 import core.sys.linux.config;
31 
32 // <bits/dlfcn.h>
33 version (X86_Any)
34 {
35     // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
36     static if (_GNU_SOURCE)
37     {
38         RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
39         {
40             _dl_mcount_wrapper_check(cast(void*)fctp);
41             return fctp(args);
42         }
43 
44         void _dl_mcount_wrapper_check(void* __selfpc);
45     }
46 }
47 else version (HPPA_Any)
48 {
49     // http://sourceware.org/git/?p=glibc.git;a=blob;f=ports/sysdeps/hppa/bits/dlfcn.h
50     static if (_GNU_SOURCE)
51     {
52         RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
53         {
54             _dl_mcount_wrapper_check(cast(void*)fctp);
55             return fctp(args);
56         }
57 
58         void _dl_mcount_wrapper_check(void* __selfpc);
59     }
60 }
61 else version (MIPS_Any)
62 {
63     // http://sourceware.org/git/?p=glibc.git;a=blob;f=ports/sysdeps/mips/bits/dlfcn.h
64     static if (_GNU_SOURCE)
65     {
66         RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
67         {
68             _dl_mcount_wrapper_check(cast(void*)fctp);
69             return fctp(args);
70         }
71 
72         void _dl_mcount_wrapper_check(void* __selfpc);
73     }
74 }
75 else version (PPC_Any)
76 {
77     // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
78     static if (_GNU_SOURCE)
79     {
80         RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
81         {
82             _dl_mcount_wrapper_check(cast(void*)fctp);
83             return fctp(args);
84         }
85 
86         void _dl_mcount_wrapper_check(void* __selfpc);
87     }
88 }
89 else version (ARM_Any)
90 {
91     // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
92     static if (_GNU_SOURCE)
93     {
94         RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
95         {
96             _dl_mcount_wrapper_check(cast(void*)fctp);
97             return fctp(args);
98         }
99 
100         void _dl_mcount_wrapper_check(void* __selfpc);
101     }
102 }
103 else version (RISCV_Any)
104 {
105     // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
106     static if (_GNU_SOURCE)
107     {
108         RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
109         {
110             _dl_mcount_wrapper_check(cast(void*)fctp);
111             return fctp(args);
112         }
113 
114         void _dl_mcount_wrapper_check(void* __selfpc);
115     }
116 }
117 else version (SPARC_Any)
118 {
119     // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
120     static if (_GNU_SOURCE)
121     {
122         RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
123         {
124             _dl_mcount_wrapper_check(cast(void*)fctp);
125             return fctp(args);
126         }
127 
128         void _dl_mcount_wrapper_check(void* __selfpc);
129     }
130 }
131 else version (IBMZ_Any)
132 {
133     // http://sourceware.org/git/?p=glibc.git;a=blob;f=bits/dlfcn.h
134     static if (_GNU_SOURCE)
135     {
136         RT DL_CALL_FCT(RT, Args...)(RT function(Args) fctp, auto ref Args args)
137         {
138             _dl_mcount_wrapper_check(cast(void*)fctp);
139             return fctp(args);
140         }
141 
142         void _dl_mcount_wrapper_check(void* __selfpc);
143     }
144 }
145 else
146     static assert(0, "unimplemented");
147 
148 // <bits/dlfcn.h>
149 
150 static if (_GNU_SOURCE)
151 {
152     enum RTLD_NEXT = cast(void *)-1L;
153     enum RTLD_DEFAULT = cast(void *)0;
154     alias c_long Lmid_t;
155     enum LM_ID_BASE = 0;
156     enum LM_ID_NEWLM = -1;
157 }
158 
159 // void* dlopen(const scope char* __file, int __mode); // POSIX
160 // int dlclose(void* __handle); // POSIX
161 // void* dlsym(void* __handle, const scope char* __name); // POSIX
162 
163 static if (_GNU_SOURCE)
164 {
165     void* dlmopen(Lmid_t __nsid, const scope char* __file, int __mode);
166     void* dlvsym(void* __handle, const scope char* __name, const scope char* __version);
167 }
168 
169 // char* dlerror(); // POSIX
170 
171 static if (_GNU_SOURCE)
172 {
173     int dladdr1(void* __address, Dl_info* __info, void** __extra_info, int __flags);
174 
175     enum
176     {
177         RTLD_DL_SYMENT = 1,
178         RTLD_DL_LINKMAP = 2,
179     }
180 
181     int dlinfo(void* __handle, int __request, void* __arg);
182 
183     enum
184     {
185         RTLD_DI_LMID = 1,
186         RTLD_DI_LINKMAP = 2,
187         RTLD_DI_CONFIGADDR = 3,
188         RTLD_DI_SERINFO = 4,
189         RTLD_DI_SERINFOSIZE = 5,
190         RTLD_DI_ORIGIN = 6,
191         RTLD_DI_PROFILENAME = 7,
192         RTLD_DI_PROFILEOUT = 8,
193         RTLD_DI_TLS_MODID = 9,
194         RTLD_DI_TLS_DATA = 10,
195         RTLD_DI_MAX = 10,
196     }
197 
198     struct Dl_serpath
199     {
200         char* dls_name;
201         uint dls_flags;
202     }
203 
204     struct Dl_serinfo
205     {
206         size_t dls_size;
207         uint dls_cnt;
208         Dl_serpath[1] dls_serpath;
209     }
210 }