| 1 |
use std::os::raw::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 |
| 15 |
pub 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 |
| 28 |
pub 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 |
| 38 |
pub 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. |
| 44 |
pub const RTLD_LOCAL: c_int = posix::RTLD_LOCAL; |
| 45 |
|
| 46 |
#[cfg(all(libloading_docs, not(unix)))] |
| 47 |
mod 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))] |
| 56 |
mod posix { |
| 57 |
extern crate cfg_if; |
| 58 |
use self::cfg_if::cfg_if; |
| 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 = "freebsd", |
| 73 |
target_os = "dragonfly", |
| 74 |
target_os = "openbsd", |
| 75 |
target_os = "netbsd", |
| 76 |
|
| 77 |
target_os = "solaris", |
| 78 |
target_os = "illumos", |
| 79 |
|
| 80 |
target_env = "uclibc", |
| 81 |
target_env = "newlib", |
| 82 |
|
| 83 |
target_os = "fuchsia", |
| 84 |
target_os = "redox", |
| 85 |
target_os = "nto", |
| 86 |
target_os = "hurd", |
| 87 |
))] { |
| 88 |
pub(super) const RTLD_LAZY: c_int = 1; |
| 89 |
} else { |
| 90 |
compile_error!( |
| 91 |
"Target has no known `RTLD_LAZY` value. Please submit an issue or PR adding it." |
| 92 |
); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
cfg_if! { |
| 97 |
if #[cfg(target_os = "haiku")] { |
| 98 |
pub(super) const RTLD_NOW: c_int = 1; |
| 99 |
} else if #[cfg(any( |
| 100 |
target_os = "linux", |
| 101 |
all(target_os = "android", target_pointer_width = "64"), |
| 102 |
target_os = "emscripten", |
| 103 |
|
| 104 |
target_os = "macos", |
| 105 |
target_os = "ios", |
| 106 |
target_os = "freebsd", |
| 107 |
target_os = "dragonfly", |
| 108 |
target_os = "openbsd", |
| 109 |
target_os = "netbsd", |
| 110 |
|
| 111 |
target_os = "aix", |
| 112 |
target_os = "solaris", |
| 113 |
target_os = "illumos", |
| 114 |
|
| 115 |
target_env = "uclibc", |
| 116 |
target_env = "newlib", |
| 117 |
|
| 118 |
target_os = "fuchsia", |
| 119 |
target_os = "redox", |
| 120 |
target_os = "nto", |
| 121 |
target_os = "hurd", |
| 122 |
))] { |
| 123 |
pub(super) const RTLD_NOW: c_int = 2; |
| 124 |
} else if #[cfg(all(target_os = "android",target_pointer_width = "32"))] { |
| 125 |
pub(super) const RTLD_NOW: c_int = 0; |
| 126 |
} else { |
| 127 |
compile_error!( |
| 128 |
"Target has no known `RTLD_NOW` value. Please submit an issue or PR adding it." |
| 129 |
); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
cfg_if! { |
| 134 |
if #[cfg(any( |
| 135 |
target_os = "haiku", |
| 136 |
all(target_os = "android",target_pointer_width = "32"), |
| 137 |
))] { |
| 138 |
pub(super) const RTLD_GLOBAL: c_int = 2; |
| 139 |
} else if #[cfg(target_os = "aix")] { |
| 140 |
pub(super) const RTLD_GLOBAL: c_int = 0x10000; |
| 141 |
} else if #[cfg(any( |
| 142 |
target_env = "uclibc", |
| 143 |
all(target_os = "linux", target_arch = "mips"), |
| 144 |
all(target_os = "linux", target_arch = "mips64"), |
| 145 |
))] { |
| 146 |
pub(super) const RTLD_GLOBAL: c_int = 4; |
| 147 |
} else if #[cfg(any( |
| 148 |
target_os = "macos", |
| 149 |
target_os = "ios", |
| 150 |
))] { |
| 151 |
pub(super) const RTLD_GLOBAL: c_int = 8; |
| 152 |
} else if #[cfg(any( |
| 153 |
target_os = "linux", |
| 154 |
all(target_os = "android", target_pointer_width = "64"), |
| 155 |
target_os = "emscripten", |
| 156 |
|
| 157 |
target_os = "freebsd", |
| 158 |
target_os = "dragonfly", |
| 159 |
target_os = "openbsd", |
| 160 |
target_os = "netbsd", |
| 161 |
|
| 162 |
target_os = "solaris", |
| 163 |
target_os = "illumos", |
| 164 |
|
| 165 |
target_env = "newlib", |
| 166 |
|
| 167 |
target_os = "fuchsia", |
| 168 |
target_os = "redox", |
| 169 |
target_os = "nto", |
| 170 |
target_os = "hurd", |
| 171 |
))] { |
| 172 |
pub(super) const RTLD_GLOBAL: c_int = 0x100; |
| 173 |
} else { |
| 174 |
compile_error!( |
| 175 |
"Target has no known `RTLD_GLOBAL` value. Please submit an issue or PR adding it." |
| 176 |
); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
cfg_if! { |
| 181 |
if #[cfg(any( |
| 182 |
target_os = "netbsd", |
| 183 |
target_os = "nto", |
| 184 |
))] { |
| 185 |
pub(super) const RTLD_LOCAL: c_int = 0x200; |
| 186 |
} else if #[cfg(target_os = "aix")] { |
| 187 |
pub(super) const RTLD_LOCAL: c_int = 0x80000; |
| 188 |
} else if #[cfg(any( |
| 189 |
target_os = "macos", |
| 190 |
target_os = "ios", |
| 191 |
))] { |
| 192 |
pub(super) const RTLD_LOCAL: c_int = 4; |
| 193 |
} else if #[cfg(any( |
| 194 |
target_os = "linux", |
| 195 |
target_os = "android", |
| 196 |
target_os = "emscripten", |
| 197 |
|
| 198 |
target_os = "freebsd", |
| 199 |
target_os = "dragonfly", |
| 200 |
target_os = "openbsd", |
| 201 |
|
| 202 |
target_os = "haiku", |
| 203 |
|
| 204 |
target_os = "solaris", |
| 205 |
target_os = "illumos", |
| 206 |
|
| 207 |
target_env = "uclibc", |
| 208 |
target_env = "newlib", |
| 209 |
|
| 210 |
target_os = "fuchsia", |
| 211 |
target_os = "redox", |
| 212 |
target_os = "hurd", |
| 213 |
))] { |
| 214 |
pub(super) const RTLD_LOCAL: c_int = 0; |
| 215 |
} else { |
| 216 |
compile_error!( |
| 217 |
"Target has no known `RTLD_LOCAL` value. Please submit an issue or PR adding it." |
| 218 |
); |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
// Other constants that exist but are not bound because they are platform-specific (non-posix) |
| 224 |
// extensions. Some of these constants are only relevant to `dlsym` or `dlmopen` calls. |
| 225 |
// |
| 226 |
// RTLD_CONFGEN |
| 227 |
// RTLD_DEFAULT |
| 228 |
// RTLD_DI_CONFIGADDR |
| 229 |
// RTLD_DI_LINKMAP |
| 230 |
// RTLD_DI_LMID |
| 231 |
// RTLD_DI_ORIGIN |
| 232 |
// RTLD_DI_PROFILENAME |
| 233 |
// RTLD_DI_PROFILEOUT |
| 234 |
// RTLD_DI_SERINFO |
| 235 |
// RTLD_DI_SERINFOSIZE |
| 236 |
// RTLD_DI_TLS_DATA |
| 237 |
// RTLD_DI_TLS_MODID |
| 238 |
// RTLD_FIRST |
| 239 |
// RTLD_GROUP |
| 240 |
// RTLD_NEXT |
| 241 |
// RTLD_PARENT |
| 242 |
// RTLD_PROBE |
| 243 |
// RTLD_SELF |
| 244 |
// RTLD_WORLD |
| 245 |
// RTLD_NODELETE |
| 246 |
// RTLD_NOLOAD |
| 247 |
// RTLD_DEEPBIND |