Debian Codegraph @

src/os/windows/mod.rs

raw symbols SCIP
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(windows)))]
4 mod windows_imports {}
5 #[cfg(any(not(libloading_docs), windows))]
6 mod windows_imports {
7 use super::{BOOL, DWORD, FARPROC, HANDLE, HMODULE};
8 pub(super) use std::os::windows::ffi::{OsStrExt, OsStringExt};
9 windows_link::link!("kernel32.dll" "system" fn GetLastError() -> DWORD);
10 windows_link::link!("kernel32.dll" "system" fn SetThreadErrorMode(new_mode: DWORD, old_mode: *mut DWORD) -> BOOL);
11 windows_link::link!("kernel32.dll" "system" fn GetModuleHandleExW(flags: u32, module_name: *const u16, module: *mut HMODULE) -> BOOL);
12 windows_link::link!("kernel32.dll" "system" fn FreeLibrary(module: HMODULE) -> BOOL);
13 windows_link::link!("kernel32.dll" "system" fn LoadLibraryExW(filename: *const u16, file: HANDLE, flags: DWORD) -> HMODULE);
14 windows_link::link!("kernel32.dll" "system" fn GetModuleFileNameW(module: HMODULE, filename: *mut u16, size: DWORD) -> DWORD);
15 windows_link::link!("kernel32.dll" "system" fn GetProcAddress(module: HMODULE, procname: *const u8) -> FARPROC);
16 }
17
18 use self::windows_imports::*;
19 use std::ffi::{OsStr, OsString};
20 use std::os::raw;
21 use std::{fmt, io, marker, mem, ptr};
22 use util::{cstr_cow_from_bytes, ensure_compatible_types};
23
24 /// The platform-specific counterpart of the cross-platform [`Library`](crate::Library).
25 pub struct Library(HMODULE);
26
27 unsafe impl Send for Library {}
28 // Now, this is sort-of-tricky. MSDN documentation does not really make any claims as to safety of
29 // the Win32 APIs. Sadly, whomever I asked, even current and former Microsoft employees, couldn’t
30 // say for sure whether the Win32 APIs used to implement `Library` are thread-safe or not.
31 //
32 // My investigation ended up with a question about thread-safety properties of the API involved
33 // being sent to an internal (to MS) general question mailing-list. The conclusion of the mail is
34 // as such:
35 //
36 // * Nobody inside MS (at least out of all of the people who have seen the question) knows for
37 // sure either;
38 // * However, the general consensus between MS developers is that one can rely on the API being
39 // thread-safe. In case it is not thread-safe it should be considered a bug on the Windows
40 // part. (NB: bugs filed at https://connect.microsoft.com/ against Windows Server)
41 unsafe impl Sync for Library {}
42
43 impl Library {
44 /// Find and load a module.
45 ///
46 /// If the `filename` specifies a full path, the function only searches that path for the
47 /// module. Otherwise, if the `filename` specifies a relative path or a module name without a
48 /// path, the function uses a Windows-specific search strategy to find the module. For more
49 /// information, see the [Remarks on MSDN][msdn].
50 ///
51 /// If the `filename` specifies a library filename without a path and with the extension omitted,
52 /// the `.dll` extension is implicitly added. This behaviour may be suppressed by appending a
53 /// trailing `.` to the `filename`.
54 ///
55 /// This is equivalent to <code>[Library::load_with_flags](filename, 0)</code>.
56 ///
57 /// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryw#remarks
58 ///
59 /// # Safety
60 ///
61 /// When a library is loaded, initialisation routines contained within the library are executed.
62 /// For the purposes of safety, the execution of these routines is conceptually the same calling an
63 /// unknown foreign function and may impose arbitrary requirements on the caller for the call
64 /// to be sound.
65 ///
66 /// Additionally, the callers of this function must also ensure that execution of the
67 /// termination routines contained within the library is safe as well. These routines may be
68 /// executed when the library is unloaded.
69 #[inline]
70 pub unsafe fn new<P: AsRef<OsStr>>(filename: P) -> Result<Library, crate::Error> {
71 Library::load_with_flags(filename, 0)
72 }
73
74 /// Get the `Library` representing the original program executable.
75 ///
76 /// Note that the behaviour of the `Library` loaded with this method is different from
77 /// Libraries loaded with [`os::unix::Library::this`]. For more information refer to [MSDN].
78 ///
79 /// Corresponds to `GetModuleHandleExW(0, NULL, _)`.
80 ///
81 /// [`os::unix::Library::this`]: crate::os::unix::Library::this
82 /// [MSDN]: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandleexw
83 pub fn this() -> Result<Library, crate::Error> {
84 unsafe {
85 let mut handle: HMODULE = 0;
86 with_get_last_error(
87 |source| crate::Error::GetModuleHandleExW { source },
88 || {
89 let result = GetModuleHandleExW(0, std::ptr::null_mut(), &mut handle);
90 if result == 0 {
91 None
92 } else {
93 Some(Library(handle))
94 }
95 },
96 )
97 .map_err(|e| e.unwrap_or(crate::Error::GetModuleHandleExWUnknown))
98 }
99 }
100
101 /// Get a module that is already loaded by the program.
102 ///
103 /// This function returns a `Library` corresponding to a module with the given name that is
104 /// already mapped into the address space of the process. If the module isn't found, an error is
105 /// returned.
106 ///
107 /// If the `filename` does not include a full path and there are multiple different loaded
108 /// modules corresponding to the `filename`, it is impossible to predict which module handle
109 /// will be returned. For more information refer to [MSDN].
110 ///
111 /// If the `filename` specifies a library filename without a path and with the extension omitted,
112 /// the `.dll` extension is implicitly added. This behaviour may be suppressed by appending a
113 /// trailing `.` to the `filename`.
114 ///
115 /// This is equivalent to `GetModuleHandleExW(0, filename, _)`.
116 ///
117 /// [MSDN]: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandleexw
118 pub fn open_already_loaded<P: AsRef<OsStr>>(filename: P) -> Result<Library, crate::Error> {
119 let wide_filename: Vec<u16> = filename.as_ref().encode_wide().chain(Some(0)).collect();
120
121 let ret = unsafe {
122 let mut handle: HMODULE = 0;
123 with_get_last_error(
124 |source| crate::Error::GetModuleHandleExW { source },
125 || {
126 // Make sure no winapi calls as a result of drop happen inside this closure, because
127 // otherwise that might change the return value of the GetLastError.
128 let result = GetModuleHandleExW(0, wide_filename.as_ptr(), &mut handle);
129 if result == 0 {
130 None
131 } else {
132 Some(Library(handle))
133 }
134 },
135 )
136 .map_err(|e| e.unwrap_or(crate::Error::GetModuleHandleExWUnknown))
137 };
138
139 drop(wide_filename); // Drop wide_filename here to ensure it doesn’t get moved and dropped
140 // inside the closure by mistake. See comment inside the closure.
141 ret
142 }
143
144 /// Find and load a module, additionally adjusting behaviour with flags.
145 ///
146 /// See [`Library::new`] for documentation on the handling of the `filename` argument. See the
147 /// [flag table on MSDN][flags] for information on applicable values for the `flags` argument.
148 ///
149 /// Corresponds to `LoadLibraryExW(filename, reserved: NULL, flags)`.
150 ///
151 /// [flags]: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters
152 ///
153 /// # Safety
154 ///
155 /// When a library is loaded, initialisation routines contained within the library are executed.
156 /// For the purposes of safety, the execution of these routines is conceptually the same calling an
157 /// unknown foreign function and may impose arbitrary requirements on the caller for the call
158 /// to be sound.
159 ///
160 /// Additionally, the callers of this function must also ensure that execution of the
161 /// termination routines contained within the library is safe as well. These routines may be
162 /// executed when the library is unloaded.
163 pub unsafe fn load_with_flags<P: AsRef<OsStr>>(
164 filename: P,
165 flags: LOAD_LIBRARY_FLAGS,
166 ) -> Result<Library, crate::Error> {
167 let wide_filename: Vec<u16> = filename.as_ref().encode_wide().chain(Some(0)).collect();
168 let _guard = ErrorModeGuard::new();
169
170 let ret = with_get_last_error(
171 |source| crate::Error::LoadLibraryExW { source },
172 || {
173 // Make sure no winapi calls as a result of drop happen inside this closure, because
174 // otherwise that might change the return value of the GetLastError.
175 let handle = LoadLibraryExW(wide_filename.as_ptr(), 0, flags);
176 if handle == 0 {
177 None
178 } else {
179 Some(Library(handle))
180 }
181 },
182 )
183 .map_err(|e| e.unwrap_or(crate::Error::LoadLibraryExWUnknown));
184 drop(wide_filename); // Drop wide_filename here to ensure it doesn’t get moved and dropped
185 // inside the closure by mistake. See comment inside the closure.
186 ret
187 }
188
189 /// Attempts to pin the module represented by the current `Library` into memory.
190 ///
191 /// Calls `GetModuleHandleExW` with the flag `GET_MODULE_HANDLE_EX_FLAG_PIN` to pin the module.
192 /// See the [MSDN documentation][msdn] for more information.
193 ///
194 /// [msdn]: https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandleexw
195 ///
196 /// If successful, the module will remain in memory regardless of the refcount for this `Library`
197 pub fn pin(&self) -> Result<(), crate::Error> {
198 const GET_MODULE_HANDLE_EX_FLAG_PIN: u32 = 0x1;
199 const GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS: u32 = 0x4;
200 unsafe {
201 let mut handle: HMODULE = 0;
202 with_get_last_error(
203 |source| crate::Error::GetModuleHandleExW { source },
204 || {
205 // Make sure no winapi calls as a result of drop happen inside this closure, because
206 // otherwise that might change the return value of the GetLastError.
207
208 // We use our cached module handle of this `Library` instead of the module name. This works
209 // if we also pass the flag `GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS` because on Windows, module handles
210 // are the loaded base address of the module.
211 let result = GetModuleHandleExW(
212 GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
213 self.0 as *const u16,
214 &mut handle,
215 );
216 if result == 0 {
217 None
218 } else {
219 Some(())
220 }
221 },
222 )
223 .map_err(|e| e.unwrap_or(crate::Error::GetModuleHandleExWUnknown))
224 }
225 }
226
227 /// Get a pointer to a function or static variable by symbol name.
228 ///
229 /// The `symbol` may not contain any null bytes, with the exception of the last byte. A null
230 /// terminated `symbol` may avoid a string allocation in some cases.
231 ///
232 /// Symbol is interpreted as-is; no mangling is done. This means that symbols like `x::y` are
233 /// most likely invalid.
234 ///
235 /// # Safety
236 ///
237 /// Users of this API must specify the correct type of the function or variable loaded.
238 pub unsafe fn get<T>(&self, symbol: &[u8]) -> Result<Symbol<T>, crate::Error> {
239 ensure_compatible_types::<T, FARPROC>()?;
240 let symbol = cstr_cow_from_bytes(symbol)?;
241 with_get_last_error(
242 |source| crate::Error::GetProcAddress { source },
243 || {
244 let symbol = GetProcAddress(self.0, symbol.as_ptr().cast());
245 if symbol.is_none() {
246 None
247 } else {
248 Some(Symbol {
249 pointer: symbol,
250 pd: marker::PhantomData,
251 })
252 }
253 },
254 )
255 .map_err(|e| e.unwrap_or(crate::Error::GetProcAddressUnknown))
256 }
257
258 /// Get a pointer to a function or static variable by ordinal number.
259 ///
260 /// # Safety
261 ///
262 /// Users of this API must specify the correct type of the function or variable loaded.
263 pub unsafe fn get_ordinal<T>(&self, ordinal: u16) -> Result<Symbol<T>, crate::Error> {
264 ensure_compatible_types::<T, FARPROC>()?;
265 with_get_last_error(
266 |source| crate::Error::GetProcAddress { source },
267 || {
268 let ordinal = ordinal as usize as *const _;
269 let symbol = GetProcAddress(self.0, ordinal);
270 if symbol.is_none() {
271 None
272 } else {
273 Some(Symbol {
274 pointer: symbol,
275 pd: marker::PhantomData,
276 })
277 }
278 },
279 )
280 .map_err(|e| e.unwrap_or(crate::Error::GetProcAddressUnknown))
281 }
282
283 /// Convert the `Library` to a raw handle.
284 pub fn into_raw(self) -> HMODULE {
285 let handle = self.0;
286 mem::forget(self);
287 handle
288 }
289
290 /// Convert a raw handle to a `Library`.
291 ///
292 /// # Safety
293 ///
294 /// The handle must be the result of a successful call of `LoadLibraryA`, `LoadLibraryW`,
295 /// `LoadLibraryExW`, or `LoadLibraryExA`, or a handle previously returned by the
296 /// `Library::into_raw` call.
297 pub unsafe fn from_raw(handle: HMODULE) -> Library {
298 Library(handle)
299 }
300
301 /// Unload the library.
302 ///
303 /// You only need to call this if you are interested in handling any errors that may arise when
304 /// library is unloaded. Otherwise this will be done when `Library` is dropped.
305 ///
306 /// The underlying data structures may still get leaked if an error does occur.
307 pub fn close(self) -> Result<(), crate::Error> {
308 let result = with_get_last_error(
309 |source| crate::Error::FreeLibrary { source },
310 || {
311 if unsafe { FreeLibrary(self.0) == 0 } {
312 None
313 } else {
314 Some(())
315 }
316 },
317 )
318 .map_err(|e| e.unwrap_or(crate::Error::FreeLibraryUnknown));
319 // While the library is not free'd yet in case of an error, there is no reason to try
320 // dropping it again, because all that will do is try calling `FreeLibrary` again. only
321 // this time it would ignore the return result, which we already seen failing...
322 std::mem::forget(self);
323 result
324 }
325 }
326
327 impl Drop for Library {
328 fn drop(&mut self) {
329 unsafe {
330 FreeLibrary(self.0);
331 }
332 }
333 }
334
335 impl fmt::Debug for Library {
336 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
337 unsafe {
338 // FIXME: use Maybeuninit::uninit_array when stable
339 let mut buf = mem::MaybeUninit::<[mem::MaybeUninit<u16>; 1024]>::uninit().assume_init();
340 let len = GetModuleFileNameW(self.0, buf[..].as_mut_ptr().cast(), 1024) as usize;
341 if len == 0 {
342 f.write_str(&format!("Library@{:#x}", self.0))
343 } else {
344 let string: OsString = OsString::from_wide(
345 // FIXME: use Maybeuninit::slice_get_ref when stable
346 &*(&buf[..len] as *const [_] as *const [u16]),
347 );
348 f.write_str(&format!("Library@{:#x} from {:?}", self.0, string))
349 }
350 }
351 }
352 }
353
354 /// A symbol from a library.
355 ///
356 /// A major difference compared to the cross-platform `Symbol` is that this does not ensure that the
357 /// `Symbol` does not outlive the `Library` that it comes from.
358 pub struct Symbol<T> {
359 pointer: FARPROC,
360 pd: marker::PhantomData<T>,
361 }
362
363 impl<T> Symbol<T> {
364 /// Convert the loaded `Symbol` into a handle.
365 pub fn into_raw(self) -> FARPROC {
366 self.pointer
367 }
368
369 /// Convert the loaded `Symbol` into a raw pointer.
370 pub fn as_raw_ptr(self) -> *mut raw::c_void {
371 self.pointer
372 .map(|raw| raw as *mut raw::c_void)
373 .unwrap_or(std::ptr::null_mut())
374 }
375 }
376
377 impl<T> Symbol<Option<T>> {
378 /// Lift Option out of the symbol.
379 pub fn lift_option(self) -> Option<Symbol<T>> {
380 if self.pointer.is_none() {
381 None
382 } else {
383 Some(Symbol {
384 pointer: self.pointer,
385 pd: marker::PhantomData,
386 })
387 }
388 }
389 }
390
391 unsafe impl<T: Send> Send for Symbol<T> {}
392 unsafe impl<T: Sync> Sync for Symbol<T> {}
393
394 impl<T> Clone for Symbol<T> {
395 fn clone(&self) -> Symbol<T> {
396 Symbol { ..*self }
397 }
398 }
399
400 impl<T> ::std::ops::Deref for Symbol<T> {
401 type Target = T;
402 fn deref(&self) -> &T {
403 unsafe { &*((&self.pointer) as *const FARPROC as *const T) }
404 }
405 }
406
407 impl<T> fmt::Debug for Symbol<T> {
408 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
409 match self.pointer {
410 None => f.write_str("Symbol@0x0"),
411 Some(ptr) => f.write_str(&format!("Symbol@{:p}", ptr as *const ())),
412 }
413 }
414 }
415
416 struct ErrorModeGuard(DWORD);
417
418 impl ErrorModeGuard {
419 #[allow(clippy::if_same_then_else)]
420 fn new() -> Option<ErrorModeGuard> {
421 unsafe {
422 let mut previous_mode = 0;
423 if SetThreadErrorMode(SEM_FAILCRITICALERRORS, &mut previous_mode) == 0 {
424 // How in the world is it possible for what is essentially a simple variable swap
425 // to fail? For now we just ignore the error -- the worst that can happen here is
426 // the previous mode staying on and user seeing a dialog error on older Windows
427 // machines.
428 None
429 } else if previous_mode == SEM_FAILCRITICALERRORS {
430 None
431 } else {
432 Some(ErrorModeGuard(previous_mode))
433 }
434 }
435 }
436 }
437
438 impl Drop for ErrorModeGuard {
439 fn drop(&mut self) {
440 unsafe {
441 SetThreadErrorMode(self.0, ptr::null_mut());
442 }
443 }
444 }
445
446 fn with_get_last_error<T, F>(
447 wrap: fn(crate::error::WindowsError) -> crate::Error,
448 closure: F,
449 ) -> Result<T, Option<crate::Error>>
450 where
451 F: FnOnce() -> Option<T>,
452 {
453 closure().ok_or_else(|| {
454 let error = unsafe { GetLastError() };
455 if error == 0 {
456 None
457 } else {
458 Some(wrap(crate::error::WindowsError(
459 io::Error::from_raw_os_error(error as i32),
460 )))
461 }
462 })
463 }
464
465 #[allow(clippy::upper_case_acronyms)]
466 type BOOL = i32;
467 #[allow(clippy::upper_case_acronyms)]
468 type DWORD = u32;
469 #[allow(clippy::upper_case_acronyms)]
470 type HANDLE = isize;
471 #[allow(clippy::upper_case_acronyms)]
472 type HMODULE = isize;
473 #[allow(clippy::upper_case_acronyms)]
474 type FARPROC = Option<unsafe extern "system" fn() -> isize>;
475 #[allow(non_camel_case_types)]
476 type LOAD_LIBRARY_FLAGS = DWORD;
477
478 const SEM_FAILCRITICALERRORS: DWORD = 1;
479
480 /// Do not check AppLocker rules or apply Software Restriction Policies for the DLL.
481 ///
482 /// This action applies only to the DLL being loaded and not to its dependencies. This value is
483 /// recommended for use in setup programs that must run extracted DLLs during installation.
484 ///
485 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
486 pub const LOAD_IGNORE_CODE_AUTHZ_LEVEL: LOAD_LIBRARY_FLAGS = 0x00000010;
487
488 /// Map the file into the calling process’ virtual address space as if it were a data file.
489 ///
490 /// Nothing is done to execute or prepare to execute the mapped file. Therefore, you cannot call
491 /// functions like [`Library::get`] with this DLL. Using this value causes writes to read-only
492 /// memory to raise an access violation. Use this flag when you want to load a DLL only to extract
493 /// messages or resources from it.
494 ///
495 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
496 pub const LOAD_LIBRARY_AS_DATAFILE: LOAD_LIBRARY_FLAGS = 0x00000002;
497
498 /// Map the file into the calling process’ virtual address space as if it were a data file.
499 ///
500 /// Similar to [`LOAD_LIBRARY_AS_DATAFILE`], except that the DLL file is opened with exclusive
501 /// write access for the calling process. Other processes cannot open the DLL file for write access
502 /// while it is in use. However, the DLL can still be opened by other processes.
503 ///
504 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
505 pub const LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE: LOAD_LIBRARY_FLAGS = 0x00000040;
506
507 /// Map the file into the process’ virtual address space as an image file.
508 ///
509 /// The loader does not load the static imports or perform the other usual initialisation steps.
510 /// Use this flag when you want to load a DLL only to extract messages or resources from it.
511 ///
512 /// Unless the application depends on the file having the in-memory layout of an image, this value
513 /// should be used with either [`LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE`] or
514 /// [`LOAD_LIBRARY_AS_DATAFILE`].
515 ///
516 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
517 pub const LOAD_LIBRARY_AS_IMAGE_RESOURCE: LOAD_LIBRARY_FLAGS = 0x00000020;
518
519 /// Search the application's installation directory for the DLL and its dependencies.
520 ///
521 /// Directories in the standard search path are not searched. This value cannot be combined with
522 /// [`LOAD_WITH_ALTERED_SEARCH_PATH`].
523 ///
524 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
525 pub const LOAD_LIBRARY_SEARCH_APPLICATION_DIR: LOAD_LIBRARY_FLAGS = 0x00000200;
526
527 /// Search default directories when looking for the DLL and its dependencies.
528 ///
529 /// This value is a combination of [`LOAD_LIBRARY_SEARCH_APPLICATION_DIR`],
530 /// [`LOAD_LIBRARY_SEARCH_SYSTEM32`], and [`LOAD_LIBRARY_SEARCH_USER_DIRS`]. Directories in the
531 /// standard search path are not searched. This value cannot be combined with
532 /// [`LOAD_WITH_ALTERED_SEARCH_PATH`].
533 ///
534 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
535 pub const LOAD_LIBRARY_SEARCH_DEFAULT_DIRS: LOAD_LIBRARY_FLAGS = 0x00001000;
536
537 /// Directory that contains the DLL is temporarily added to the beginning of the list of
538 /// directories that are searched for the DLL’s dependencies.
539 ///
540 /// Directories in the standard search path are not searched.
541 ///
542 /// The `filename` parameter must specify a fully qualified path. This value cannot be combined
543 /// with [`LOAD_WITH_ALTERED_SEARCH_PATH`].
544 ///
545 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
546 pub const LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR: LOAD_LIBRARY_FLAGS = 0x00000100;
547
548 /// Search `%windows%\system32` for the DLL and its dependencies.
549 ///
550 /// Directories in the standard search path are not searched. This value cannot be combined with
551 /// [`LOAD_WITH_ALTERED_SEARCH_PATH`].
552 ///
553 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
554 pub const LOAD_LIBRARY_SEARCH_SYSTEM32: LOAD_LIBRARY_FLAGS = 0x00000800;
555
556 /// Directories added using the `AddDllDirectory` or the `SetDllDirectory` function are searched
557 /// for the DLL and its dependencies.
558 ///
559 /// If more than one directory has been added, the order in which the directories are searched is
560 /// unspecified. Directories in the standard search path are not searched. This value cannot be
561 /// combined with [`LOAD_WITH_ALTERED_SEARCH_PATH`].
562 ///
563 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
564 pub const LOAD_LIBRARY_SEARCH_USER_DIRS: LOAD_LIBRARY_FLAGS = 0x00000400;
565
566 /// If `filename` specifies an absolute path, the system uses the alternate file search strategy
567 /// discussed in the [Remarks section] to find associated executable modules that the specified
568 /// module causes to be loaded.
569 ///
570 /// If this value is used and `filename` specifies a relative path, the behaviour is undefined.
571 ///
572 /// If this value is not used, or if `filename` does not specify a path, the system uses the
573 /// standard search strategy discussed in the [Remarks section] to find associated executable
574 /// modules that the specified module causes to be loaded.
575 ///
576 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
577 ///
578 /// [Remarks]: https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#remarks
579 pub const LOAD_WITH_ALTERED_SEARCH_PATH: LOAD_LIBRARY_FLAGS = 0x00000008;
580
581 /// Specifies that the digital signature of the binary image must be checked at load time.
582 ///
583 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
584 pub const LOAD_LIBRARY_REQUIRE_SIGNED_TARGET: LOAD_LIBRARY_FLAGS = 0x00000080;
585
586 /// Allow loading a DLL for execution from the current directory only if it is under a directory in
587 /// the Safe load list.
588 ///
589 /// See [flag documentation on MSDN](https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw#parameters).
590 pub const LOAD_LIBRARY_SAFE_CURRENT_DIRS: LOAD_LIBRARY_FLAGS = 0x00002000;