Skip to content

Commit

Permalink
Remove DWORD
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Jul 15, 2024
1 parent 7d18991 commit a1a1c6a
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 105 deletions.
22 changes: 9 additions & 13 deletions std/src/process/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,29 +385,25 @@ fn test_interior_nul_in_env_value_is_error() {
#[cfg(windows)]
fn test_creation_flags() {
use crate::os::windows::process::CommandExt;
use crate::sys::c::{BOOL, DWORD, INFINITE};
use crate::sys::c::{BOOL, INFINITE};
#[repr(C)]
struct DEBUG_EVENT {
pub event_code: DWORD,
pub process_id: DWORD,
pub thread_id: DWORD,
pub event_code: u32,
pub process_id: u32,
pub thread_id: u32,
// This is a union in the real struct, but we don't
// need this data for the purposes of this test.
pub _junk: [u8; 164],
}

extern "system" {
fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: DWORD) -> BOOL;
fn ContinueDebugEvent(
dwProcessId: DWORD,
dwThreadId: DWORD,
dwContinueStatus: DWORD,
) -> BOOL;
fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: u32) -> BOOL;
fn ContinueDebugEvent(dwProcessId: u32, dwThreadId: u32, dwContinueStatus: u32) -> BOOL;
}

const DEBUG_PROCESS: DWORD = 1;
const EXIT_PROCESS_DEBUG_EVENT: DWORD = 5;
const DBG_EXCEPTION_NOT_HANDLED: DWORD = 0x80010001;
const DEBUG_PROCESS: u32 = 1;
const EXIT_PROCESS_DEBUG_EVENT: u32 = 5;
const DBG_EXCEPTION_NOT_HANDLED: u32 = 0x80010001;

let mut child =
Command::new("cmd").creation_flags(DEBUG_PROCESS).stdin(Stdio::piped()).spawn().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions std/src/sys/pal/windows/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod tests;
// See https://docs.microsoft.com/windows/win32/api/heapapi/

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

// Get a handle to the default heap of the current process, or null if the operation fails.
//
Expand Down Expand Up @@ -113,7 +113,7 @@ fn init_or_get_process_heap() -> c::HANDLE {
#[cold]
extern "C" fn process_heap_init_and_alloc(
_heap: MaybeUninit<c::HANDLE>, // We pass this argument to match the ABI of `HeapAlloc`
flags: c::DWORD,
flags: u32,
dwBytes: usize,
) -> *mut c_void {
let heap = init_or_get_process_heap();
Expand All @@ -127,7 +127,7 @@ extern "C" fn process_heap_init_and_alloc(
#[inline(never)]
fn process_heap_alloc(
_heap: MaybeUninit<c::HANDLE>, // We pass this argument to match the ABI of `HeapAlloc`,
flags: c::DWORD,
flags: u32,
dwBytes: usize,
) -> *mut c_void {
let heap = HEAP.load(Ordering::Relaxed);
Expand Down
17 changes: 8 additions & 9 deletions std/src/sys/pal/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub(super) mod windows_targets;
mod windows_sys;
pub use windows_sys::*;

pub type DWORD = c_ulong;
pub type WCHAR = u16;

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

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

// >= Win8 / Server 2012
Expand Down Expand Up @@ -383,9 +382,9 @@ compat_fn_with_fallback! {
#[cfg(target_vendor = "win7")]
pub fn NtCreateKeyedEvent(
KeyedEventHandle: *mut HANDLE,
DesiredAccess: DWORD,
DesiredAccess: u32,
ObjectAttributes: *mut c_void,
Flags: ULONG
Flags: u32
) -> NTSTATUS {
panic!("keyed events not available")
}
Expand Down Expand Up @@ -433,9 +432,9 @@ compat_fn_with_fallback! {
apccontext: *mut c_void,
iostatusblock: &mut IO_STATUS_BLOCK,
buffer: *mut crate::mem::MaybeUninit<u8>,
length: ULONG,
length: u32,
byteoffset: Option<&i64>,
key: Option<&ULONG>
key: Option<&u32>
) -> NTSTATUS {
STATUS_NOT_IMPLEMENTED
}
Expand All @@ -447,9 +446,9 @@ compat_fn_with_fallback! {
apccontext: *mut c_void,
iostatusblock: &mut IO_STATUS_BLOCK,
buffer: *const u8,
length: ULONG,
length: u32,
byteoffset: Option<&i64>,
key: Option<&ULONG>
key: Option<&u32>
) -> NTSTATUS {
STATUS_NOT_IMPLEMENTED
}
Expand Down
57 changes: 28 additions & 29 deletions std/src/sys/pal/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ pub struct File {

#[derive(Clone)]
pub struct FileAttr {
attributes: c::DWORD,
attributes: u32,
creation_time: c::FILETIME,
last_access_time: c::FILETIME,
last_write_time: c::FILETIME,
file_size: u64,
reparse_tag: c::DWORD,
reparse_tag: u32,
volume_serial_number: Option<u32>,
number_of_links: Option<u32>,
file_index: Option<u64>,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct FileType {
attributes: c::DWORD,
reparse_tag: c::DWORD,
attributes: u32,
reparse_tag: u32,
}

pub struct ReadDir {
Expand Down Expand Up @@ -75,16 +75,16 @@ pub struct OpenOptions {
create_new: bool,
// system-specific
custom_flags: u32,
access_mode: Option<c::DWORD>,
attributes: c::DWORD,
share_mode: c::DWORD,
security_qos_flags: c::DWORD,
access_mode: Option<u32>,
attributes: u32,
share_mode: u32,
security_qos_flags: u32,
security_attributes: *mut c::SECURITY_ATTRIBUTES,
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FilePermissions {
attrs: c::DWORD,
attrs: u32,
}

#[derive(Copy, Clone, Debug, Default)]
Expand Down Expand Up @@ -245,7 +245,7 @@ impl OpenOptions {
self.security_attributes = attrs;
}

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

fn get_creation_mode(&self) -> io::Result<c::DWORD> {
fn get_creation_mode(&self) -> io::Result<u32> {
match (self.write, self.append) {
(true, false) => {}
(false, false) => {
Expand All @@ -287,7 +287,7 @@ impl OpenOptions {
})
}

fn get_flags_and_attributes(&self) -> c::DWORD {
fn get_flags_and_attributes(&self) -> u32 {
self.custom_flags
| self.attributes
| self.security_qos_flags
Expand Down Expand Up @@ -397,21 +397,21 @@ impl File {
self.handle.as_raw_handle(),
c::FileBasicInfo,
core::ptr::addr_of_mut!(info) as *mut c_void,
size as c::DWORD,
size as u32,
))?;
let mut attr = FileAttr {
attributes: info.FileAttributes,
creation_time: c::FILETIME {
dwLowDateTime: info.CreationTime as c::DWORD,
dwHighDateTime: (info.CreationTime >> 32) as c::DWORD,
dwLowDateTime: info.CreationTime as u32,
dwHighDateTime: (info.CreationTime >> 32) as u32,
},
last_access_time: c::FILETIME {
dwLowDateTime: info.LastAccessTime as c::DWORD,
dwHighDateTime: (info.LastAccessTime >> 32) as c::DWORD,
dwLowDateTime: info.LastAccessTime as u32,
dwHighDateTime: (info.LastAccessTime >> 32) as u32,
},
last_write_time: c::FILETIME {
dwLowDateTime: info.LastWriteTime as c::DWORD,
dwHighDateTime: (info.LastWriteTime >> 32) as c::DWORD,
dwLowDateTime: info.LastWriteTime as u32,
dwHighDateTime: (info.LastWriteTime >> 32) as u32,
},
file_size: 0,
reparse_tag: 0,
Expand All @@ -425,7 +425,7 @@ impl File {
self.handle.as_raw_handle(),
c::FileStandardInfo,
core::ptr::addr_of_mut!(info) as *mut c_void,
size as c::DWORD,
size as u32,
))?;
attr.file_size = info.AllocationSize as u64;
attr.number_of_links = Some(info.NumberOfLinks);
Expand Down Expand Up @@ -511,7 +511,7 @@ impl File {
fn reparse_point(
&self,
space: &mut Align8<[MaybeUninit<u8>]>,
) -> io::Result<(c::DWORD, *mut c::REPARSE_DATA_BUFFER)> {
) -> io::Result<(u32, *mut c::REPARSE_DATA_BUFFER)> {
unsafe {
let mut bytes = 0;
cvt({
Expand All @@ -524,7 +524,7 @@ impl File {
ptr::null_mut(),
0,
space.0.as_mut_ptr().cast(),
len as c::DWORD,
len as u32,
&mut bytes,
ptr::null_mut(),
)
Expand Down Expand Up @@ -609,8 +609,7 @@ impl File {
"Cannot set file timestamp to 0",
));
}
let is_max =
|t: c::FILETIME| t.dwLowDateTime == c::DWORD::MAX && t.dwHighDateTime == c::DWORD::MAX;
let is_max = |t: c::FILETIME| t.dwLowDateTime == u32::MAX && t.dwHighDateTime == u32::MAX;
if times.accessed.map_or(false, is_max)
|| times.modified.map_or(false, is_max)
|| times.created.map_or(false, is_max)
Expand Down Expand Up @@ -641,7 +640,7 @@ impl File {
self.handle.as_raw_handle(),
c::FileBasicInfo,
core::ptr::addr_of_mut!(info) as *mut c_void,
size as c::DWORD,
size as u32,
))?;
Ok(info)
}
Expand Down Expand Up @@ -1020,7 +1019,7 @@ impl FileTimes {
}

impl FileType {
fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType {
fn new(attrs: u32, reparse_tag: u32) -> FileType {
FileType { attributes: attrs, reparse_tag }
}
pub fn is_dir(&self) -> bool {
Expand Down Expand Up @@ -1421,12 +1420,12 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
_TotalBytesTransferred: i64,
_StreamSize: i64,
StreamBytesTransferred: i64,
dwStreamNumber: c::DWORD,
_dwCallbackReason: c::DWORD,
dwStreamNumber: u32,
_dwCallbackReason: u32,
_hSourceFile: c::HANDLE,
_hDestinationFile: c::HANDLE,
lpData: *const c_void,
) -> c::DWORD {
) -> u32 {
if dwStreamNumber == 1 {
*(lpData as *mut i64) = StreamBytesTransferred;
}
Expand Down
13 changes: 4 additions & 9 deletions std/src/sys/pal/windows/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Handle {
buf: &mut [u8],
overlapped: *mut c::OVERLAPPED,
) -> io::Result<Option<usize>> {
let len = cmp::min(buf.len(), <c::DWORD>::MAX as usize) as c::DWORD;
let len = cmp::min(buf.len(), u32::MAX as usize) as u32;
let mut amt = 0;
let res =
cvt(c::ReadFile(self.as_raw_handle(), buf.as_mut_ptr(), len, &mut amt, overlapped));
Expand Down Expand Up @@ -209,12 +209,7 @@ impl Handle {
Ok(Self(self.0.try_clone()?))
}

pub fn duplicate(
&self,
access: c::DWORD,
inherit: bool,
options: c::DWORD,
) -> io::Result<Self> {
pub fn duplicate(&self, access: u32, inherit: bool, options: u32) -> io::Result<Self> {
Ok(Self(self.0.as_handle().duplicate(access, inherit, options)?))
}

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

// The length is clamped at u32::MAX.
let len = cmp::min(len, c::DWORD::MAX as usize) as c::DWORD;
let len = cmp::min(len, u32::MAX as usize) as u32;
let status = c::NtReadFile(
self.as_handle(),
ptr::null_mut(),
Expand Down Expand Up @@ -281,7 +276,7 @@ impl Handle {
let mut io_status = c::IO_STATUS_BLOCK::PENDING;

// The length is clamped at u32::MAX.
let len = cmp::min(buf.len(), c::DWORD::MAX as usize) as c::DWORD;
let len = cmp::min(buf.len(), u32::MAX as usize) as u32;
let status = unsafe {
c::NtWriteFile(
self.as_handle(),
Expand Down
Loading

0 comments on commit a1a1c6a

Please sign in to comment.