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