diff options
author | Haibo Huang <hhb@google.com> | 2021-01-14 10:25:20 -0800 |
---|---|---|
committer | Jeff Vander Stoep <jeffv@google.com> | 2021-01-15 15:44:45 +0100 |
commit | a808f0b96818463b4f91191aa7240d0a658b7cfd (patch) | |
tree | e4d69b01b606725d494bae74af52d6580bc4c06f | |
parent | bdf1f3062da9d9d393468fe1e601850bb7513d1a (diff) | |
download | libloading-a808f0b96818463b4f91191aa7240d0a658b7cfd.tar.gz |
Upgrade rust/crates/libloading to 0.6.7
Test: make
Change-Id: I1647c9b968bbc78df711476794e40829ccfb3034
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .github/workflows/libloading.yml | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | TEST_MAPPING | 7 | ||||
-rw-r--r-- | src/changelog.rs | 11 | ||||
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/os/windows/mod.rs | 39 | ||||
-rw-r--r-- | tests/functions.rs | 20 |
10 files changed, 83 insertions, 14 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index eb64010..2bb276f 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "c8b034167dae9e4b00c8c5e7dca651738f8bd421" + "sha1": "1cc40888d23607a066164238694f0ccab684555e" } } diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index aa9b3f6..811681d 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -6,7 +6,7 @@ on: - '*.mkd' - 'LICENSE' pull_request: - types: [opened, repoened, synchronize] + types: [opened, reopened, synchronize] jobs: native-test: @@ -12,7 +12,7 @@ [package] name = "libloading" -version = "0.6.6" +version = "0.6.7" authors = ["Simonas Kazlauskas <libloading@kazlauskas.me>"] description = "A safer binding to platform’s dynamic library loading utilities" documentation = "https://docs.rs/libloading/" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 6e4696b..5b687a0 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -3,7 +3,7 @@ name = "libloading" # When bumping # * Don’t forget to add an entry to `src/changelog.rs` # * If bumping a incompatible version, adjust documentation in `src/lib.rs` -version = "0.6.6" +version = "0.6.7" authors = ["Simonas Kazlauskas <libloading@kazlauskas.me>"] license = "ISC" repository = "https://github.com/nagisa/rust_libloading/" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/libloading/libloading-0.6.6.crate" + value: "https://static.crates.io/crates/libloading/libloading-0.6.7.crate" } - version: "0.6.6" + version: "0.6.7" license_type: NOTICE last_upgrade_date { - year: 2020 - month: 12 - day: 3 + year: 2021 + month: 1 + day: 14 } } diff --git a/TEST_MAPPING b/TEST_MAPPING index 7bc6ed2..03d7e78 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,12 +1,11 @@ -// Generated by cargo2android.py for tests in Android.bp +// Generated by cargo2android.py for tests that depend on this crate. { "presubmit": [ { - "host": true, - "name": "libsqlite3-sys_host_test_src_lib" + "name": "libsqlite3-sys_device_test_src_lib" }, { - "name": "libsqlite3-sys_device_test_src_lib" + "name": "keystore2_test" } ] } diff --git a/src/changelog.rs b/src/changelog.rs index 0ae7323..67f9cb0 100644 --- a/src/changelog.rs +++ b/src/changelog.rs @@ -3,6 +3,17 @@ // TODO: for the next breaking release rename `Error::LoadLibraryW` to `Error::LoadLibraryExW`. // TODO: for the next breaking release use `RTLD_LAZY | RTLD_LOCAL` by default on unix. +/// Release 0.6.7 (2021-01-14) +/// +/// * Added a [`os::windows::Library::open_already_loaded`] to obtain a handle to a library that +/// must already be loaded. There is no portable equivalent for all UNIX targets. Users who do not +/// care about portability across UNIX platforms may use [`os::unix::Library::open`] with +/// `libc::RTLD_NOLOAD`; +/// +/// [`os::windows::Library::open_already_loaded`]: crate::os::windows::Library::open_already_loaded +/// [`os::unix::Library::open`]: crate::os::unix::Library::open +pub mod r0_6_7 {} + /// Release 0.6.6 (2020-12-03) /// /// * Fix a double-release of resources when [`Library::close`] or [`os::windows::Library::close`] diff --git a/src/error.rs b/src/error.rs index 6ba5367..e1c465e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -55,7 +55,7 @@ pub enum Error { /// The source error. source: WindowsError }, - /// The `LoadLibraryW` call failed and system did not report an error. + /// The `GetModuleHandleExW` call failed and system did not report an error. GetModuleHandleExWUnknown, /// The `GetProcAddress` call failed. GetProcAddress { diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index da1b5c9..f1298f6 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -119,6 +119,45 @@ impl Library { } } + /// Load a module that is already loaded by the program. + /// + /// This function returns a `Library` corresponding to a module with the given name that is + /// already mapped into the address space of the process. If the module isn't found an error is + /// returned. + /// + /// If the `filename` does not include a full path and there are multiple different loaded + /// modules corresponding to the `filename`, it is impossible to predict which module handle + /// will be returned. For more information refer to [MSDN]. + /// + /// If the `filename` specifies a library filename without path and with extension omitted, + /// `.dll` extension is implicitly added. This behaviour may be suppressed by appending a + /// trailing `.` to the `filename`. + /// + /// This is equivalent to `GetModuleHandleExW(0, filename, _)`. + /// + /// [MSDN]: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandleexw + pub fn open_already_loaded<P: AsRef<OsStr>>(filename: P) -> Result<Library, crate::Error> { + let wide_filename: Vec<u16> = filename.as_ref().encode_wide().chain(Some(0)).collect(); + + let ret = unsafe { + let mut handle: HMODULE = std::ptr::null_mut(); + with_get_last_error(|source| crate::Error::GetModuleHandleExW { source }, || { + // Make sure no winapi calls as a result of drop happen inside this closure, because + // otherwise that might change the return value of the GetLastError. + let result = libloaderapi::GetModuleHandleExW(0, wide_filename.as_ptr(), &mut handle); + if result == 0 { + None + } else { + Some(Library(handle)) + } + }).map_err(|e| e.unwrap_or(crate::Error::GetModuleHandleExWUnknown)) + }; + + drop(wide_filename); // Drop wide_filename here to ensure it doesn’t get moved and dropped + // inside the closure by mistake. See comment inside the closure. + ret + } + /// Find and load a module, additionally adjusting behaviour with flags. /// /// See [`Library::new`] for documentation on handling of the `filename` argument. See the diff --git a/tests/functions.rs b/tests/functions.rs index e899344..35045e8 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -235,3 +235,23 @@ fn works_getlasterror0() { assert_eq!(errhandlingapi::GetLastError(), gle()) } } + +#[cfg(windows)] +#[test] +fn library_open_already_loaded() { + use libloading::os::windows::Library; + + // Present on Windows systems and NOT used by any other tests to prevent races. + const LIBPATH: &str = "Msftedit.dll"; + + // Not loaded yet. + assert!(match Library::open_already_loaded(LIBPATH) { + Err(libloading::Error::GetModuleHandleExW { .. }) => true, + _ => false, + }); + + let _lib = Library::new(LIBPATH).unwrap(); + + // Loaded now. + assert!(Library::open_already_loaded(LIBPATH).is_ok()); +} |