diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:06:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:06:37 +0000 |
commit | 246f239d9f40f633160f0c18f87a20922d4e77bb (patch) | |
tree | 5a88572663584b3d4d28e5a20e10abab1be40884 /vendor/memmap2/src/windows.rs | |
parent | Releasing progress-linux version 1.64.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-246f239d9f40f633160f0c18f87a20922d4e77bb.tar.xz rustc-246f239d9f40f633160f0c18f87a20922d4e77bb.zip |
Merging debian version 1.65.0+dfsg1-2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vendor/memmap2/src/windows.rs | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/vendor/memmap2/src/windows.rs b/vendor/memmap2/src/windows.rs index b3b8c620a..d580995e6 100644 --- a/vendor/memmap2/src/windows.rs +++ b/vendor/memmap2/src/windows.rs @@ -1,8 +1,10 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] +use std::fs::File; +use std::mem::ManuallyDrop; use std::os::raw::c_void; -use std::os::windows::io::RawHandle; +use std::os::windows::io::{FromRawHandle, RawHandle}; use std::{io, mem, ptr}; type BOOL = i32; @@ -82,22 +84,6 @@ pub struct FILETIME { pub dwHighDateTime: DWORD, } -#[repr(C)] -struct BY_HANDLE_FILE_INFORMATION { - dwFileAttributes: DWORD, - ftCreationTime: FILETIME, - ftLastAccessTime: FILETIME, - ftLastWriteTime: FILETIME, - dwVolumeSerialNumber: DWORD, - nFileSizeHigh: DWORD, - nFileSizeLow: DWORD, - nNumberOfLinks: DWORD, - nFileIndexHigh: DWORD, - nFileIndexLow: DWORD, -} - -type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION; - extern "system" { fn GetCurrentProcess() -> HANDLE; @@ -124,11 +110,6 @@ extern "system" { fn FlushFileBuffers(hFile: HANDLE) -> BOOL; - fn GetFileInformationByHandle( - hFile: HANDLE, - lpFileInformation: LPBY_HANDLE_FILE_INFORMATION, - ) -> BOOL; - fn FlushViewOfFile(lpBaseAddress: LPCVOID, dwNumberOfBytesToFlush: SIZE_T) -> BOOL; fn UnmapViewOfFile(lpBaseAddress: LPCVOID) -> BOOL; @@ -526,16 +507,10 @@ fn allocation_granularity() -> usize { } pub fn file_len(handle: RawHandle) -> io::Result<u64> { - let info = unsafe { - let mut info = mem::MaybeUninit::<BY_HANDLE_FILE_INFORMATION>::uninit(); - - let ok = GetFileInformationByHandle(handle, info.as_mut_ptr()); - if ok == 0 { - return Err(io::Error::last_os_error()); - } - - info.assume_init() - }; - - Ok((info.nFileSizeHigh as u64) << 32 | info.nFileSizeLow as u64) + // SAFETY: We must not close the passed-in fd by dropping the File we create, + // we ensure this by immediately wrapping it in a ManuallyDrop. + unsafe { + let file = ManuallyDrop::new(File::from_raw_handle(handle)); + Ok(file.metadata()?.len()) + } } |