libloading/os/unix/
consts.rs

1use core::ffi::c_int;
2
3/// Perform lazy binding.
4///
5/// Relocations shall be performed at an implementation-defined time, ranging from the time
6/// of the [`Library::open`] call until the first reference to a given symbol occurs.
7/// Specifying `RTLD_LAZY` should improve performance on implementations supporting dynamic
8/// symbol binding since a process might not reference all of the symbols in an executable
9/// object file. And, for systems supporting dynamic symbol resolution for normal process
10/// execution, this behaviour mimics the normal handling of process execution.
11///
12/// Conflicts with [`RTLD_NOW`].
13///
14/// [`Library::open`]: crate::os::unix::Library::open
15pub const RTLD_LAZY: c_int = posix::RTLD_LAZY;
16
17/// Perform eager binding.
18///
19/// All necessary relocations shall be performed when the executable object file is first
20/// loaded. This may waste some processing if relocations are performed for symbols
21/// that are never referenced. This behaviour may be useful for applications that need to
22/// know that all symbols referenced during execution will be available before
23/// [`Library::open`] returns.
24///
25/// Conflicts with [`RTLD_LAZY`].
26///
27/// [`Library::open`]: crate::os::unix::Library::open
28pub const RTLD_NOW: c_int = posix::RTLD_NOW;
29
30/// Make loaded symbols available for resolution globally.
31///
32/// The executable object file's symbols shall be made available for relocation processing of any
33/// other executable object file. In addition, calls to [`Library::get`] on `Library` obtained from
34/// [`Library::this`] allows executable object files loaded with this mode to be searched.
35///
36/// [`Library::this`]: crate::os::unix::Library::this
37/// [`Library::get`]: crate::os::unix::Library::get
38pub const RTLD_GLOBAL: c_int = posix::RTLD_GLOBAL;
39
40/// Load symbols into an isolated namespace.
41///
42/// The executable object file's symbols shall not be made available for relocation processing of
43/// any other executable object file. This mode of operation is most appropriate for e.g. plugins.
44pub const RTLD_LOCAL: c_int = posix::RTLD_LOCAL;
45
46#[cfg(all(libloading_docs, not(unix)))]
47mod posix {
48    use super::c_int;
49    pub(super) const RTLD_LAZY: c_int = !0;
50    pub(super) const RTLD_NOW: c_int = !0;
51    pub(super) const RTLD_GLOBAL: c_int = !0;
52    pub(super) const RTLD_LOCAL: c_int = !0;
53}
54
55#[cfg(any(not(libloading_docs), unix, target_os = "twizzler"))]
56mod posix {
57    use cfg_if::cfg_if;
58
59    use super::c_int;
60    cfg_if! {
61        if #[cfg(target_os = "haiku")] {
62            pub(super) const RTLD_LAZY: c_int = 0;
63        } else if #[cfg(target_os = "aix")] {
64            pub(super) const RTLD_LAZY: c_int = 4;
65        } else if #[cfg(any(
66            target_os = "linux",
67            target_os = "android",
68            target_os = "emscripten",
69
70            target_os = "macos",
71            target_os = "ios",
72            target_os = "tvos",
73            target_os = "visionos",
74            target_os = "watchos",
75
76            target_os = "freebsd",
77            target_os = "dragonfly",
78            target_os = "openbsd",
79            target_os = "netbsd",
80
81            target_os = "solaris",
82            target_os = "illumos",
83
84            target_env = "uclibc",
85            target_env = "newlib",
86
87            target_os = "fuchsia",
88            target_os = "redox",
89            target_os = "nto",
90            target_os = "hurd",
91            target_os = "cygwin",
92            target_os = "twizzler",
93        ))] {
94            pub(super) const RTLD_LAZY: c_int = 1;
95        } else {
96            compile_error!(
97                "Target has no known `RTLD_LAZY` value. Please submit an issue or PR adding it."
98            );
99        }
100    }
101
102    cfg_if! {
103        if #[cfg(target_os = "haiku")] {
104            pub(super) const RTLD_NOW: c_int = 1;
105        } else if #[cfg(any(
106            target_os = "linux",
107            all(target_os = "android", target_pointer_width = "64"),
108            target_os = "emscripten",
109
110            target_os = "macos",
111            target_os = "ios",
112            target_os = "tvos",
113            target_os = "visionos",
114            target_os = "watchos",
115
116            target_os = "freebsd",
117            target_os = "dragonfly",
118            target_os = "openbsd",
119            target_os = "netbsd",
120
121            target_os = "aix",
122            target_os = "solaris",
123            target_os = "illumos",
124
125            target_env = "uclibc",
126            target_env = "newlib",
127
128            target_os = "fuchsia",
129            target_os = "redox",
130            target_os = "nto",
131            target_os = "hurd",
132            target_os = "cygwin",
133            target_os = "twizzler",
134        ))] {
135            pub(super) const RTLD_NOW: c_int = 2;
136        } else if #[cfg(all(target_os = "android",target_pointer_width = "32"))] {
137            pub(super) const RTLD_NOW: c_int = 0;
138        } else {
139            compile_error!(
140                "Target has no known `RTLD_NOW` value. Please submit an issue or PR adding it."
141            );
142        }
143    }
144
145    cfg_if! {
146        if #[cfg(any(
147            target_os = "haiku",
148            all(target_os = "android",target_pointer_width = "32"),
149        ))] {
150            pub(super) const RTLD_GLOBAL: c_int = 2;
151        } else if #[cfg(target_os = "aix")] {
152            pub(super) const RTLD_GLOBAL: c_int = 0x10000;
153        } else if #[cfg(any(
154            target_env = "uclibc",
155            all(target_os = "linux", target_arch = "mips"),
156            all(target_os = "linux", target_arch = "mips64"),
157            target_os = "cygwin",
158        ))] {
159            pub(super) const RTLD_GLOBAL: c_int = 4;
160        } else if #[cfg(any(
161            target_os = "macos",
162            target_os = "ios",
163            target_os = "tvos",
164            target_os = "visionos",
165            target_os = "watchos",
166        ))] {
167            pub(super) const RTLD_GLOBAL: c_int = 8;
168        } else if #[cfg(any(
169            target_os = "linux",
170            all(target_os = "android", target_pointer_width = "64"),
171            target_os = "emscripten",
172
173            target_os = "freebsd",
174            target_os = "dragonfly",
175            target_os = "openbsd",
176            target_os = "netbsd",
177
178            target_os = "solaris",
179            target_os = "illumos",
180
181            target_env = "newlib",
182
183            target_os = "fuchsia",
184            target_os = "redox",
185            target_os = "nto",
186            target_os = "hurd",
187            target_os = "twizzler",
188        ))] {
189            pub(super) const RTLD_GLOBAL: c_int = 0x100;
190        } else {
191            compile_error!(
192                "Target has no known `RTLD_GLOBAL` value. Please submit an issue or PR adding it."
193            );
194        }
195    }
196
197    cfg_if! {
198        if #[cfg(any(
199           target_os = "netbsd",
200           target_os = "nto",
201        ))] {
202            pub(super) const RTLD_LOCAL: c_int = 0x200;
203        } else if #[cfg(target_os = "aix")] {
204            pub(super) const RTLD_LOCAL: c_int = 0x80000;
205        } else if #[cfg(any(
206            target_os = "macos",
207            target_os = "ios",
208            target_os = "tvos",
209            target_os = "visionos",
210            target_os = "watchos",
211        ))] {
212            pub(super) const RTLD_LOCAL: c_int = 4;
213        } else if #[cfg(any(
214            target_os = "linux",
215            target_os = "android",
216            target_os = "emscripten",
217
218            target_os = "freebsd",
219            target_os = "dragonfly",
220            target_os = "openbsd",
221
222            target_os = "haiku",
223
224            target_os = "solaris",
225            target_os = "illumos",
226
227            target_env = "uclibc",
228            target_env = "newlib",
229
230            target_os = "fuchsia",
231            target_os = "redox",
232            target_os = "hurd",
233            target_os = "cygwin",
234            target_os = "twizzler",
235        ))] {
236            pub(super) const RTLD_LOCAL: c_int = 0;
237        } else {
238            compile_error!(
239                "Target has no known `RTLD_LOCAL` value. Please submit an issue or PR adding it."
240            );
241        }
242    }
243}
244
245// Other constants that exist but are not bound because they are platform-specific (non-posix)
246// extensions. Some of these constants are only relevant to `dlsym` or `dlmopen` calls.
247//
248// RTLD_CONFGEN
249// RTLD_DEFAULT
250// RTLD_DI_CONFIGADDR
251// RTLD_DI_LINKMAP
252// RTLD_DI_LMID
253// RTLD_DI_ORIGIN
254// RTLD_DI_PROFILENAME
255// RTLD_DI_PROFILEOUT
256// RTLD_DI_SERINFO
257// RTLD_DI_SERINFOSIZE
258// RTLD_DI_TLS_DATA
259// RTLD_DI_TLS_MODID
260// RTLD_FIRST
261// RTLD_GROUP
262// RTLD_NEXT
263// RTLD_PARENT
264// RTLD_PROBE
265// RTLD_SELF
266// RTLD_WORLD
267// RTLD_NODELETE
268// RTLD_NOLOAD
269// RTLD_DEEPBIND