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