aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2024-02-02 10:13:28 +0100
committerJeff Vander Stoep <jeffv@google.com>2024-02-02 10:13:28 +0100
commit852cba42bb72e3f7ea5b47878f62a0f1c00e6d90 (patch)
treef16bff48aeaaf5872a827c86113294a2ca2b01cf
parent7fd07ea45fe86513943ae55e028a4d2f223238a8 (diff)
downloadlibloading-emu-34-3-release.tar.gz
Upgrade libloading to 0.8.1emu-34-3-release
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update external/rust/crates/libloading For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: I7fc24c3d01c219608877d9cb4abb84b85400abf6
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.github/workflows/libloading.yml2
-rw-r--r--Android.bp2
-rw-r--r--Cargo.toml13
-rw-r--r--Cargo.toml.orig13
-rw-r--r--METADATA25
-rw-r--r--README.mkd7
-rw-r--r--src/changelog.rs18
-rw-r--r--src/lib.rs2
-rw-r--r--src/os/unix/consts.rs12
-rw-r--r--src/os/windows/mod.rs135
-rw-r--r--tests/functions.rs20
12 files changed, 142 insertions, 109 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 1beb39f..37498d8 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "6e284984aee68cc2d1b7e7d5e7b5a2a2279cf8e3"
+ "sha1": "006afa9d614a2a5bd2ce666b657a3fb83ce2d090"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml
index 5837da4..3382da1 100644
--- a/.github/workflows/libloading.yml
+++ b/.github/workflows/libloading.yml
@@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- rust_toolchain: [nightly, stable, 1.40.0]
+ rust_toolchain: [nightly, stable, 1.48.0]
os: [ubuntu-latest, windows-latest, macOS-latest]
timeout-minutes: 20
steps:
diff --git a/Android.bp b/Android.bp
index f847d8a..2d2d5da 100644
--- a/Android.bp
+++ b/Android.bp
@@ -23,7 +23,7 @@ rust_library {
host_supported: true,
crate_name: "libloading",
cargo_env_compat: true,
- cargo_pkg_version: "0.7.4",
+ cargo_pkg_version: "0.8.1",
srcs: ["src/lib.rs"],
edition: "2015",
rustlibs: ["libcfg_if"],
diff --git a/Cargo.toml b/Cargo.toml
index 65168d5..0165453 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,9 +10,9 @@
# See Cargo.toml.orig for the original contents.
[package]
-rust-version = "1.40.0"
+rust-version = "1.48.0"
name = "libloading"
-version = "0.7.4"
+version = "0.8.1"
authors = ["Simonas Kazlauskas <libloading@kazlauskas.me>"]
description = "Bindings around the platform's dynamic library loading primitives with greatly improved memory safety."
documentation = "https://docs.rs/libloading/"
@@ -43,9 +43,10 @@ version = "1.1"
[target."cfg(unix)".dependencies.cfg-if]
version = "1"
-[target."cfg(windows)".dependencies.winapi]
-version = "0.3"
+[target."cfg(windows)".dependencies.windows-sys]
+version = "0.48"
features = [
- "errhandlingapi",
- "libloaderapi",
+ "Win32_Foundation",
+ "Win32_System_Diagnostics_Debug",
+ "Win32_System_LibraryLoader",
]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 3fdf0c8..84d1755 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 to an incompatible version, adjust the documentation in `src/lib.rs`
-version = "0.7.4"
+version = "0.8.1"
authors = ["Simonas Kazlauskas <libloading@kazlauskas.me>"]
license = "ISC"
repository = "https://github.com/nagisa/rust_libloading/"
@@ -12,13 +12,14 @@ readme = "README.mkd"
description = "Bindings around the platform's dynamic library loading primitives with greatly improved memory safety."
keywords = ["dlopen", "load", "shared", "dylib"]
categories = ["api-bindings"]
-rust-version = "1.40.0"
+rust-version = "1.48.0"
-[target.'cfg(windows)'.dependencies.winapi]
-version = "0.3"
+[target.'cfg(windows)'.dependencies.windows-sys]
+version = "0.48"
features = [
- "errhandlingapi",
- "libloaderapi",
+ "Win32_Foundation",
+ "Win32_System_Diagnostics_Debug",
+ "Win32_System_LibraryLoader",
]
[target.'cfg(unix)'.dependencies.cfg-if]
diff --git a/METADATA b/METADATA
index ca107f6..043f360 100644
--- a/METADATA
+++ b/METADATA
@@ -1,23 +1,20 @@
# This project was upgraded with external_updater.
-# Usage: tools/external_updater/updater.sh update rust/crates/libloading
-# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+# Usage: tools/external_updater/updater.sh update external/rust/crates/libloading
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
name: "libloading"
description: "Bindings around the platform\'s dynamic library loading primitives with greatly improved memory safety."
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/libloading"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/libloading/libloading-0.7.4.crate"
- }
- version: "0.7.4"
license_type: NOTICE
last_upgrade_date {
- year: 2022
- month: 12
- day: 12
+ year: 2024
+ month: 2
+ day: 2
+ }
+ homepage: "https://crates.io/crates/libloading"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/libloading/libloading-0.8.1.crate"
+ version: "0.8.1"
}
}
diff --git a/README.mkd b/README.mkd
index 66abb30..7ff55b0 100644
--- a/README.mkd
+++ b/README.mkd
@@ -1,8 +1,11 @@
# libloading
-Bindings around the platform's dynamic library loading primitives with greatly improved memory safety. The most important safety guarantee of this library is the prevention of dangling `Symbol`s that may occur after a `Library` is unloaded.
+Bindings around the platform's dynamic library loading primitives with greatly improved memory
+safety. The most important safety guarantee of this library is the prevention of dangling `Symbol`s
+that may occur after a `Library` is unloaded.
-Using this library allows the loading of dynamic libraries, also known as shared libraries, as well as the use of the functions and static variables that these libraries may contain.
+Using this library allows the loading of dynamic libraries, also known as shared libraries, as well
+as the use of the functions and static variables that these libraries may contain.
* [Documentation][docs]
* [Changelog][changelog]
diff --git a/src/changelog.rs b/src/changelog.rs
index 162544f..536834b 100644
--- a/src/changelog.rs
+++ b/src/changelog.rs
@@ -1,5 +1,23 @@
//! The change log.
+/// Release 0.8.1 (2023-09-30)
+///
+/// ## Non-breaking changes
+///
+/// * Support for GNU Hurd.
+
+/// Release 0.8.0 (2023-04-11)
+///
+/// ## (Potentially) breaking changes
+///
+/// * `winapi` dependency has been replaced with `windows-sys`.
+/// * As a result the MSRV has been increased to 1.48.
+///
+/// ## Non-breaking changes
+///
+/// * Support for the QNX Neutrino target has been added.
+pub mod r0_8_0 {}
+
/// Release 0.7.4 (2022-11-07)
///
/// This release has no functional changes.
diff --git a/src/lib.rs b/src/lib.rs
index 6f0e4cb..b517a5c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,7 +16,7 @@
//!
//! ```toml
//! [dependencies]
-//! libloading = "0.7"
+//! libloading = "0.8"
//! ```
//!
//! # Usage
diff --git a/src/os/unix/consts.rs b/src/os/unix/consts.rs
index ea7a6a1..ed3edaf 100644
--- a/src/os/unix/consts.rs
+++ b/src/os/unix/consts.rs
@@ -82,6 +82,8 @@ mod posix {
target_os = "fuchsia",
target_os = "redox",
+ target_os = "nto",
+ target_os = "hurd",
))] {
pub(super) const RTLD_LAZY: c_int = 1;
} else {
@@ -115,6 +117,8 @@ mod posix {
target_os = "fuchsia",
target_os = "redox",
+ target_os = "nto",
+ target_os = "hurd",
))] {
pub(super) const RTLD_NOW: c_int = 2;
} else if #[cfg(all(target_os = "android",target_pointer_width = "32"))] {
@@ -162,6 +166,8 @@ mod posix {
target_os = "fuchsia",
target_os = "redox",
+ target_os = "nto",
+ target_os = "hurd",
))] {
pub(super) const RTLD_GLOBAL: c_int = 0x100;
} else {
@@ -172,7 +178,10 @@ mod posix {
}
cfg_if! {
- if #[cfg(target_os = "netbsd")] {
+ if #[cfg(any(
+ target_os = "netbsd",
+ target_os = "nto",
+ ))] {
pub(super) const RTLD_LOCAL: c_int = 0x200;
} else if #[cfg(target_os = "aix")] {
pub(super) const RTLD_LOCAL: c_int = 0x80000;
@@ -200,6 +209,7 @@ mod posix {
target_os = "fuchsia",
target_os = "redox",
+ target_os = "hurd",
))] {
pub(super) const RTLD_LOCAL: c_int = 0;
} else {
diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs
index e3da940..ff96ef8 100644
--- a/src/os/windows/mod.rs
+++ b/src/os/windows/mod.rs
@@ -2,38 +2,44 @@
// same rustdoc build visible.
#[cfg(all(libloading_docs, not(windows)))]
mod windows_imports {
- pub(super) enum WORD {}
- pub(super) struct DWORD;
pub(super) enum HMODULE {}
pub(super) enum FARPROC {}
+ #[allow(non_camel_case_types)]
+ pub(super) enum THREAD_ERROR_MODE {}
+ #[allow(non_camel_case_types)]
+ pub(super) struct LOAD_LIBRARY_FLAGS;
pub(super) mod consts {
- use super::DWORD;
- pub(crate) const LOAD_IGNORE_CODE_AUTHZ_LEVEL: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_AS_DATAFILE: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_AS_IMAGE_RESOURCE: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_SEARCH_APPLICATION_DIR: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_SEARCH_DEFAULT_DIRS: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_SEARCH_SYSTEM32: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_SEARCH_USER_DIRS: DWORD = DWORD;
- pub(crate) const LOAD_WITH_ALTERED_SEARCH_PATH: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_REQUIRE_SIGNED_TARGET: DWORD = DWORD;
- pub(crate) const LOAD_LIBRARY_SAFE_CURRENT_DIRS: DWORD = DWORD;
+ use super::LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_IGNORE_CODE_AUTHZ_LEVEL: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_AS_DATAFILE: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_AS_IMAGE_RESOURCE: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_SEARCH_APPLICATION_DIR: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_SEARCH_DEFAULT_DIRS: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_SEARCH_SYSTEM32: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_SEARCH_USER_DIRS: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_WITH_ALTERED_SEARCH_PATH: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_REQUIRE_SIGNED_TARGET: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
+ pub(crate) const LOAD_LIBRARY_SAFE_CURRENT_DIRS: LOAD_LIBRARY_FLAGS = LOAD_LIBRARY_FLAGS;
}
}
#[cfg(any(not(libloading_docs), windows))]
mod windows_imports {
- extern crate winapi;
- pub(super) use self::winapi::shared::minwindef::{WORD, DWORD, HMODULE, FARPROC};
- pub(super) use self::winapi::shared::ntdef::WCHAR;
- pub(super) use self::winapi::um::{errhandlingapi, libloaderapi};
+ extern crate windows_sys;
+ pub(super) use self::windows_sys::Win32::Foundation::{GetLastError, FARPROC, HMODULE};
+ pub(super) use self::windows_sys::Win32::System::Diagnostics::Debug as debug_api;
+ pub(super) use self::windows_sys::Win32::System::Diagnostics::Debug::SEM_FAILCRITICALERRORS;
+ pub(super) use self::windows_sys::Win32::System::Diagnostics::Debug::THREAD_ERROR_MODE;
+
+ pub(super) use self::windows_sys::Win32::System::LibraryLoader as library_loader;
+ pub(super) use self::windows_sys::Win32::System::LibraryLoader::LOAD_LIBRARY_FLAGS;
+
pub(super) use std::os::windows::ffi::{OsStrExt, OsStringExt};
- pub(super) const SEM_FAILCE: DWORD = 1;
pub(super) mod consts {
- pub(crate) use super::winapi::um::libloaderapi::{
+ pub(crate) use super::windows_sys::Win32::System::LibraryLoader::{
LOAD_IGNORE_CODE_AUTHZ_LEVEL,
LOAD_LIBRARY_AS_DATAFILE,
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE,
@@ -116,9 +122,9 @@ impl Library {
/// [MSDN]: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandleexw
pub fn this() -> Result<Library, crate::Error> {
unsafe {
- let mut handle: HMODULE = std::ptr::null_mut();
+ let mut handle: HMODULE = 0;
with_get_last_error(|source| crate::Error::GetModuleHandleExW { source }, || {
- let result = libloaderapi::GetModuleHandleExW(0, std::ptr::null_mut(), &mut handle);
+ let result = library_loader::GetModuleHandleExW(0, std::ptr::null_mut(), &mut handle);
if result == 0 {
None
} else {
@@ -149,11 +155,11 @@ impl Library {
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();
+ let mut handle: HMODULE = 0;
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);
+ let result = library_loader::GetModuleHandleExW(0, wide_filename.as_ptr(), &mut handle);
if result == 0 {
None
} else {
@@ -186,16 +192,15 @@ impl Library {
/// Additionally, the callers of this function must also ensure that execution of the
/// termination routines contained within the library is safe as well. These routines may be
/// executed when the library is unloaded.
- pub unsafe fn load_with_flags<P: AsRef<OsStr>>(filename: P, flags: DWORD) -> Result<Library, crate::Error> {
+ pub unsafe fn load_with_flags<P: AsRef<OsStr>>(filename: P, flags: LOAD_LIBRARY_FLAGS) -> Result<Library, crate::Error> {
let wide_filename: Vec<u16> = filename.as_ref().encode_wide().chain(Some(0)).collect();
let _guard = ErrorModeGuard::new();
let ret = with_get_last_error(|source| crate::Error::LoadLibraryExW { 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 handle =
- libloaderapi::LoadLibraryExW(wide_filename.as_ptr(), std::ptr::null_mut(), flags);
- if handle.is_null() {
+ let handle = library_loader::LoadLibraryExW(wide_filename.as_ptr(), 0, flags);
+ if handle == 0 {
None
} else {
Some(Library(handle))
@@ -221,8 +226,8 @@ impl Library {
ensure_compatible_types::<T, FARPROC>()?;
let symbol = cstr_cow_from_bytes(symbol)?;
with_get_last_error(|source| crate::Error::GetProcAddress { source }, || {
- let symbol = libloaderapi::GetProcAddress(self.0, symbol.as_ptr());
- if symbol.is_null() {
+ let symbol = library_loader::GetProcAddress(self.0, symbol.as_ptr().cast());
+ if symbol.is_none() {
None
} else {
Some(Symbol {
@@ -238,12 +243,12 @@ impl Library {
/// # Safety
///
/// Users of this API must specify the correct type of the function or variable loaded.
- pub unsafe fn get_ordinal<T>(&self, ordinal: WORD) -> Result<Symbol<T>, crate::Error> {
+ pub unsafe fn get_ordinal<T>(&self, ordinal: u16) -> Result<Symbol<T>, crate::Error> {
ensure_compatible_types::<T, FARPROC>()?;
with_get_last_error(|source| crate::Error::GetProcAddress { source }, || {
- let ordinal = ordinal as usize as *mut _;
- let symbol = libloaderapi::GetProcAddress(self.0, ordinal);
- if symbol.is_null() {
+ let ordinal = ordinal as usize as *const _;
+ let symbol = library_loader::GetProcAddress(self.0, ordinal);
+ if symbol.is_none() {
None
} else {
Some(Symbol {
@@ -280,7 +285,7 @@ impl Library {
/// The underlying data structures may still get leaked if an error does occur.
pub fn close(self) -> Result<(), crate::Error> {
let result = with_get_last_error(|source| crate::Error::FreeLibrary { source }, || {
- if unsafe { libloaderapi::FreeLibrary(self.0) == 0 } {
+ if unsafe { library_loader::FreeLibrary(self.0) == 0 } {
None
} else {
Some(())
@@ -296,7 +301,7 @@ impl Library {
impl Drop for Library {
fn drop(&mut self) {
- unsafe { libloaderapi::FreeLibrary(self.0); }
+ unsafe { library_loader::FreeLibrary(self.0); }
}
}
@@ -305,17 +310,17 @@ impl fmt::Debug for Library {
unsafe {
// FIXME: use Maybeuninit::uninit_array when stable
let mut buf =
- mem::MaybeUninit::<[mem::MaybeUninit::<WCHAR>; 1024]>::uninit().assume_init();
- let len = libloaderapi::GetModuleFileNameW(self.0,
+ mem::MaybeUninit::<[mem::MaybeUninit<u16>; 1024]>::uninit().assume_init();
+ let len = library_loader::GetModuleFileNameW(self.0,
buf[..].as_mut_ptr().cast(), 1024) as usize;
if len == 0 {
- f.write_str(&format!("Library@{:p}", self.0))
+ f.write_str(&format!("Library@{:#x}", self.0))
} else {
let string: OsString = OsString::from_wide(
// FIXME: use Maybeuninit::slice_get_ref when stable
- &*(&buf[..len] as *const [_] as *const [WCHAR])
+ &*(&buf[..len] as *const [_] as *const [u16]),
);
- f.write_str(&format!("Library@{:p} from {:?}", self.0, string))
+ f.write_str(&format!("Library@{:#x} from {:?}", self.0, string))
}
}
}
@@ -340,7 +345,7 @@ impl<T> Symbol<T> {
impl<T> Symbol<Option<T>> {
/// Lift Option out of the symbol.
pub fn lift_option(self) -> Option<Symbol<T>> {
- if self.pointer.is_null() {
+ if self.pointer.is_none() {
None
} else {
Some(Symbol {
@@ -363,33 +368,33 @@ impl<T> Clone for Symbol<T> {
impl<T> ::std::ops::Deref for Symbol<T> {
type Target = T;
fn deref(&self) -> &T {
- unsafe {
- // Additional reference level for a dereference on `deref` return value.
- &*(&self.pointer as *const *mut _ as *const T)
- }
+ unsafe { &*((&self.pointer) as *const FARPROC as *const T) }
}
}
impl<T> fmt::Debug for Symbol<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.write_str(&format!("Symbol@{:p}", self.pointer))
+ match self.pointer {
+ None => f.write_str("Symbol@0x0"),
+ Some(ptr) => f.write_str(&format!("Symbol@{:p}", ptr as *const ())),
+ }
}
}
-struct ErrorModeGuard(DWORD);
+struct ErrorModeGuard(THREAD_ERROR_MODE);
impl ErrorModeGuard {
#[allow(clippy::if_same_then_else)]
fn new() -> Option<ErrorModeGuard> {
unsafe {
let mut previous_mode = 0;
- if errhandlingapi::SetThreadErrorMode(SEM_FAILCE, &mut previous_mode) == 0 {
+ if debug_api::SetThreadErrorMode(SEM_FAILCRITICALERRORS, &mut previous_mode) == 0 {
// How in the world is it possible for what is essentially a simple variable swap
// to fail? For now we just ignore the error -- the worst that can happen here is
// the previous mode staying on and user seeing a dialog error on older Windows
// machines.
None
- } else if previous_mode == SEM_FAILCE {
+ } else if previous_mode == SEM_FAILCRITICALERRORS {
None
} else {
Some(ErrorModeGuard(previous_mode))
@@ -401,7 +406,7 @@ impl ErrorModeGuard {
impl Drop for ErrorModeGuard {
fn drop(&mut self) {
unsafe {
- errhandlingapi::SetThreadErrorMode(self.0, ptr::null_mut());
+ debug_api::SetThreadErrorMode(self.0, ptr::null_mut());
}
}
}
@@ -410,7 +415,7 @@ fn with_get_last_error<T, F>(wrap: fn(crate::error::WindowsError) -> crate::Erro
-> Result<T, Option<crate::Error>>
where F: FnOnce() -> Option<T> {
closure().ok_or_else(|| {
- let error = unsafe { errhandlingapi::GetLastError() };
+ let error = unsafe { GetLastError() };
if error == 0 {
None
} else {
@@ -425,7 +430,7 @@ where F: FnOnce() -> Option<T> {
/// recommended for use in setup programs that must run extracted DLLs during installation.
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_IGNORE_CODE_AUTHZ_LEVEL: DWORD = consts::LOAD_IGNORE_CODE_AUTHZ_LEVEL;
+pub const LOAD_IGNORE_CODE_AUTHZ_LEVEL: LOAD_LIBRARY_FLAGS = consts::LOAD_IGNORE_CODE_AUTHZ_LEVEL;
/// Map the file into the calling process’ virtual address space as if it were a data file.
///
@@ -435,7 +440,7 @@ pub const LOAD_IGNORE_CODE_AUTHZ_LEVEL: DWORD = consts::LOAD_IGNORE_CODE_AUTHZ_L
/// messages or resources from it.
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_AS_DATAFILE: DWORD = consts::LOAD_LIBRARY_AS_DATAFILE;
+pub const LOAD_LIBRARY_AS_DATAFILE: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_AS_DATAFILE;
/// Map the file into the calling process’ virtual address space as if it were a data file.
///
@@ -444,7 +449,7 @@ pub const LOAD_LIBRARY_AS_DATAFILE: DWORD = consts::LOAD_LIBRARY_AS_DATAFILE;
/// while it is in use. However, the DLL can still be opened by other processes.
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE: DWORD = consts::LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE;
+pub const LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE;
/// Map the file into the process’ virtual address space as an image file.
///
@@ -456,7 +461,7 @@ pub const LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE: DWORD = consts::LOAD_LIBRARY_AS_DA
/// [`LOAD_LIBRARY_AS_DATAFILE`].
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_AS_IMAGE_RESOURCE: DWORD = consts::LOAD_LIBRARY_AS_IMAGE_RESOURCE;
+pub const LOAD_LIBRARY_AS_IMAGE_RESOURCE: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_AS_IMAGE_RESOURCE;
/// Search the application's installation directory for the DLL and its dependencies.
///
@@ -464,7 +469,7 @@ pub const LOAD_LIBRARY_AS_IMAGE_RESOURCE: DWORD = consts::LOAD_LIBRARY_AS_IMAGE_
/// [`LOAD_WITH_ALTERED_SEARCH_PATH`].
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_SEARCH_APPLICATION_DIR: DWORD = consts::LOAD_LIBRARY_SEARCH_APPLICATION_DIR;
+pub const LOAD_LIBRARY_SEARCH_APPLICATION_DIR: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_SEARCH_APPLICATION_DIR;
/// Search default directories when looking for the DLL and its dependencies.
///
@@ -474,7 +479,7 @@ pub const LOAD_LIBRARY_SEARCH_APPLICATION_DIR: DWORD = consts::LOAD_LIBRARY_SEAR
/// [`LOAD_WITH_ALTERED_SEARCH_PATH`].
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_SEARCH_DEFAULT_DIRS: DWORD = consts::LOAD_LIBRARY_SEARCH_DEFAULT_DIRS;
+pub const LOAD_LIBRARY_SEARCH_DEFAULT_DIRS: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_SEARCH_DEFAULT_DIRS;
/// Directory that contains the DLL is temporarily added to the beginning of the list of
/// directories that are searched for the DLL’s dependencies.
@@ -485,7 +490,7 @@ pub const LOAD_LIBRARY_SEARCH_DEFAULT_DIRS: DWORD = consts::LOAD_LIBRARY_SEARCH_
/// with [`LOAD_WITH_ALTERED_SEARCH_PATH`].
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR: DWORD = consts::LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
+pub const LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
/// Search `%windows%\system32` for the DLL and its dependencies.
///
@@ -493,7 +498,7 @@ pub const LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR: DWORD = consts::LOAD_LIBRARY_SEARCH_
/// [`LOAD_WITH_ALTERED_SEARCH_PATH`].
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_SEARCH_SYSTEM32: DWORD = consts::LOAD_LIBRARY_SEARCH_SYSTEM32;
+pub const LOAD_LIBRARY_SEARCH_SYSTEM32: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_SEARCH_SYSTEM32;
/// Directories added using the `AddDllDirectory` or the `SetDllDirectory` function are searched
/// for the DLL and its dependencies.
@@ -503,7 +508,7 @@ pub const LOAD_LIBRARY_SEARCH_SYSTEM32: DWORD = consts::LOAD_LIBRARY_SEARCH_SYST
/// combined with [`LOAD_WITH_ALTERED_SEARCH_PATH`].
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_SEARCH_USER_DIRS: DWORD = consts::LOAD_LIBRARY_SEARCH_USER_DIRS;
+pub const LOAD_LIBRARY_SEARCH_USER_DIRS: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_SEARCH_USER_DIRS;
/// If `filename` specifies an absolute path, the system uses the alternate file search strategy
/// discussed in the [Remarks section] to find associated executable modules that the specified
@@ -518,15 +523,15 @@ pub const LOAD_LIBRARY_SEARCH_USER_DIRS: DWORD = consts::LOAD_LIBRARY_SEARCH_USE
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
///
/// [Remarks]: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#remarks
-pub const LOAD_WITH_ALTERED_SEARCH_PATH: DWORD = consts::LOAD_WITH_ALTERED_SEARCH_PATH;
+pub const LOAD_WITH_ALTERED_SEARCH_PATH: LOAD_LIBRARY_FLAGS = consts::LOAD_WITH_ALTERED_SEARCH_PATH;
/// Specifies that the digital signature of the binary image must be checked at load time.
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_REQUIRE_SIGNED_TARGET: DWORD = consts::LOAD_LIBRARY_REQUIRE_SIGNED_TARGET;
+pub const LOAD_LIBRARY_REQUIRE_SIGNED_TARGET: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_REQUIRE_SIGNED_TARGET;
/// Allow loading a DLL for execution from the current directory only if it is under a directory in
/// the Safe load list.
///
/// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
-pub const LOAD_LIBRARY_SAFE_CURRENT_DIRS: DWORD = consts::LOAD_LIBRARY_SAFE_CURRENT_DIRS;
+pub const LOAD_LIBRARY_SAFE_CURRENT_DIRS: LOAD_LIBRARY_FLAGS = consts::LOAD_LIBRARY_SAFE_CURRENT_DIRS;
diff --git a/tests/functions.rs b/tests/functions.rs
index c8d1952..a0175a6 100644
--- a/tests/functions.rs
+++ b/tests/functions.rs
@@ -1,5 +1,5 @@
#[cfg(windows)]
-extern crate winapi;
+extern crate windows_sys;
extern crate libloading;
use libloading::{Library, Symbol};
@@ -237,14 +237,13 @@ fn library_this() {
#[test]
fn works_getlasterror() {
use libloading::os::windows::{Library, Symbol};
- use winapi::shared::minwindef::DWORD;
- use winapi::um::errhandlingapi;
+ use windows_sys::Win32::Foundation::{GetLastError, SetLastError};
unsafe {
let lib = Library::new("kernel32.dll").unwrap();
- let gle: Symbol<unsafe extern "system" fn() -> DWORD> = lib.get(b"GetLastError").unwrap();
- errhandlingapi::SetLastError(42);
- assert_eq!(errhandlingapi::GetLastError(), gle())
+ let gle: Symbol<unsafe extern "system" fn() -> u32> = lib.get(b"GetLastError").unwrap();
+ SetLastError(42);
+ assert_eq!(GetLastError(), gle())
}
}
@@ -252,14 +251,13 @@ fn works_getlasterror() {
#[test]
fn works_getlasterror0() {
use libloading::os::windows::{Library, Symbol};
- use winapi::shared::minwindef::DWORD;
- use winapi::um::errhandlingapi;
+ use windows_sys::Win32::Foundation::{GetLastError, SetLastError};
unsafe {
let lib = Library::new("kernel32.dll").unwrap();
- let gle: Symbol<unsafe extern "system" fn() -> DWORD> = lib.get(b"GetLastError\0").unwrap();
- errhandlingapi::SetLastError(42);
- assert_eq!(errhandlingapi::GetLastError(), gle())
+ let gle: Symbol<unsafe extern "system" fn() -> u32> = lib.get(b"GetLastError\0").unwrap();
+ SetLastError(42);
+ assert_eq!(GetLastError(), gle())
}
}