From 94a0819fe3a0d679c3042a77bfe6a2afc505daea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:28 +0200 Subject: Adding upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/memmap2/src/windows.rs | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) (limited to 'vendor/memmap2/src/windows.rs') 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 { - let info = unsafe { - let mut info = mem::MaybeUninit::::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()) + } } -- cgit v1.2.3