| 1 | // A hack for docs.rs to build documentation that has both windows and linux documentation in the |
| 2 | // same rustdoc build visible. |
| 3 | #[cfg(all(libloading_docs, not(unix)))] |
| 4 | mod unix_importsrust-analyzer cargo libloading 0.8.9 os/unix/unix_imports/ {} |
| 5 | #[cfg(any(not(libloading_docs), unix))] |
| 6 | mod unix_importsrust-analyzer cargo libloading 0.8.9 os/unix/unix_imports/ { |
| 7 | pub(superrust-analyzer cargo libloading 0.8.9 os/unix/) use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/::OsStrExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/OsStrExt#; |
| 8 | } |
| 9 | |
| 10 | pub use selfrust-analyzer cargo libloading 0.8.9 os/unix/::constsrust-analyzer cargo libloading 0.8.9 os/unix/consts/::*; |
| 11 | use selfrust-analyzer cargo libloading 0.8.9 os/unix/::unix_importsrust-analyzer cargo libloading 0.8.9 os/unix/unix_imports/::*; |
| 12 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#, OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#}; |
| 13 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/; |
| 14 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/, memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/, ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/}; |
| 15 | use util::{cstr_cow_from_bytes, ensure_compatible_types}; |
| 16 | |
| 17 | mod constsrust-analyzer cargo libloading 0.8.9 os/unix/consts/; |
| 18 | |
| 19 | /// Run code and handle errors reported by `dlerror`. |
| 20 | /// |
| 21 | /// This function first executes the `closure` function containing calls to the functions that |
| 22 | /// report their errors via `dlerror`. This closure may return either `None` or `Some(*)` to |
| 23 | /// further affect operation of this function. |
| 24 | /// |
| 25 | /// In case the `closure` returns `None`, `with_dlerror` inspects the `dlerror`. `dlerror` may |
| 26 | /// decide to not provide any error description, in which case `Err(None)` is returned to the |
| 27 | /// caller. Otherwise the `error` callback is invoked to allow inspection and conversion of the |
| 28 | /// error message. The conversion result is returned as `Err(Some(Error))`. |
| 29 | /// |
| 30 | /// If the operations that report their errors via `dlerror` were all successful, `closure` should |
| 31 | /// return `Some(T)` instead. In this case `dlerror` is not inspected at all. |
| 32 | /// |
| 33 | /// # Notes |
| 34 | /// |
| 35 | /// The whole `dlerror` handling scheme is done via setting and querying some global state. For |
| 36 | /// that reason it is not safe to use dynamic library loading in MT-capable environment at all. |
| 37 | /// Only in POSIX 2008+TC1 a thread-local state was allowed for `dlerror`, making the dl* family of |
| 38 | /// functions possibly MT-safe, depending on the implementation of `dlerror`. |
| 39 | /// |
| 40 | /// In practice (as of 2020-04-01) most of the widely used targets use a thread-local for error |
| 41 | /// state and have been doing so for a long time. |
| 42 | pub fn with_dlerrorrust-analyzer cargo libloading 0.8.9 os/unix/with_dlerror().<T, F, Error>(closure: F, error: fn(&CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#) -> Error) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Error>> |
| 43 | where |
| 44 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>, |
| 45 | { |
| 46 | // We used to guard all uses of dl* functions with our own mutex. This made them safe to use in |
| 47 | // MT programs provided the only way a program used dl* was via this library. However, it also |
| 48 | // had a number of downsides or cases where it failed to handle the problems. For instance, |
| 49 | // if any other library called `dlerror` internally concurrently with `libloading` things would |
| 50 | // still go awry. |
| 51 | // |
| 52 | // On platforms where `dlerror` is still MT-unsafe, `dlsym` (`Library::get`) can spuriously |
| 53 | // succeed and return a null pointer for a symbol when the actual symbol look-up operation |
| 54 | // fails. Instances where the actual symbol _could_ be `NULL` are platform specific. For |
| 55 | // instance on GNU glibc based-systems (an excerpt from dlsym(3)): |
| 56 | // |
| 57 | // > The value of a symbol returned by dlsym() will never be NULL if the shared object is the |
| 58 | // > result of normal compilation, since a global symbol is never placed at the NULL |
| 59 | // > address. There are nevertheless cases where a lookup using dlsym() may return NULL as the |
| 60 | // > value of a symbol. For example, the symbol value may be the result of a GNU indirect |
| 61 | // > function (IFUNC) resolver function that returns NULL as the resolved value. |
| 62 | |
| 63 | // While we could could call `dlerror` here to clear the previous error value, only the `dlsym` |
| 64 | // call depends on it being cleared beforehand and only in some cases too. We will instead |
| 65 | // clear the error inside the dlsym binding instead. |
| 66 | // |
| 67 | // In all the other cases, clearing the error here will only be hiding misuse of these bindings |
| 68 | // or a bug in implementation of dl* family of functions. |
| 69 | closure().ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| unsafe { |
| 70 | // This code will only get executed if the `closure` returns `None`. |
| 71 | let dlerror_str = dlerrorrust-analyzer cargo libloading 0.8.9 dlerror().(); |
| 72 | if dlerror_str.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 73 | // In non-dlsym case this may happen when there’re bugs in our bindings or there’s |
| 74 | // non-libloading user of libdl; possibly in another thread. |
| 75 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 76 | } else { |
| 77 | // You can’t even rely on error string being static here; call to subsequent dlerror |
| 78 | // may invalidate or overwrite the error message. Why couldn’t they simply give up the |
| 79 | // ownership over the message? |
| 80 | // TODO: should do locale-aware conversion here. OTOH Rust doesn’t seem to work well in |
| 81 | // any system that uses non-utf8 locale, so I doubt there’s a problem here. |
| 82 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(error(CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(dlerror_str))) |
| 83 | // Since we do a copy of the error string above, maybe we should call dlerror again to |
| 84 | // let libdl know it may free its copy of the string now? |
| 85 | } |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | /// A platform-specific counterpart of the cross-platform [`Library`](crate::Library). |
| 90 | pub struct Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# { |
| 91 | handlerust-analyzer cargo libloading 0.8.9 os/unix/Library#handle.: *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 92 | } |
| 93 | |
| 94 | unsafe impl Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# {} |
| 95 | |
| 96 | // That being said... this section in the volume 2 of POSIX.1-2008 states: |
| 97 | // |
| 98 | // > All functions defined by this volume of POSIX.1-2008 shall be thread-safe, except that the |
| 99 | // > following functions need not be thread-safe. |
| 100 | // |
| 101 | // With notable absence of any dl* function other than dlerror in the list. By “this volume” |
| 102 | // I suppose they refer precisely to the “volume 2”. dl* family of functions are specified |
| 103 | // by this same volume, so the conclusion is indeed that dl* functions are required by POSIX |
| 104 | // to be thread-safe. Great! |
| 105 | // |
| 106 | // See for more details: |
| 107 | // |
| 108 | // * https://github.com/nagisa/rust_libloading/pull/17 |
| 109 | // * http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_01 |
| 110 | unsafe impl Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# {} |
| 111 | |
| 112 | impl Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# { |
| 113 | /// Find and eagerly load a shared library (module). |
| 114 | /// |
| 115 | /// If the `filename` contains a [path separator], the `filename` is interpreted as a `path` to |
| 116 | /// a file. Otherwise, platform-specific algorithms are employed to find a library with a |
| 117 | /// matching file name. |
| 118 | /// |
| 119 | /// This is equivalent to <code>[Library::open](filename, [RTLD_LAZY] | [RTLD_LOCAL])</code>. |
| 120 | /// |
| 121 | /// [path separator]: std::path::MAIN_SEPARATOR |
| 122 | /// |
| 123 | /// # Safety |
| 124 | /// |
| 125 | /// When a library is loaded, initialisation routines contained within the library are executed. |
| 126 | /// For the purposes of safety, the execution of these routines is conceptually the same calling an |
| 127 | /// unknown foreign function and may impose arbitrary requirements on the caller for the call |
| 128 | /// to be sound. |
| 129 | /// |
| 130 | /// Additionally, the callers of this function must also ensure that execution of the |
| 131 | /// termination routines contained within the library is safe as well. These routines may be |
| 132 | /// executed when the library is unloaded. |
| 133 | #[inline] |
| 134 | pub unsafe fn newrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]new().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(filename: P) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library#, craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#> { |
| 135 | Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library#::openrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]open().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(filename), RTLD_LAZYrust-analyzer cargo libloading 0.8.9 os/unix/consts/RTLD_LAZY. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().RTLD_LOCALrust-analyzer cargo libloading 0.8.9 os/unix/consts/RTLD_LOCAL.) |
| 136 | } |
| 137 | |
| 138 | /// Load the `Library` representing the current executable. |
| 139 | /// |
| 140 | /// [`Library::get`] calls of the returned `Library` will look for symbols in following |
| 141 | /// locations in order: |
| 142 | /// |
| 143 | /// 1. The original program image; |
| 144 | /// 2. Any executable object files (e.g. shared libraries) loaded at program startup; |
| 145 | /// 3. Any executable object files loaded at runtime (e.g. via other `Library::new` calls or via |
| 146 | /// calls to the `dlopen` function). |
| 147 | /// |
| 148 | /// Note that the behaviour of a `Library` loaded with this method is different from that of |
| 149 | /// Libraries loaded with [`os::windows::Library::this`]. |
| 150 | /// |
| 151 | /// This is equivalent to <code>[Library::open](None, [RTLD_LAZY] | [RTLD_LOCAL])</code>. |
| 152 | /// |
| 153 | /// [`os::windows::Library::this`]: crate::os::windows::Library::this |
| 154 | #[inline] |
| 155 | pub fn thisrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]this().() -> Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# { |
| 156 | unsafe { |
| 157 | // SAFE: this does not load any new shared library images, no danger in it executing |
| 158 | // initialiser routines. |
| 159 | Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library#::openrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]open().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#::<&OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>, RTLD_LAZYrust-analyzer cargo libloading 0.8.9 os/unix/consts/RTLD_LAZY. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().RTLD_LOCALrust-analyzer cargo libloading 0.8.9 os/unix/consts/RTLD_LOCAL.).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("this should never fail") |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /// Find and load an executable object file (shared library). |
| 164 | /// |
| 165 | /// See documentation for [`Library::this`] for further description of the behaviour |
| 166 | /// when the `filename` is `None`. Otherwise see [`Library::new`]. |
| 167 | /// |
| 168 | /// Corresponds to `dlopen(filename, flags)`. |
| 169 | /// |
| 170 | /// # Safety |
| 171 | /// |
| 172 | /// When a library is loaded, initialisation routines contained within the library are executed. |
| 173 | /// For the purposes of safety, the execution of these routines is conceptually the same calling an |
| 174 | /// unknown foreign function and may impose arbitrary requirements on the caller for the call |
| 175 | /// to be sound. |
| 176 | /// |
| 177 | /// Additionally, the callers of this function must also ensure that execution of the |
| 178 | /// termination routines contained within the library is safe as well. These routines may be |
| 179 | /// executed when the library is unloaded. |
| 180 | pub unsafe fn openrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]open().<P>(filename: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<P>, flags: rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library#, craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#> |
| 181 | where |
| 182 | P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>, |
| 183 | { |
| 184 | let filename = match filename { |
| 185 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 186 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref f) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cstr_cow_from_bytesrust-analyzer cargo libloading 0.8.9 util/cstr_cow_from_bytes().(f.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().), |
| 187 | }; |
| 188 | with_dlerrorrust-analyzer cargo libloading 0.8.9 os/unix/with_dlerror().( |
| 189 | move || { |
| 190 | let result = dlopenrust-analyzer cargo libloading 0.8.9 dlopen().( |
| 191 | match filename { |
| 192 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().(), |
| 193 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref f) => f.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), |
| 194 | }, |
| 195 | flags, |
| 196 | ); |
| 197 | // ensure filename lives until dlopen completes |
| 198 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(filename); |
| 199 | if result.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 200 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 201 | } else { |
| 202 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# { handlerust-analyzer cargo libloading 0.8.9 os/unix/Library#handle.: result }) |
| 203 | } |
| 204 | }, |
| 205 | |desc| craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#::DlOpenrust-analyzer cargo libloading 0.8.9 error/Error#DlOpen# { descrust-analyzer cargo libloading 0.8.9 error/Error#DlOpen#desc.: desc.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() }, |
| 206 | ) |
| 207 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#::DlOpenUnknownrust-analyzer cargo libloading 0.8.9 error/Error#DlOpenUnknown#)) |
| 208 | } |
| 209 | |
| 210 | unsafe fn get_implrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]get_impl().<T, F>(&self, symbol: &[u8], on_null: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T>, craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#> |
| 211 | where |
| 212 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T>, craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#>, |
| 213 | { |
| 214 | ensure_compatible_typesrust-analyzer cargo libloading 0.8.9 util/ensure_compatible_types().::<T, *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 215 | let symbol = cstr_cow_from_bytesrust-analyzer cargo libloading 0.8.9 util/cstr_cow_from_bytes().(symbol)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 216 | // `dlsym` may return nullptr in two cases: when a symbol genuinely points to a null |
| 217 | // pointer or the symbol cannot be found. In order to detect this case a double dlerror |
| 218 | // pattern must be used, which is, sadly, a little bit racy. |
| 219 | // |
| 220 | // We try to leave as little space as possible for this to occur, but we can’t exactly |
| 221 | // fully prevent it. |
| 222 | let result = with_dlerrorrust-analyzer cargo libloading 0.8.9 os/unix/with_dlerror().( |
| 223 | || { |
| 224 | dlerrorrust-analyzer cargo libloading 0.8.9 dlerror().(); |
| 225 | let symbol = dlsymrust-analyzer cargo libloading 0.8.9 dlsym().(self.handlerust-analyzer cargo libloading 0.8.9 os/unix/Library#handle., symbol.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().()); |
| 226 | if symbol.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 227 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 228 | } else { |
| 229 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol# { |
| 230 | pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer.: symbol, |
| 231 | pdrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pd.: markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 232 | }) |
| 233 | } |
| 234 | }, |
| 235 | |desc| craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#::DlSymrust-analyzer cargo libloading 0.8.9 error/Error#DlSym# { descrust-analyzer cargo libloading 0.8.9 error/Error#DlSym#desc.: desc.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() }, |
| 236 | ); |
| 237 | match result { |
| 238 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => on_null(), |
| 239 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e)) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), |
| 240 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(x) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(x), |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /// Get a pointer to a function or static variable by symbol name. |
| 245 | /// |
| 246 | /// The `symbol` may not contain any null bytes, with the exception of the last byte. Providing a |
| 247 | /// null terminated `symbol` may help to avoid an allocation. |
| 248 | /// |
| 249 | /// Symbol is interpreted as-is; no mangling is done. This means that symbols like `x::y` are |
| 250 | /// most likely invalid. |
| 251 | /// |
| 252 | /// # Safety |
| 253 | /// |
| 254 | /// Users of this API must specify the correct type of the function or variable loaded. Using a |
| 255 | /// `Symbol` with a wrong type is undefined. |
| 256 | /// |
| 257 | /// # Platform-specific behaviour |
| 258 | /// |
| 259 | /// Implementation of thread local variables is extremely platform specific and uses of such |
| 260 | /// variables that work on e.g. Linux may have unintended behaviour on other targets. |
| 261 | /// |
| 262 | /// On POSIX implementations where the `dlerror` function is not confirmed to be MT-safe (such |
| 263 | /// as FreeBSD), this function will unconditionally return an error when the underlying `dlsym` |
| 264 | /// call returns a null pointer. There are rare situations where `dlsym` returns a genuine null |
| 265 | /// pointer without it being an error. If loading a null pointer is something you care about, |
| 266 | /// consider using the [`Library::get_singlethreaded`] call. |
| 267 | #[inline(always)] |
| 268 | pub unsafe fn getrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]get().<T>(&self, symbol: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T>, craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#> { |
| 269 | extern crate cfg_ifrust-analyzer cargo libloading 0.8.9 os/unix/cfg_if/; |
| 270 | cfg_ifrust-analyzer cargo cfg-if 1.0.3 crate/::cfg_ifrust-analyzer cargo cfg-if 1.0.3 cfg_if!! { |
| 271 | // These targets are known to have MT-safe `dlerror`. |
| 272 | if #[cfg(any( |
| 273 | target_os = "linux", |
| 274 | target_os = "android", |
| 275 | target_os = "openbsd", |
| 276 | target_os = "macos", |
| 277 | target_os = "ios", |
| 278 | target_os = "solaris", |
| 279 | target_os = "illumos", |
| 280 | target_os = "redox", |
| 281 | target_os = "fuchsia", |
| 282 | target_os = "cygwin", |
| 283 | ))] { |
| 284 | self.get_singlethreadedrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]get_singlethreaded().(symbol) |
| 285 | } else { |
| 286 | self.get_impl(symbol, || Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#::DlSymUnknownrust-analyzer cargo libloading 0.8.9 error/Error#DlSymUnknown#)) |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /// Get a pointer to function or static variable by symbol name. |
| 292 | /// |
| 293 | /// The `symbol` may not contain any null bytes, with the exception of the last byte. Providing a |
| 294 | /// null terminated `symbol` may help to avoid an allocation. |
| 295 | /// |
| 296 | /// Symbol is interpreted as-is; no mangling is done. This means that symbols like `x::y` are |
| 297 | /// most likely invalid. |
| 298 | /// |
| 299 | /// # Safety |
| 300 | /// |
| 301 | /// Users of this API must specify the correct type of the function or variable loaded. |
| 302 | /// |
| 303 | /// It is up to the user of this library to ensure that no other calls to an MT-unsafe |
| 304 | /// implementation of `dlerror` occur during the execution of this function. Failing that, the |
| 305 | /// behaviour of this function is not defined. |
| 306 | /// |
| 307 | /// # Platform-specific behaviour |
| 308 | /// |
| 309 | /// The implementation of thread-local variables is extremely platform specific and uses of such |
| 310 | /// variables that work on e.g. Linux may have unintended behaviour on other targets. |
| 311 | #[inline(always)] |
| 312 | pub unsafe fn get_singlethreadedrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]get_singlethreaded().<T>(&self, symbol: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T>, craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#> { |
| 313 | self.get_implrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]get_impl().(symbol, || { |
| 314 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol# { |
| 315 | pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer.: ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().(), |
| 316 | pdrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pd.: markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 317 | }) |
| 318 | }) |
| 319 | } |
| 320 | |
| 321 | /// Convert the `Library` to a raw handle. |
| 322 | /// |
| 323 | /// The handle returned by this function shall be usable with APIs which accept handles |
| 324 | /// as returned by `dlopen`. |
| 325 | pub fn into_rawrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]into_raw().(self) -> *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void# { |
| 326 | let handle = self.handlerust-analyzer cargo libloading 0.8.9 os/unix/Library#handle.; |
| 327 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::forgetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/forget().(self); |
| 328 | handle |
| 329 | } |
| 330 | |
| 331 | /// Convert a raw handle returned by `dlopen`-family of calls to a `Library`. |
| 332 | /// |
| 333 | /// # Safety |
| 334 | /// |
| 335 | /// The pointer shall be a result of a successful call of the `dlopen`-family of functions or a |
| 336 | /// pointer previously returned by `Library::into_raw` call. It must be valid to call `dlclose` |
| 337 | /// with this pointer as an argument. |
| 338 | pub unsafe fn from_rawrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]from_raw().(handle: *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#) -> Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# { |
| 339 | Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# { handlerust-analyzer cargo libloading 0.8.9 os/unix/Library#handle. } |
| 340 | } |
| 341 | |
| 342 | /// Unload the library. |
| 343 | /// |
| 344 | /// This method might be a no-op, depending on the flags with which the `Library` was opened, |
| 345 | /// what library was opened or other platform specifics. |
| 346 | /// |
| 347 | /// You only need to call this if you are interested in handling any errors that may arise when |
| 348 | /// library is unloaded. Otherwise the implementation of `Drop` for `Library` will close the |
| 349 | /// library and ignore the errors were they arise. |
| 350 | /// |
| 351 | /// The underlying data structures may still get leaked if an error does occur. |
| 352 | pub fn closerust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]close().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#> { |
| 353 | let result = with_dlerrorrust-analyzer cargo libloading 0.8.9 os/unix/with_dlerror().( |
| 354 | || { |
| 355 | if unsafe { dlcloserust-analyzer cargo libloading 0.8.9 dlclose().(self.handlerust-analyzer cargo libloading 0.8.9 os/unix/Library#handle.) } rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 { |
| 356 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(()) |
| 357 | } else { |
| 358 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 359 | } |
| 360 | }, |
| 361 | |desc| craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#::DlCloserust-analyzer cargo libloading 0.8.9 error/Error#DlClose# { descrust-analyzer cargo libloading 0.8.9 error/Error#DlClose#desc.: desc.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() }, |
| 362 | ) |
| 363 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(craterust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#::DlCloseUnknownrust-analyzer cargo libloading 0.8.9 error/Error#DlCloseUnknown#)); |
| 364 | // While the library is not free'd yet in case of an error, there is no reason to try |
| 365 | // dropping it again, because all that will do is try calling `dlclose` again. only |
| 366 | // this time it would ignore the return result, which we already seen failing… |
| 367 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::forgetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/forget().(self); |
| 368 | result |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# { |
| 373 | fn droprust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library][Drop]drop().(&mut self) { |
| 374 | unsafe { |
| 375 | dlcloserust-analyzer cargo libloading 0.8.9 dlclose().(self.handlerust-analyzer cargo libloading 0.8.9 os/unix/Library#handle.); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library# { |
| 381 | fn fmtrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 382 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Library@{:p}", self.handlerust-analyzer cargo libloading 0.8.9 os/unix/Library#handle.)) |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /// Symbol from a library. |
| 387 | /// |
| 388 | /// A major difference compared to the cross-platform `Symbol` is that this does not ensure that the |
| 389 | /// `Symbol` does not outlive the `Library` it comes from. |
| 390 | pub struct Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T> { |
| 391 | pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer.: *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 392 | pdrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pd.: markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<T>, |
| 393 | } |
| 394 | |
| 395 | impl<T> Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T> { |
| 396 | /// Convert the loaded `Symbol` into a raw pointer. |
| 397 | pub fn into_rawrust-analyzer cargo libloading 0.8.9 os/unix/impl#[`Symbol<T>`]into_raw().(self) -> *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void# { |
| 398 | self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer. |
| 399 | } |
| 400 | |
| 401 | /// Convert the loaded `Symbol` into a raw pointer. |
| 402 | /// For unix this does the same as into_raw. |
| 403 | pub fn as_raw_ptrrust-analyzer cargo libloading 0.8.9 os/unix/impl#[`Symbol<T>`]as_raw_ptr().(self) -> *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void# { |
| 404 | self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer. |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | impl<T> Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>> { |
| 409 | /// Lift Option out of the symbol. |
| 410 | pub fn lift_optionrust-analyzer cargo libloading 0.8.9 os/unix/impl#[`Symbol<Option<T>>`]lift_option().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T>> { |
| 411 | if self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer..is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 412 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 413 | } else { |
| 414 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol# { |
| 415 | pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer.: self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer., |
| 416 | pdrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pd.: markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 417 | }) |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T> {} |
| 423 | unsafe impl<T: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#> Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T> {} |
| 424 | |
| 425 | impl<T> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T> { |
| 426 | fn clonerust-analyzer cargo libloading 0.8.9 os/unix/impl#[`Symbol<T>`][Clone]clone().(&self) -> Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T> { |
| 427 | Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol# { ..*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | impl<T> ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T> { |
| 432 | type Targetrust-analyzer cargo libloading 0.8.9 os/unix/impl#[`Symbol<T>`][Deref]Target# = T; |
| 433 | fn derefrust-analyzer cargo libloading 0.8.9 os/unix/impl#[`Symbol<T>`][Deref]deref().(&self) -> &T { |
| 434 | unsafe { |
| 435 | // Additional reference level for a dereference on `deref` return value. |
| 436 | &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().(&self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer. as *const *mut _ as *const T) |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | impl<T> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Symbolrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#<T> { |
| 442 | fn fmtrust-analyzer cargo libloading 0.8.9 os/unix/impl#[`Symbol<T>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 443 | unsafe { |
| 444 | let mut info = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<DlInforust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().(); |
| 445 | if dladdrrust-analyzer cargo libloading 0.8.9 dladdr().(self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer., info.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().0 { |
| 446 | let info = info.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().(); |
| 447 | if info.dli_snamerust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#dli_sname..is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]is_null().() { |
| 448 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 449 | "Symbol@{:p} from {:?}", |
| 450 | self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer., |
| 451 | CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(info.dli_fnamerust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#dli_fname.) |
| 452 | )) |
| 453 | } else { |
| 454 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 455 | "Symbol {:?}@{:p} from {:?}", |
| 456 | CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(info.dli_snamerust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#dli_sname.), |
| 457 | self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer., |
| 458 | CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(info.dli_fnamerust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#dli_fname.) |
| 459 | )) |
| 460 | } |
| 461 | } else { |
| 462 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Symbol@{:p}", self.pointerrust-analyzer cargo libloading 0.8.9 os/unix/Symbol#pointer.)) |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // Platform specific things |
| 469 | #[cfg_attr(any(target_os = "linux", target_os = "android"), link(name = "dl"))] |
| 470 | #[cfg_attr(any(target_os = "freebsd", target_os = "dragonfly"), link(name = "c"))] |
| 471 | extern "C" { |
| 472 | fn dlopenrust-analyzer cargo libloading 0.8.9 dlopen().(filename: *const rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, flags: rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#) -> *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#; |
| 473 | fn dlcloserust-analyzer cargo libloading 0.8.9 dlclose().(handle: *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#) -> rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 474 | fn dlsymrust-analyzer cargo libloading 0.8.9 dlsym().(handle: *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, symbol: *const rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#) -> *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#; |
| 475 | fn dlerrorrust-analyzer cargo libloading 0.8.9 dlerror().() -> *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#; |
| 476 | fn dladdrrust-analyzer cargo libloading 0.8.9 dladdr().(addr: *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, info: *mut DlInforust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#) -> rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_intrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_int#; |
| 477 | } |
| 478 | |
| 479 | #[repr(C)] |
| 480 | struct DlInforust-analyzer cargo libloading 0.8.9 os/unix/DlInfo# { |
| 481 | dli_fnamerust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#dli_fname.: *const rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, |
| 482 | dli_fbaserust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#dli_fbase.: *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 483 | dli_snamerust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#dli_sname.: *const rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_charrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_char#, |
| 484 | dli_saddrrust-analyzer cargo libloading 0.8.9 os/unix/DlInfo#dli_saddr.: *mut rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#, |
| 485 | } |