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