Skip to content

Commit a1a1c6a

Browse files
committed
Remove DWORD
1 parent 7d18991 commit a1a1c6a

File tree

15 files changed

+90
-105
lines changed

15 files changed

+90
-105
lines changed

std/src/process/tests.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -385,29 +385,25 @@ fn test_interior_nul_in_env_value_is_error() {
385385
#[cfg(windows)]
386386
fn test_creation_flags() {
387387
use crate::os::windows::process::CommandExt;
388-
use crate::sys::c::{BOOL, DWORD, INFINITE};
388+
use crate::sys::c::{BOOL, INFINITE};
389389
#[repr(C)]
390390
struct DEBUG_EVENT {
391-
pub event_code: DWORD,
392-
pub process_id: DWORD,
393-
pub thread_id: DWORD,
391+
pub event_code: u32,
392+
pub process_id: u32,
393+
pub thread_id: u32,
394394
// This is a union in the real struct, but we don't
395395
// need this data for the purposes of this test.
396396
pub _junk: [u8; 164],
397397
}
398398

399399
extern "system" {
400-
fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: DWORD) -> BOOL;
401-
fn ContinueDebugEvent(
402-
dwProcessId: DWORD,
403-
dwThreadId: DWORD,
404-
dwContinueStatus: DWORD,
405-
) -> BOOL;
400+
fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: u32) -> BOOL;
401+
fn ContinueDebugEvent(dwProcessId: u32, dwThreadId: u32, dwContinueStatus: u32) -> BOOL;
406402
}
407403

408-
const DEBUG_PROCESS: DWORD = 1;
409-
const EXIT_PROCESS_DEBUG_EVENT: DWORD = 5;
410-
const DBG_EXCEPTION_NOT_HANDLED: DWORD = 0x80010001;
404+
const DEBUG_PROCESS: u32 = 1;
405+
const EXIT_PROCESS_DEBUG_EVENT: u32 = 5;
406+
const DBG_EXCEPTION_NOT_HANDLED: u32 = 0x80010001;
411407

412408
let mut child =
413409
Command::new("cmd").creation_flags(DEBUG_PROCESS).stdin(Stdio::piped()).spawn().unwrap();

std/src/sys/pal/windows/alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod tests;
1515
// See https://docs.microsoft.com/windows/win32/api/heapapi/
1616

1717
// Flag to indicate that the memory returned by `HeapAlloc` should be zeroed.
18-
const HEAP_ZERO_MEMORY: c::DWORD = 0x00000008;
18+
const HEAP_ZERO_MEMORY: u32 = 0x00000008;
1919

2020
// Get a handle to the default heap of the current process, or null if the operation fails.
2121
//
@@ -113,7 +113,7 @@ fn init_or_get_process_heap() -> c::HANDLE {
113113
#[cold]
114114
extern "C" fn process_heap_init_and_alloc(
115115
_heap: MaybeUninit<c::HANDLE>, // We pass this argument to match the ABI of `HeapAlloc`
116-
flags: c::DWORD,
116+
flags: u32,
117117
dwBytes: usize,
118118
) -> *mut c_void {
119119
let heap = init_or_get_process_heap();
@@ -127,7 +127,7 @@ extern "C" fn process_heap_init_and_alloc(
127127
#[inline(never)]
128128
fn process_heap_alloc(
129129
_heap: MaybeUninit<c::HANDLE>, // We pass this argument to match the ABI of `HeapAlloc`,
130-
flags: c::DWORD,
130+
flags: u32,
131131
dwBytes: usize,
132132
) -> *mut c_void {
133133
let heap = HEAP.load(Ordering::Relaxed);

std/src/sys/pal/windows/c.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub(super) mod windows_targets;
1717
mod windows_sys;
1818
pub use windows_sys::*;
1919

20-
pub type DWORD = c_ulong;
2120
pub type WCHAR = u16;
2221

2322
pub type socklen_t = c_int;
@@ -316,13 +315,13 @@ compat_fn_with_fallback! {
316315
// >= Win10 1607
317316
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
318317
pub fn SetThreadDescription(hthread: HANDLE, lpthreaddescription: PCWSTR) -> HRESULT {
319-
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); E_NOTIMPL
318+
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL
320319
}
321320

322321
// >= Win10 1607
323322
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreaddescription
324323
pub fn GetThreadDescription(hthread: HANDLE, lpthreaddescription: *mut PWSTR) -> HRESULT {
325-
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); E_NOTIMPL
324+
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL
326325
}
327326

328327
// >= Win8 / Server 2012
@@ -383,9 +382,9 @@ compat_fn_with_fallback! {
383382
#[cfg(target_vendor = "win7")]
384383
pub fn NtCreateKeyedEvent(
385384
KeyedEventHandle: *mut HANDLE,
386-
DesiredAccess: DWORD,
385+
DesiredAccess: u32,
387386
ObjectAttributes: *mut c_void,
388-
Flags: ULONG
387+
Flags: u32
389388
) -> NTSTATUS {
390389
panic!("keyed events not available")
391390
}
@@ -433,9 +432,9 @@ compat_fn_with_fallback! {
433432
apccontext: *mut c_void,
434433
iostatusblock: &mut IO_STATUS_BLOCK,
435434
buffer: *mut crate::mem::MaybeUninit<u8>,
436-
length: ULONG,
435+
length: u32,
437436
byteoffset: Option<&i64>,
438-
key: Option<&ULONG>
437+
key: Option<&u32>
439438
) -> NTSTATUS {
440439
STATUS_NOT_IMPLEMENTED
441440
}
@@ -447,9 +446,9 @@ compat_fn_with_fallback! {
447446
apccontext: *mut c_void,
448447
iostatusblock: &mut IO_STATUS_BLOCK,
449448
buffer: *const u8,
450-
length: ULONG,
449+
length: u32,
451450
byteoffset: Option<&i64>,
452-
key: Option<&ULONG>
451+
key: Option<&u32>
453452
) -> NTSTATUS {
454453
STATUS_NOT_IMPLEMENTED
455454
}

std/src/sys/pal/windows/fs.rs

+28-29
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ pub struct File {
2828

2929
#[derive(Clone)]
3030
pub struct FileAttr {
31-
attributes: c::DWORD,
31+
attributes: u32,
3232
creation_time: c::FILETIME,
3333
last_access_time: c::FILETIME,
3434
last_write_time: c::FILETIME,
3535
file_size: u64,
36-
reparse_tag: c::DWORD,
36+
reparse_tag: u32,
3737
volume_serial_number: Option<u32>,
3838
number_of_links: Option<u32>,
3939
file_index: Option<u64>,
4040
}
4141

4242
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
4343
pub struct FileType {
44-
attributes: c::DWORD,
45-
reparse_tag: c::DWORD,
44+
attributes: u32,
45+
reparse_tag: u32,
4646
}
4747

4848
pub struct ReadDir {
@@ -75,16 +75,16 @@ pub struct OpenOptions {
7575
create_new: bool,
7676
// system-specific
7777
custom_flags: u32,
78-
access_mode: Option<c::DWORD>,
79-
attributes: c::DWORD,
80-
share_mode: c::DWORD,
81-
security_qos_flags: c::DWORD,
78+
access_mode: Option<u32>,
79+
attributes: u32,
80+
share_mode: u32,
81+
security_qos_flags: u32,
8282
security_attributes: *mut c::SECURITY_ATTRIBUTES,
8383
}
8484

8585
#[derive(Clone, PartialEq, Eq, Debug)]
8686
pub struct FilePermissions {
87-
attrs: c::DWORD,
87+
attrs: u32,
8888
}
8989

9090
#[derive(Copy, Clone, Debug, Default)]
@@ -245,7 +245,7 @@ impl OpenOptions {
245245
self.security_attributes = attrs;
246246
}
247247

248-
fn get_access_mode(&self) -> io::Result<c::DWORD> {
248+
fn get_access_mode(&self) -> io::Result<u32> {
249249
match (self.read, self.write, self.append, self.access_mode) {
250250
(.., Some(mode)) => Ok(mode),
251251
(true, false, false, None) => Ok(c::GENERIC_READ),
@@ -261,7 +261,7 @@ impl OpenOptions {
261261
}
262262
}
263263

264-
fn get_creation_mode(&self) -> io::Result<c::DWORD> {
264+
fn get_creation_mode(&self) -> io::Result<u32> {
265265
match (self.write, self.append) {
266266
(true, false) => {}
267267
(false, false) => {
@@ -287,7 +287,7 @@ impl OpenOptions {
287287
})
288288
}
289289

290-
fn get_flags_and_attributes(&self) -> c::DWORD {
290+
fn get_flags_and_attributes(&self) -> u32 {
291291
self.custom_flags
292292
| self.attributes
293293
| self.security_qos_flags
@@ -397,21 +397,21 @@ impl File {
397397
self.handle.as_raw_handle(),
398398
c::FileBasicInfo,
399399
core::ptr::addr_of_mut!(info) as *mut c_void,
400-
size as c::DWORD,
400+
size as u32,
401401
))?;
402402
let mut attr = FileAttr {
403403
attributes: info.FileAttributes,
404404
creation_time: c::FILETIME {
405-
dwLowDateTime: info.CreationTime as c::DWORD,
406-
dwHighDateTime: (info.CreationTime >> 32) as c::DWORD,
405+
dwLowDateTime: info.CreationTime as u32,
406+
dwHighDateTime: (info.CreationTime >> 32) as u32,
407407
},
408408
last_access_time: c::FILETIME {
409-
dwLowDateTime: info.LastAccessTime as c::DWORD,
410-
dwHighDateTime: (info.LastAccessTime >> 32) as c::DWORD,
409+
dwLowDateTime: info.LastAccessTime as u32,
410+
dwHighDateTime: (info.LastAccessTime >> 32) as u32,
411411
},
412412
last_write_time: c::FILETIME {
413-
dwLowDateTime: info.LastWriteTime as c::DWORD,
414-
dwHighDateTime: (info.LastWriteTime >> 32) as c::DWORD,
413+
dwLowDateTime: info.LastWriteTime as u32,
414+
dwHighDateTime: (info.LastWriteTime >> 32) as u32,
415415
},
416416
file_size: 0,
417417
reparse_tag: 0,
@@ -425,7 +425,7 @@ impl File {
425425
self.handle.as_raw_handle(),
426426
c::FileStandardInfo,
427427
core::ptr::addr_of_mut!(info) as *mut c_void,
428-
size as c::DWORD,
428+
size as u32,
429429
))?;
430430
attr.file_size = info.AllocationSize as u64;
431431
attr.number_of_links = Some(info.NumberOfLinks);
@@ -511,7 +511,7 @@ impl File {
511511
fn reparse_point(
512512
&self,
513513
space: &mut Align8<[MaybeUninit<u8>]>,
514-
) -> io::Result<(c::DWORD, *mut c::REPARSE_DATA_BUFFER)> {
514+
) -> io::Result<(u32, *mut c::REPARSE_DATA_BUFFER)> {
515515
unsafe {
516516
let mut bytes = 0;
517517
cvt({
@@ -524,7 +524,7 @@ impl File {
524524
ptr::null_mut(),
525525
0,
526526
space.0.as_mut_ptr().cast(),
527-
len as c::DWORD,
527+
len as u32,
528528
&mut bytes,
529529
ptr::null_mut(),
530530
)
@@ -609,8 +609,7 @@ impl File {
609609
"Cannot set file timestamp to 0",
610610
));
611611
}
612-
let is_max =
613-
|t: c::FILETIME| t.dwLowDateTime == c::DWORD::MAX && t.dwHighDateTime == c::DWORD::MAX;
612+
let is_max = |t: c::FILETIME| t.dwLowDateTime == u32::MAX && t.dwHighDateTime == u32::MAX;
614613
if times.accessed.map_or(false, is_max)
615614
|| times.modified.map_or(false, is_max)
616615
|| times.created.map_or(false, is_max)
@@ -641,7 +640,7 @@ impl File {
641640
self.handle.as_raw_handle(),
642641
c::FileBasicInfo,
643642
core::ptr::addr_of_mut!(info) as *mut c_void,
644-
size as c::DWORD,
643+
size as u32,
645644
))?;
646645
Ok(info)
647646
}
@@ -1020,7 +1019,7 @@ impl FileTimes {
10201019
}
10211020

10221021
impl FileType {
1023-
fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType {
1022+
fn new(attrs: u32, reparse_tag: u32) -> FileType {
10241023
FileType { attributes: attrs, reparse_tag }
10251024
}
10261025
pub fn is_dir(&self) -> bool {
@@ -1421,12 +1420,12 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
14211420
_TotalBytesTransferred: i64,
14221421
_StreamSize: i64,
14231422
StreamBytesTransferred: i64,
1424-
dwStreamNumber: c::DWORD,
1425-
_dwCallbackReason: c::DWORD,
1423+
dwStreamNumber: u32,
1424+
_dwCallbackReason: u32,
14261425
_hSourceFile: c::HANDLE,
14271426
_hDestinationFile: c::HANDLE,
14281427
lpData: *const c_void,
1429-
) -> c::DWORD {
1428+
) -> u32 {
14301429
if dwStreamNumber == 1 {
14311430
*(lpData as *mut i64) = StreamBytesTransferred;
14321431
}

std/src/sys/pal/windows/handle.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Handle {
141141
buf: &mut [u8],
142142
overlapped: *mut c::OVERLAPPED,
143143
) -> io::Result<Option<usize>> {
144-
let len = cmp::min(buf.len(), <c::DWORD>::MAX as usize) as c::DWORD;
144+
let len = cmp::min(buf.len(), u32::MAX as usize) as u32;
145145
let mut amt = 0;
146146
let res =
147147
cvt(c::ReadFile(self.as_raw_handle(), buf.as_mut_ptr(), len, &mut amt, overlapped));
@@ -209,12 +209,7 @@ impl Handle {
209209
Ok(Self(self.0.try_clone()?))
210210
}
211211

212-
pub fn duplicate(
213-
&self,
214-
access: c::DWORD,
215-
inherit: bool,
216-
options: c::DWORD,
217-
) -> io::Result<Self> {
212+
pub fn duplicate(&self, access: u32, inherit: bool, options: u32) -> io::Result<Self> {
218213
Ok(Self(self.0.as_handle().duplicate(access, inherit, options)?))
219214
}
220215

@@ -233,7 +228,7 @@ impl Handle {
233228
let mut io_status = c::IO_STATUS_BLOCK::PENDING;
234229

235230
// The length is clamped at u32::MAX.
236-
let len = cmp::min(len, c::DWORD::MAX as usize) as c::DWORD;
231+
let len = cmp::min(len, u32::MAX as usize) as u32;
237232
let status = c::NtReadFile(
238233
self.as_handle(),
239234
ptr::null_mut(),
@@ -281,7 +276,7 @@ impl Handle {
281276
let mut io_status = c::IO_STATUS_BLOCK::PENDING;
282277

283278
// The length is clamped at u32::MAX.
284-
let len = cmp::min(buf.len(), c::DWORD::MAX as usize) as c::DWORD;
279+
let len = cmp::min(buf.len(), u32::MAX as usize) as u32;
285280
let status = unsafe {
286281
c::NtWriteFile(
287282
self.as_handle(),

0 commit comments

Comments
 (0)