The OpenD Programming Language

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