Skip to content

Commit ad97196

Browse files
authored
Use heuristic to determine handle types (#3793)
1 parent 6bb1683 commit ad97196

File tree

10 files changed

+225
-224
lines changed

10 files changed

+225
-224
lines changed

crates/libs/bindgen/src/types/cpp_struct.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,19 @@ impl CppStruct {
4242
self.type_name().write(config, &[])
4343
}
4444

45+
// A "handle" type is any struct with a single field called "Value" of some primitive type.
4546
pub fn is_handle(&self) -> bool {
46-
self.def.has_attribute("NativeTypedefAttribute")
47+
let mut fields = self.def.fields();
48+
49+
let Some(field) = fields.next() else {
50+
return false;
51+
};
52+
53+
if field.name() != "Value" || !field.ty(Some(self)).is_primitive() {
54+
return false;
55+
}
56+
57+
fields.next().is_none()
4758
}
4859

4960
pub fn write_cfg(&self, config: &Config) -> TokenStream {

crates/libs/sys/src/Windows/Win32/Graphics/Printing/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,16 +3550,7 @@ pub const PRINTER_EXECUTE: PRINTER_ACCESS_RIGHTS = 131080u32;
35503550
pub const PRINTER_EXTENSION_DETAILEDREASON_PRINTER_STATUS: windows_sys::core::GUID = windows_sys::core::GUID::from_u128(0x5d5a1704_dfd1_4181_8eee_815c86edad31);
35513551
pub const PRINTER_EXTENSION_REASON_DRIVER_EVENT: windows_sys::core::GUID = windows_sys::core::GUID::from_u128(0x23bb1328_63de_4293_915b_a6a23d929acb);
35523552
pub const PRINTER_EXTENSION_REASON_PRINT_PREFERENCES: windows_sys::core::GUID = windows_sys::core::GUID::from_u128(0xec8f261f_267c_469f_b5d6_3933023c29cc);
3553-
#[repr(C)]
3554-
#[derive(Clone, Copy)]
3555-
pub struct PRINTER_HANDLE {
3556-
pub Value: *mut core::ffi::c_void,
3557-
}
3558-
impl Default for PRINTER_HANDLE {
3559-
fn default() -> Self {
3560-
unsafe { core::mem::zeroed() }
3561-
}
3562-
}
3553+
pub type PRINTER_HANDLE = *mut core::ffi::c_void;
35633554
#[repr(C)]
35643555
#[derive(Clone, Copy)]
35653556
pub struct PRINTER_INFO_1A {

crates/libs/sys/src/Windows/Win32/System/Diagnostics/Etw/mod.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ impl Default for CLASSIC_EVENT_ID {
107107
}
108108
}
109109
pub const CLSID_TraceRelogger: windows_sys::core::GUID = windows_sys::core::GUID::from_u128(0x7b40792d_05ff_44c4_9058_f440c71f17d4);
110-
#[repr(C)]
111-
#[derive(Clone, Copy, Default)]
112-
pub struct CONTROLTRACE_HANDLE {
113-
pub Value: u64,
114-
}
110+
pub type CONTROLTRACE_HANDLE = u64;
115111
pub const CTraceRelogger: windows_sys::core::GUID = windows_sys::core::GUID::from_u128(0x7b40792d_05ff_44c4_9058_f440c71f17d4);
116112
pub type DECODING_SOURCE = i32;
117113
pub const DIAG_LOGGER_NAMEA: windows_sys::core::PCSTR = windows_sys::core::s!("DiagLog");
@@ -1487,11 +1483,7 @@ pub type PEVENT_RECORD_CALLBACK = Option<unsafe extern "system" fn(eventrecord:
14871483
pub type PEVENT_TRACE_BUFFER_CALLBACKA = Option<unsafe extern "system" fn(logfile: *mut EVENT_TRACE_LOGFILEA) -> u32>;
14881484
#[cfg(feature = "Win32_System_Time")]
14891485
pub type PEVENT_TRACE_BUFFER_CALLBACKW = Option<unsafe extern "system" fn(logfile: *mut EVENT_TRACE_LOGFILEW) -> u32>;
1490-
#[repr(C)]
1491-
#[derive(Clone, Copy, Default)]
1492-
pub struct PROCESSTRACE_HANDLE {
1493-
pub Value: u64,
1494-
}
1486+
pub type PROCESSTRACE_HANDLE = u64;
14951487
pub const PROCESS_TRACE_MODE_EVENT_RECORD: u32 = 268435456u32;
14961488
pub const PROCESS_TRACE_MODE_RAW_TIMESTAMP: u32 = 4096u32;
14971489
pub const PROCESS_TRACE_MODE_REAL_TIME: u32 = 256u32;
@@ -1589,11 +1581,7 @@ pub const PropertyParamLength: PROPERTY_FLAGS = 2i32;
15891581
pub const PropertyStruct: PROPERTY_FLAGS = 1i32;
15901582
pub const PropertyWBEMXmlFragment: PROPERTY_FLAGS = 8i32;
15911583
pub type REGHANDLE = i64;
1592-
#[repr(C)]
1593-
#[derive(Clone, Copy, Default)]
1594-
pub struct RELOGSTREAM_HANDLE {
1595-
pub Value: u64,
1596-
}
1584+
pub type RELOGSTREAM_HANDLE = u64;
15971585
pub const RegistryGuid: windows_sys::core::GUID = windows_sys::core::GUID::from_u128(0xae53722e_c863_11d2_8659_00c04fa321a1);
15981586
pub const SYSTEM_ALPC_KW_GENERAL: u64 = 1u64;
15991587
pub const SYSTEM_CONFIG_KW_GRAPHICS: u64 = 2u64;

crates/libs/sys/src/Windows/Win32/System/Memory/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,7 @@ pub struct MEMORY_BASIC_INFORMATION64 {
238238
pub Type: PAGE_TYPE,
239239
pub __alignment2: u32,
240240
}
241-
#[repr(C)]
242-
#[derive(Clone, Copy)]
243-
pub struct MEMORY_MAPPED_VIEW_ADDRESS {
244-
pub Value: *mut core::ffi::c_void,
245-
}
246-
impl Default for MEMORY_MAPPED_VIEW_ADDRESS {
247-
fn default() -> Self {
248-
unsafe { core::mem::zeroed() }
249-
}
250-
}
241+
pub type MEMORY_MAPPED_VIEW_ADDRESS = *mut core::ffi::c_void;
251242
#[repr(C)]
252243
#[derive(Clone, Copy, Default)]
253244
pub struct MEMORY_PARTITION_DEDICATED_MEMORY_ATTRIBUTE {

crates/libs/sys/src/Windows/Win32/System/Threading/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,7 @@ pub const MUTEX_ALL_ACCESS: SYNCHRONIZATION_ACCESS_RIGHTS = 2031617u32;
544544
pub const MUTEX_MODIFY_STATE: SYNCHRONIZATION_ACCESS_RIGHTS = 1u32;
545545
pub const MaxProcessMitigationPolicy: PROCESS_MITIGATION_POLICY = 20i32;
546546
pub const NORMAL_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 32u32;
547-
#[repr(C)]
548-
#[derive(Clone, Copy, Default)]
549-
pub struct OVERRIDE_PREFETCH_PARAMETER {
550-
pub Value: u32,
551-
}
547+
pub type OVERRIDE_PREFETCH_PARAMETER = u32;
552548
#[repr(C)]
553549
#[cfg(feature = "Win32_System_Kernel")]
554550
#[derive(Clone, Copy)]

crates/libs/windows/src/Windows/Win32/Graphics/Printing/mod.rs

Lines changed: 135 additions & 121 deletions
Large diffs are not rendered by default.

crates/libs/windows/src/Windows/Win32/System/Diagnostics/Etw/mod.rs

Lines changed: 37 additions & 33 deletions
Large diffs are not rendered by default.

crates/libs/windows/src/Windows/Win32/System/Memory/mod.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -326,39 +326,46 @@ pub unsafe fn MapUserPhysicalPagesScatter(virtualaddresses: *const *const core::
326326
unsafe { MapUserPhysicalPagesScatter(virtualaddresses, numberofpages, pagearray.unwrap_or(core::mem::zeroed()) as _).ok() }
327327
}
328328
#[inline]
329-
pub unsafe fn MapViewOfFile(hfilemappingobject: super::super::Foundation::HANDLE, dwdesiredaccess: FILE_MAP, dwfileoffsethigh: u32, dwfileoffsetlow: u32, dwnumberofbytestomap: usize) -> MEMORY_MAPPED_VIEW_ADDRESS {
329+
pub unsafe fn MapViewOfFile(hfilemappingobject: super::super::Foundation::HANDLE, dwdesiredaccess: FILE_MAP, dwfileoffsethigh: u32, dwfileoffsetlow: u32, dwnumberofbytestomap: usize) -> windows_core::Result<MEMORY_MAPPED_VIEW_ADDRESS> {
330330
windows_core::link!("kernel32.dll" "system" fn MapViewOfFile(hfilemappingobject : super::super::Foundation:: HANDLE, dwdesiredaccess : FILE_MAP, dwfileoffsethigh : u32, dwfileoffsetlow : u32, dwnumberofbytestomap : usize) -> MEMORY_MAPPED_VIEW_ADDRESS);
331-
unsafe { MapViewOfFile(hfilemappingobject, dwdesiredaccess, dwfileoffsethigh, dwfileoffsetlow, dwnumberofbytestomap) }
331+
let result__ = unsafe { MapViewOfFile(hfilemappingobject, dwdesiredaccess, dwfileoffsethigh, dwfileoffsetlow, dwnumberofbytestomap) };
332+
(!result__.is_invalid()).then_some(result__).ok_or_else(windows_core::Error::from_thread)
332333
}
333334
#[inline]
334-
pub unsafe fn MapViewOfFile3(filemapping: super::super::Foundation::HANDLE, process: Option<super::super::Foundation::HANDLE>, baseaddress: Option<*const core::ffi::c_void>, offset: u64, viewsize: usize, allocationtype: VIRTUAL_ALLOCATION_TYPE, pageprotection: u32, extendedparameters: Option<&mut [MEM_EXTENDED_PARAMETER]>) -> MEMORY_MAPPED_VIEW_ADDRESS {
335+
pub unsafe fn MapViewOfFile3(filemapping: super::super::Foundation::HANDLE, process: Option<super::super::Foundation::HANDLE>, baseaddress: Option<*const core::ffi::c_void>, offset: u64, viewsize: usize, allocationtype: VIRTUAL_ALLOCATION_TYPE, pageprotection: u32, extendedparameters: Option<&mut [MEM_EXTENDED_PARAMETER]>) -> windows_core::Result<MEMORY_MAPPED_VIEW_ADDRESS> {
335336
windows_core::link!("api-ms-win-core-memory-l1-1-6.dll" "system" fn MapViewOfFile3(filemapping : super::super::Foundation:: HANDLE, process : super::super::Foundation:: HANDLE, baseaddress : *const core::ffi::c_void, offset : u64, viewsize : usize, allocationtype : VIRTUAL_ALLOCATION_TYPE, pageprotection : u32, extendedparameters : *mut MEM_EXTENDED_PARAMETER, parametercount : u32) -> MEMORY_MAPPED_VIEW_ADDRESS);
336-
unsafe { MapViewOfFile3(filemapping, process.unwrap_or(core::mem::zeroed()) as _, baseaddress.unwrap_or(core::mem::zeroed()) as _, offset, viewsize, allocationtype, pageprotection, core::mem::transmute(extendedparameters.as_deref().map_or(core::ptr::null(), |slice| slice.as_ptr())), extendedparameters.as_deref().map_or(0, |slice| slice.len().try_into().unwrap())) }
337+
let result__ = unsafe { MapViewOfFile3(filemapping, process.unwrap_or(core::mem::zeroed()) as _, baseaddress.unwrap_or(core::mem::zeroed()) as _, offset, viewsize, allocationtype, pageprotection, core::mem::transmute(extendedparameters.as_deref().map_or(core::ptr::null(), |slice| slice.as_ptr())), extendedparameters.as_deref().map_or(0, |slice| slice.len().try_into().unwrap())) };
338+
(!result__.is_invalid()).then_some(result__).ok_or_else(windows_core::Error::from_thread)
337339
}
338340
#[inline]
339-
pub unsafe fn MapViewOfFile3FromApp(filemapping: super::super::Foundation::HANDLE, process: Option<super::super::Foundation::HANDLE>, baseaddress: Option<*const core::ffi::c_void>, offset: u64, viewsize: usize, allocationtype: VIRTUAL_ALLOCATION_TYPE, pageprotection: u32, extendedparameters: Option<&mut [MEM_EXTENDED_PARAMETER]>) -> MEMORY_MAPPED_VIEW_ADDRESS {
341+
pub unsafe fn MapViewOfFile3FromApp(filemapping: super::super::Foundation::HANDLE, process: Option<super::super::Foundation::HANDLE>, baseaddress: Option<*const core::ffi::c_void>, offset: u64, viewsize: usize, allocationtype: VIRTUAL_ALLOCATION_TYPE, pageprotection: u32, extendedparameters: Option<&mut [MEM_EXTENDED_PARAMETER]>) -> windows_core::Result<MEMORY_MAPPED_VIEW_ADDRESS> {
340342
windows_core::link!("api-ms-win-core-memory-l1-1-6.dll" "system" fn MapViewOfFile3FromApp(filemapping : super::super::Foundation:: HANDLE, process : super::super::Foundation:: HANDLE, baseaddress : *const core::ffi::c_void, offset : u64, viewsize : usize, allocationtype : VIRTUAL_ALLOCATION_TYPE, pageprotection : u32, extendedparameters : *mut MEM_EXTENDED_PARAMETER, parametercount : u32) -> MEMORY_MAPPED_VIEW_ADDRESS);
341-
unsafe { MapViewOfFile3FromApp(filemapping, process.unwrap_or(core::mem::zeroed()) as _, baseaddress.unwrap_or(core::mem::zeroed()) as _, offset, viewsize, allocationtype, pageprotection, core::mem::transmute(extendedparameters.as_deref().map_or(core::ptr::null(), |slice| slice.as_ptr())), extendedparameters.as_deref().map_or(0, |slice| slice.len().try_into().unwrap())) }
343+
let result__ = unsafe { MapViewOfFile3FromApp(filemapping, process.unwrap_or(core::mem::zeroed()) as _, baseaddress.unwrap_or(core::mem::zeroed()) as _, offset, viewsize, allocationtype, pageprotection, core::mem::transmute(extendedparameters.as_deref().map_or(core::ptr::null(), |slice| slice.as_ptr())), extendedparameters.as_deref().map_or(0, |slice| slice.len().try_into().unwrap())) };
344+
(!result__.is_invalid()).then_some(result__).ok_or_else(windows_core::Error::from_thread)
342345
}
343346
#[inline]
344-
pub unsafe fn MapViewOfFileEx(hfilemappingobject: super::super::Foundation::HANDLE, dwdesiredaccess: FILE_MAP, dwfileoffsethigh: u32, dwfileoffsetlow: u32, dwnumberofbytestomap: usize, lpbaseaddress: Option<*const core::ffi::c_void>) -> MEMORY_MAPPED_VIEW_ADDRESS {
347+
pub unsafe fn MapViewOfFileEx(hfilemappingobject: super::super::Foundation::HANDLE, dwdesiredaccess: FILE_MAP, dwfileoffsethigh: u32, dwfileoffsetlow: u32, dwnumberofbytestomap: usize, lpbaseaddress: Option<*const core::ffi::c_void>) -> windows_core::Result<MEMORY_MAPPED_VIEW_ADDRESS> {
345348
windows_core::link!("kernel32.dll" "system" fn MapViewOfFileEx(hfilemappingobject : super::super::Foundation:: HANDLE, dwdesiredaccess : FILE_MAP, dwfileoffsethigh : u32, dwfileoffsetlow : u32, dwnumberofbytestomap : usize, lpbaseaddress : *const core::ffi::c_void) -> MEMORY_MAPPED_VIEW_ADDRESS);
346-
unsafe { MapViewOfFileEx(hfilemappingobject, dwdesiredaccess, dwfileoffsethigh, dwfileoffsetlow, dwnumberofbytestomap, lpbaseaddress.unwrap_or(core::mem::zeroed()) as _) }
349+
let result__ = unsafe { MapViewOfFileEx(hfilemappingobject, dwdesiredaccess, dwfileoffsethigh, dwfileoffsetlow, dwnumberofbytestomap, lpbaseaddress.unwrap_or(core::mem::zeroed()) as _) };
350+
(!result__.is_invalid()).then_some(result__).ok_or_else(windows_core::Error::from_thread)
347351
}
348352
#[inline]
349-
pub unsafe fn MapViewOfFileExNuma(hfilemappingobject: super::super::Foundation::HANDLE, dwdesiredaccess: FILE_MAP, dwfileoffsethigh: u32, dwfileoffsetlow: u32, dwnumberofbytestomap: usize, lpbaseaddress: Option<*const core::ffi::c_void>, nndpreferred: u32) -> MEMORY_MAPPED_VIEW_ADDRESS {
353+
pub unsafe fn MapViewOfFileExNuma(hfilemappingobject: super::super::Foundation::HANDLE, dwdesiredaccess: FILE_MAP, dwfileoffsethigh: u32, dwfileoffsetlow: u32, dwnumberofbytestomap: usize, lpbaseaddress: Option<*const core::ffi::c_void>, nndpreferred: u32) -> windows_core::Result<MEMORY_MAPPED_VIEW_ADDRESS> {
350354
windows_core::link!("kernel32.dll" "system" fn MapViewOfFileExNuma(hfilemappingobject : super::super::Foundation:: HANDLE, dwdesiredaccess : FILE_MAP, dwfileoffsethigh : u32, dwfileoffsetlow : u32, dwnumberofbytestomap : usize, lpbaseaddress : *const core::ffi::c_void, nndpreferred : u32) -> MEMORY_MAPPED_VIEW_ADDRESS);
351-
unsafe { MapViewOfFileExNuma(hfilemappingobject, dwdesiredaccess, dwfileoffsethigh, dwfileoffsetlow, dwnumberofbytestomap, lpbaseaddress.unwrap_or(core::mem::zeroed()) as _, nndpreferred) }
355+
let result__ = unsafe { MapViewOfFileExNuma(hfilemappingobject, dwdesiredaccess, dwfileoffsethigh, dwfileoffsetlow, dwnumberofbytestomap, lpbaseaddress.unwrap_or(core::mem::zeroed()) as _, nndpreferred) };
356+
(!result__.is_invalid()).then_some(result__).ok_or_else(windows_core::Error::from_thread)
352357
}
353358
#[inline]
354-
pub unsafe fn MapViewOfFileFromApp(hfilemappingobject: super::super::Foundation::HANDLE, desiredaccess: FILE_MAP, fileoffset: u64, numberofbytestomap: usize) -> MEMORY_MAPPED_VIEW_ADDRESS {
359+
pub unsafe fn MapViewOfFileFromApp(hfilemappingobject: super::super::Foundation::HANDLE, desiredaccess: FILE_MAP, fileoffset: u64, numberofbytestomap: usize) -> windows_core::Result<MEMORY_MAPPED_VIEW_ADDRESS> {
355360
windows_core::link!("kernel32.dll" "system" fn MapViewOfFileFromApp(hfilemappingobject : super::super::Foundation:: HANDLE, desiredaccess : FILE_MAP, fileoffset : u64, numberofbytestomap : usize) -> MEMORY_MAPPED_VIEW_ADDRESS);
356-
unsafe { MapViewOfFileFromApp(hfilemappingobject, desiredaccess, fileoffset, numberofbytestomap) }
361+
let result__ = unsafe { MapViewOfFileFromApp(hfilemappingobject, desiredaccess, fileoffset, numberofbytestomap) };
362+
(!result__.is_invalid()).then_some(result__).ok_or_else(windows_core::Error::from_thread)
357363
}
358364
#[inline]
359-
pub unsafe fn MapViewOfFileNuma2(filemappinghandle: super::super::Foundation::HANDLE, processhandle: super::super::Foundation::HANDLE, offset: u64, baseaddress: Option<*const core::ffi::c_void>, viewsize: usize, allocationtype: u32, pageprotection: u32, preferrednode: u32) -> MEMORY_MAPPED_VIEW_ADDRESS {
365+
pub unsafe fn MapViewOfFileNuma2(filemappinghandle: super::super::Foundation::HANDLE, processhandle: super::super::Foundation::HANDLE, offset: u64, baseaddress: Option<*const core::ffi::c_void>, viewsize: usize, allocationtype: u32, pageprotection: u32, preferrednode: u32) -> windows_core::Result<MEMORY_MAPPED_VIEW_ADDRESS> {
360366
windows_core::link!("api-ms-win-core-memory-l1-1-5.dll" "system" fn MapViewOfFileNuma2(filemappinghandle : super::super::Foundation:: HANDLE, processhandle : super::super::Foundation:: HANDLE, offset : u64, baseaddress : *const core::ffi::c_void, viewsize : usize, allocationtype : u32, pageprotection : u32, preferrednode : u32) -> MEMORY_MAPPED_VIEW_ADDRESS);
361-
unsafe { MapViewOfFileNuma2(filemappinghandle, processhandle, offset, baseaddress.unwrap_or(core::mem::zeroed()) as _, viewsize, allocationtype, pageprotection, preferrednode) }
367+
let result__ = unsafe { MapViewOfFileNuma2(filemappinghandle, processhandle, offset, baseaddress.unwrap_or(core::mem::zeroed()) as _, viewsize, allocationtype, pageprotection, preferrednode) };
368+
(!result__.is_invalid()).then_some(result__).ok_or_else(windows_core::Error::from_thread)
362369
}
363370
#[inline]
364371
pub unsafe fn OfferVirtualMemory(virtualaddress: &mut [u8], priority: OFFER_PRIORITY) -> u32 {
@@ -480,17 +487,17 @@ pub unsafe fn SetSystemFileCacheSize(minimumfilecachesize: usize, maximumfilecac
480487
#[inline]
481488
pub unsafe fn UnmapViewOfFile(lpbaseaddress: MEMORY_MAPPED_VIEW_ADDRESS) -> windows_core::Result<()> {
482489
windows_core::link!("kernel32.dll" "system" fn UnmapViewOfFile(lpbaseaddress : MEMORY_MAPPED_VIEW_ADDRESS) -> windows_core::BOOL);
483-
unsafe { UnmapViewOfFile(core::mem::transmute(lpbaseaddress)).ok() }
490+
unsafe { UnmapViewOfFile(lpbaseaddress).ok() }
484491
}
485492
#[inline]
486493
pub unsafe fn UnmapViewOfFile2(process: super::super::Foundation::HANDLE, baseaddress: MEMORY_MAPPED_VIEW_ADDRESS, unmapflags: UNMAP_VIEW_OF_FILE_FLAGS) -> windows_core::Result<()> {
487494
windows_core::link!("api-ms-win-core-memory-l1-1-5.dll" "system" fn UnmapViewOfFile2(process : super::super::Foundation:: HANDLE, baseaddress : MEMORY_MAPPED_VIEW_ADDRESS, unmapflags : UNMAP_VIEW_OF_FILE_FLAGS) -> windows_core::BOOL);
488-
unsafe { UnmapViewOfFile2(process, core::mem::transmute(baseaddress), unmapflags).ok() }
495+
unsafe { UnmapViewOfFile2(process, baseaddress, unmapflags).ok() }
489496
}
490497
#[inline]
491498
pub unsafe fn UnmapViewOfFileEx(baseaddress: MEMORY_MAPPED_VIEW_ADDRESS, unmapflags: UNMAP_VIEW_OF_FILE_FLAGS) -> windows_core::Result<()> {
492499
windows_core::link!("kernel32.dll" "system" fn UnmapViewOfFileEx(baseaddress : MEMORY_MAPPED_VIEW_ADDRESS, unmapflags : UNMAP_VIEW_OF_FILE_FLAGS) -> windows_core::BOOL);
493-
unsafe { UnmapViewOfFileEx(core::mem::transmute(baseaddress), unmapflags).ok() }
500+
unsafe { UnmapViewOfFileEx(baseaddress, unmapflags).ok() }
494501
}
495502
#[inline]
496503
pub unsafe fn UnregisterBadMemoryNotification(registrationhandle: *const core::ffi::c_void) -> windows_core::Result<()> {
@@ -849,10 +856,13 @@ pub struct MEMORY_BASIC_INFORMATION64 {
849856
pub Type: PAGE_TYPE,
850857
pub __alignment2: u32,
851858
}
852-
#[repr(C)]
853-
#[derive(Clone, Copy, Debug, PartialEq)]
854-
pub struct MEMORY_MAPPED_VIEW_ADDRESS {
855-
pub Value: *mut core::ffi::c_void,
859+
#[repr(transparent)]
860+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
861+
pub struct MEMORY_MAPPED_VIEW_ADDRESS(pub *mut core::ffi::c_void);
862+
impl MEMORY_MAPPED_VIEW_ADDRESS {
863+
pub fn is_invalid(&self) -> bool {
864+
self.0.is_null()
865+
}
856866
}
857867
impl Default for MEMORY_MAPPED_VIEW_ADDRESS {
858868
fn default() -> Self {

crates/libs/windows/src/Windows/Win32/System/Threading/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,11 +2459,9 @@ pub const MUTEX_ALL_ACCESS: SYNCHRONIZATION_ACCESS_RIGHTS = SYNCHRONIZATION_ACCE
24592459
pub const MUTEX_MODIFY_STATE: SYNCHRONIZATION_ACCESS_RIGHTS = SYNCHRONIZATION_ACCESS_RIGHTS(1u32);
24602460
pub const MaxProcessMitigationPolicy: PROCESS_MITIGATION_POLICY = PROCESS_MITIGATION_POLICY(20i32);
24612461
pub const NORMAL_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = PROCESS_CREATION_FLAGS(32u32);
2462-
#[repr(C)]
2463-
#[derive(Clone, Copy, Debug, Default, PartialEq)]
2464-
pub struct OVERRIDE_PREFETCH_PARAMETER {
2465-
pub Value: u32,
2466-
}
2462+
#[repr(transparent)]
2463+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
2464+
pub struct OVERRIDE_PREFETCH_PARAMETER(pub u32);
24672465
#[repr(C)]
24682466
#[cfg(feature = "Win32_System_Kernel")]
24692467
#[derive(Clone, Copy, Debug)]

crates/tests/misc/not_dll/tests/sys.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use windows_sys::Win32::Graphics::Printing::*;
55
#[test]
66
fn test() {
77
unsafe {
8-
_ = GetSpoolFileHandle(PRINTER_HANDLE {
9-
Value: std::ptr::null_mut(),
10-
});
8+
_ = GetSpoolFileHandle(std::ptr::null_mut());
119
}
1210
}

0 commit comments

Comments
 (0)