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