Skip to content

Commit

Permalink
Avoid transforming array parameters with mismatched metadata (#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Sep 20, 2022
1 parent 6d45cc6 commit 5ecc633
Show file tree
Hide file tree
Showing 97 changed files with 1,867 additions and 1,352 deletions.
18 changes: 13 additions & 5 deletions crates/libs/metadata/src/reader/mod.rs
Expand Up @@ -48,7 +48,6 @@ pub enum ArrayInfo {
RelativeByteLen(usize),
RelativePtr(usize),
None,
Removed,
}

#[derive(Clone, PartialEq, PartialOrd, Eq, Ord)]
Expand Down Expand Up @@ -542,6 +541,15 @@ impl<'a> Reader<'a> {
})
.collect();

// Remove any byte arrays that aren't byte-sized types.
for param in &mut params {
if let ArrayInfo::RelativeByteLen(_) = param.array_info {
if !param.ty.is_byte_size() {
param.array_info = ArrayInfo::None
}
}
}

for position in 0..params.len() {
// Point len params back to the corresponding ptr params.
match params[position].array_info {
Expand All @@ -550,12 +558,12 @@ impl<'a> Reader<'a> {
if !self.param_flags(params[relative].def).output() && position != relative && !params[relative].ty.is_pointer() {
params[relative].array_info = ArrayInfo::RelativePtr(position);
} else {
params[position].array_info = ArrayInfo::Removed;
params[position].array_info = ArrayInfo::None;
}
}
ArrayInfo::Fixed(_) => {
if self.param_free_with(params[position].def).is_some() {
params[position].array_info = ArrayInfo::Removed;
params[position].array_info = ArrayInfo::None;
}
}
_ => {}
Expand All @@ -577,9 +585,9 @@ impl<'a> Reader<'a> {
// Remove all sets.
for (len, ptrs) in sets {
if ptrs.len() > 1 {
params[len].array_info = ArrayInfo::Removed;
params[len].array_info = ArrayInfo::None;
for ptr in ptrs {
params[ptr].array_info = ArrayInfo::Removed;
params[ptr].array_info = ArrayInfo::None;
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion crates/libs/metadata/src/reader/type.rs
Expand Up @@ -127,10 +127,18 @@ impl Type {
/// Returns `true` if the `Type` is incomplete.
pub fn is_void(&self) -> bool {
match self {
// TODO: do we care about void behind pointers?
Type::ConstPtr((kind, _)) | Type::MutPtr((kind, _)) => kind.is_void(),
Type::Void => true,
_ => false,
}
}

/// Returns `true` if the `Type` has a byte-sized address.
pub fn is_byte_size(&self) -> bool {
match self {
Type::ConstPtr((kind, _)) | Type::MutPtr((kind, _)) => kind.is_byte_size(),
Type::I8 | Type::U8 | Type::Void | Type::PSTR | Type::PCSTR => true,
_ => false,
}
}
}
Expand Up @@ -258,7 +258,7 @@ where
extern "system" {
fn DRMCreateRight(wszrightname: ::windows::core::PCWSTR, pstfrom: *mut super::super::Foundation::SYSTEMTIME, pstuntil: *mut super::super::Foundation::SYSTEMTIME, cextendedinfo: u32, pwszextendedinfoname: *const ::windows::core::PWSTR, pwszextendedinfovalue: *const ::windows::core::PWSTR, phright: *mut u32) -> ::windows::core::HRESULT;
}
DRMCreateRight(wszrightname.into(), ::core::mem::transmute(pstfrom), ::core::mem::transmute(pstuntil), ::core::mem::transmute(cextendedinfo), ::core::mem::transmute(pwszextendedinfoname.unwrap_or(::std::ptr::null())), ::core::mem::transmute(pwszextendedinfovalue.unwrap_or(::std::ptr::null())), ::core::mem::transmute(phright)).ok()
DRMCreateRight(wszrightname.into(), ::core::mem::transmute(pstfrom), ::core::mem::transmute(pstuntil), cextendedinfo, ::core::mem::transmute(pwszextendedinfoname.unwrap_or(::std::ptr::null())), ::core::mem::transmute(pwszextendedinfovalue.unwrap_or(::std::ptr::null())), ::core::mem::transmute(phright)).ok()
}
#[doc = "*Required features: `\"Win32_Data_RightsManagement\"`*"]
#[inline]
Expand Down
Expand Up @@ -269,15 +269,15 @@ where
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
#[inline]
pub unsafe fn SetCommConfig<'a, P0>(hcommdev: P0, lpcc: &[u8]) -> super::super::Foundation::BOOL
pub unsafe fn SetCommConfig<'a, P0>(hcommdev: P0, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL
where
P0: ::std::convert::Into<super::super::Foundation::HANDLE>,
{
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
fn SetCommConfig(hcommdev: super::super::Foundation::HANDLE, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL;
}
SetCommConfig(hcommdev.into(), ::core::mem::transmute(lpcc.as_ptr()), lpcc.len() as _)
SetCommConfig(hcommdev.into(), ::core::mem::transmute(lpcc), dwsize)
}
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down Expand Up @@ -321,28 +321,28 @@ where
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
#[inline]
pub unsafe fn SetDefaultCommConfigA<'a, P0>(lpszname: P0, lpcc: &[u8]) -> super::super::Foundation::BOOL
pub unsafe fn SetDefaultCommConfigA<'a, P0>(lpszname: P0, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL
where
P0: ::std::convert::Into<::windows::core::PCSTR>,
{
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
fn SetDefaultCommConfigA(lpszname: ::windows::core::PCSTR, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL;
}
SetDefaultCommConfigA(lpszname.into(), ::core::mem::transmute(lpcc.as_ptr()), lpcc.len() as _)
SetDefaultCommConfigA(lpszname.into(), ::core::mem::transmute(lpcc), dwsize)
}
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
#[inline]
pub unsafe fn SetDefaultCommConfigW<'a, P0>(lpszname: P0, lpcc: &[u8]) -> super::super::Foundation::BOOL
pub unsafe fn SetDefaultCommConfigW<'a, P0>(lpszname: P0, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL
where
P0: ::std::convert::Into<::windows::core::PCWSTR>,
{
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
fn SetDefaultCommConfigW(lpszname: ::windows::core::PCWSTR, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL;
}
SetDefaultCommConfigW(lpszname.into(), ::core::mem::transmute(lpcc.as_ptr()), lpcc.len() as _)
SetDefaultCommConfigW(lpszname.into(), ::core::mem::transmute(lpcc), dwsize)
}
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
Expand Down

0 comments on commit 5ecc633

Please sign in to comment.