all: remove unnecessary mem:: prefix
This commit is contained in:
parent
c00ef63afe
commit
1e45a243de
22 changed files with 61 additions and 76 deletions
|
|
@ -43,7 +43,7 @@ use {
|
||||||
ZwpTabletToolV2Id,
|
ZwpTabletToolV2Id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
std::{cell::RefCell, mem, rc::Rc},
|
std::{cell::RefCell, rc::Rc},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Objects {
|
pub struct Objects {
|
||||||
|
|
@ -81,7 +81,7 @@ pub struct Objects {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const MIN_SERVER_ID: u32 = 0xff000000;
|
pub const MIN_SERVER_ID: u32 = 0xff000000;
|
||||||
const SEG_SIZE: usize = 8 * mem::size_of::<usize>();
|
const SEG_SIZE: usize = usize::BITS as usize;
|
||||||
|
|
||||||
impl Objects {
|
impl Objects {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use {
|
||||||
DbusError, DbusType, DynamicType, Parser,
|
DbusError, DbusType, DynamicType, Parser,
|
||||||
},
|
},
|
||||||
bstr::ByteSlice,
|
bstr::ByteSlice,
|
||||||
std::{borrow::Cow, mem, rc::Rc},
|
std::{borrow::Cow, rc::Rc},
|
||||||
uapi::{OwnedFd, Pod},
|
uapi::{OwnedFd, Pod},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ impl<'a> Parser<'a> {
|
||||||
self.align_to(T::ALIGNMENT)?;
|
self.align_to(T::ALIGNMENT)?;
|
||||||
match uapi::pod_read_init(&self.buf[self.pos..]) {
|
match uapi::pod_read_init(&self.buf[self.pos..]) {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
self.pos += mem::size_of::<T>();
|
self.pos += size_of::<T>();
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
_ => Err(DbusError::UnexpectedEof),
|
_ => Err(DbusError::UnexpectedEof),
|
||||||
|
|
@ -95,13 +95,13 @@ impl<'a> Parser<'a> {
|
||||||
return Err(DbusError::UnexpectedEof);
|
return Err(DbusError::UnexpectedEof);
|
||||||
}
|
}
|
||||||
if T::IS_POD {
|
if T::IS_POD {
|
||||||
if len % mem::size_of::<T>() != 0 {
|
if len % size_of::<T>() != 0 {
|
||||||
return Err(DbusError::PodArrayLength);
|
return Err(DbusError::PodArrayLength);
|
||||||
}
|
}
|
||||||
let slice = unsafe {
|
let slice = unsafe {
|
||||||
std::slice::from_raw_parts(
|
std::slice::from_raw_parts(
|
||||||
self.buf[self.pos..].as_ptr() as *const T,
|
self.buf[self.pos..].as_ptr() as *const T,
|
||||||
len / mem::size_of::<T>(),
|
len / size_of::<T>(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
self.pos += len;
|
self.pos += len;
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,8 @@ impl IoOut {
|
||||||
bincode_ops()
|
bincode_ops()
|
||||||
.serialize_into(&mut self.scratch, &msg)
|
.serialize_into(&mut self.scratch, &msg)
|
||||||
.map_err(ForkerError::EncodeFailed)?;
|
.map_err(ForkerError::EncodeFailed)?;
|
||||||
let len = self.scratch.len() - mem::size_of_val(&0usize);
|
let len = self.scratch.len() - size_of_val(&0usize);
|
||||||
self.scratch[..mem::size_of_val(&len)].copy_from_slice(uapi::as_bytes(&len));
|
self.scratch[..size_of_val(&len)].copy_from_slice(uapi::as_bytes(&len));
|
||||||
let mut buf = self.scratch.borrow();
|
let mut buf = self.scratch.borrow();
|
||||||
match self
|
match self
|
||||||
.outgoing
|
.outgoing
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ use {
|
||||||
PrimitiveTopology, PushConstantRange, SampleCountFlags, ShaderStageFlags,
|
PrimitiveTopology, PushConstantRange, SampleCountFlags, ShaderStageFlags,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
std::{mem, rc::Rc, slice},
|
std::{rc::Rc, slice},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(super) struct VulkanPipeline {
|
pub(super) struct VulkanPipeline {
|
||||||
|
|
@ -45,7 +45,7 @@ impl VulkanDevice {
|
||||||
&self,
|
&self,
|
||||||
info: PipelineCreateInfo,
|
info: PipelineCreateInfo,
|
||||||
) -> Result<Rc<VulkanPipeline>, VulkanError> {
|
) -> Result<Rc<VulkanPipeline>, VulkanError> {
|
||||||
self.create_pipeline_(info, mem::size_of::<V>() as _, mem::size_of::<F>() as _)
|
self.create_pipeline_(info, size_of::<V>() as _, size_of::<F>() as _)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_pipeline_(
|
fn create_pipeline_(
|
||||||
|
|
|
||||||
|
|
@ -590,7 +590,7 @@ impl VulkanRenderer {
|
||||||
buf,
|
buf,
|
||||||
pipeline.pipeline_layout,
|
pipeline.pipeline_layout,
|
||||||
ShaderStageFlags::FRAGMENT,
|
ShaderStageFlags::FRAGMENT,
|
||||||
mem::size_of_val(&vert) as _,
|
size_of_val(&vert) as _,
|
||||||
uapi::as_bytes(&frag),
|
uapi::as_bytes(&frag),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ use {
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
cell::{Cell, RefCell, UnsafeCell},
|
cell::{Cell, RefCell, UnsafeCell},
|
||||||
mem::{self},
|
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::atomic::{
|
sync::atomic::{
|
||||||
AtomicU32,
|
AtomicU32,
|
||||||
|
|
@ -119,7 +118,7 @@ impl IoUring {
|
||||||
Err(e) => return Err(IoUringError::MapSqRing(e)),
|
Err(e) => return Err(IoUringError::MapSqRing(e)),
|
||||||
};
|
};
|
||||||
let sqesmap_map = mmap(
|
let sqesmap_map = mmap(
|
||||||
params.sq_entries as usize * mem::size_of::<io_uring_sqe>(),
|
params.sq_entries as usize * size_of::<io_uring_sqe>(),
|
||||||
c::PROT_READ | c::PROT_WRITE,
|
c::PROT_READ | c::PROT_WRITE,
|
||||||
c::MAP_SHARED | c::MAP_POPULATE,
|
c::MAP_SHARED | c::MAP_POPULATE,
|
||||||
fd.raw(),
|
fd.raw(),
|
||||||
|
|
@ -130,8 +129,7 @@ impl IoUring {
|
||||||
Err(e) => return Err(IoUringError::MapSqEntries(e)),
|
Err(e) => return Err(IoUringError::MapSqEntries(e)),
|
||||||
};
|
};
|
||||||
let cqmap_map = mmap(
|
let cqmap_map = mmap(
|
||||||
params.cq_off.cqes as usize
|
params.cq_off.cqes as usize + params.cq_entries as usize * size_of::<io_uring_cqe>(),
|
||||||
+ params.cq_entries as usize * mem::size_of::<io_uring_cqe>(),
|
|
||||||
c::PROT_READ | c::PROT_WRITE,
|
c::PROT_READ | c::PROT_WRITE,
|
||||||
c::MAP_SHARED | c::MAP_POPULATE,
|
c::MAP_SHARED | c::MAP_POPULATE,
|
||||||
fd.raw(),
|
fd.raw(),
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use {
|
||||||
sys::{io_uring_sqe, IORING_OP_CONNECT},
|
sys::{io_uring_sqe, IORING_OP_CONNECT},
|
||||||
IoUring, IoUringData, IoUringError, IoUringTaskId, Task, TaskResultExt,
|
IoUring, IoUringData, IoUringError, IoUringTaskId, Task, TaskResultExt,
|
||||||
},
|
},
|
||||||
std::{mem, ptr, rc::Rc},
|
std::{ptr, rc::Rc},
|
||||||
uapi::{c, OwnedFd, SockAddr},
|
uapi::{c, OwnedFd, SockAddr},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ impl IoUring {
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::copy_nonoverlapping(t, &mut pw.sockaddr as *mut _ as *mut _, 1);
|
ptr::copy_nonoverlapping(t, &mut pw.sockaddr as *mut _ as *mut _, 1);
|
||||||
}
|
}
|
||||||
pw.addrlen = mem::size_of::<T>() as _;
|
pw.addrlen = size_of::<T>() as _;
|
||||||
pw.data = Some(Data {
|
pw.data = Some(Data {
|
||||||
pr: pr.clone(),
|
pr: pr.clone(),
|
||||||
_fd: fd.clone(),
|
_fd: fd.clone(),
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,7 @@ use {
|
||||||
time::Time,
|
time::Time,
|
||||||
utils::{buf::Buf, vec_ext::UninitVecExt},
|
utils::{buf::Buf, vec_ext::UninitVecExt},
|
||||||
},
|
},
|
||||||
std::{
|
std::{mem::MaybeUninit, ptr, rc::Rc},
|
||||||
mem::{self, MaybeUninit},
|
|
||||||
ptr,
|
|
||||||
rc::Rc,
|
|
||||||
},
|
|
||||||
uapi::{c, OwnedFd},
|
uapi::{c, OwnedFd},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -44,7 +40,7 @@ impl IoUring {
|
||||||
let mut fd_ids = self.ring.fd_ids_scratch.borrow_mut();
|
let mut fd_ids = self.ring.fd_ids_scratch.borrow_mut();
|
||||||
fd_ids.clear();
|
fd_ids.clear();
|
||||||
fd_ids.extend(st.fds.iter().map(|f| f.raw()));
|
fd_ids.extend(st.fds.iter().map(|f| f.raw()));
|
||||||
let space = uapi::cmsg_space(mem::size_of_val(&fd_ids[..]));
|
let space = uapi::cmsg_space(size_of_val(&fd_ids[..]));
|
||||||
st.cmsg.clear();
|
st.cmsg.clear();
|
||||||
st.cmsg.reserve(space);
|
st.cmsg.reserve(space);
|
||||||
st.cmsg.set_len_safe(space);
|
st.cmsg.set_len_safe(space);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ mod leaks {
|
||||||
any,
|
any,
|
||||||
cell::Cell,
|
cell::Cell,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
mem, ptr,
|
ptr,
|
||||||
},
|
},
|
||||||
uapi::c,
|
uapi::c,
|
||||||
};
|
};
|
||||||
|
|
@ -115,7 +115,7 @@ mod leaks {
|
||||||
let slice = unsafe {
|
let slice = unsafe {
|
||||||
std::slice::from_raw_parts(
|
std::slice::from_raw_parts(
|
||||||
lo as *const *mut u8,
|
lo as *const *mut u8,
|
||||||
(hi - lo) / mem::size_of::<usize>(),
|
(hi - lo) / size_of::<usize>(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
for addr in slice {
|
for addr in slice {
|
||||||
|
|
@ -301,11 +301,11 @@ mod leaks {
|
||||||
IN_ALLOCATOR.set(IN_ALLOCATOR.get() + 1);
|
IN_ALLOCATOR.set(IN_ALLOCATOR.get() + 1);
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
for allocation in ALLOCATIONS.get().deref().values() {
|
for allocation in ALLOCATIONS.get().deref().values() {
|
||||||
let num = allocation.len / mem::size_of::<usize>();
|
let num = allocation.len / size_of::<usize>();
|
||||||
let elements = std::slice::from_raw_parts(allocation.addr as *const *mut u8, num);
|
let elements = std::slice::from_raw_parts(allocation.addr as *const *mut u8, num);
|
||||||
for (offset, pos) in elements.iter().enumerate() {
|
for (offset, pos) in elements.iter().enumerate() {
|
||||||
if *pos == addr {
|
if *pos == addr {
|
||||||
res.push((allocation.clone(), offset * mem::size_of::<usize>()));
|
res.push((allocation.clone(), offset * size_of::<usize>()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -372,7 +372,7 @@ macro_rules! assert_size_eq {
|
||||||
struct AssertEqSize<T, U>(std::marker::PhantomData<T>, std::marker::PhantomData<U>);
|
struct AssertEqSize<T, U>(std::marker::PhantomData<T>, std::marker::PhantomData<U>);
|
||||||
impl<T, U> AssertEqSize<T, U> {
|
impl<T, U> AssertEqSize<T, U> {
|
||||||
const VAL: usize = {
|
const VAL: usize = {
|
||||||
if std::mem::size_of::<T>() != std::mem::size_of::<U>() {
|
if size_of::<T>() != size_of::<U>() {
|
||||||
panic!("Types have different size");
|
panic!("Types have different size");
|
||||||
}
|
}
|
||||||
1
|
1
|
||||||
|
|
@ -388,7 +388,7 @@ macro_rules! assert_size_le {
|
||||||
struct AssertLeSize<T, U>(std::marker::PhantomData<T>, std::marker::PhantomData<U>);
|
struct AssertLeSize<T, U>(std::marker::PhantomData<T>, std::marker::PhantomData<U>);
|
||||||
impl<T, U> AssertLeSize<T, U> {
|
impl<T, U> AssertLeSize<T, U> {
|
||||||
const VAL: usize = {
|
const VAL: usize = {
|
||||||
if std::mem::size_of::<T>() > std::mem::size_of::<U>() {
|
if size_of::<T>() > size_of::<U>() {
|
||||||
panic!("Left type has size larger than right type");
|
panic!("Left type has size larger than right type");
|
||||||
}
|
}
|
||||||
1
|
1
|
||||||
|
|
@ -403,7 +403,7 @@ macro_rules! assert_align_eq {
|
||||||
struct AssertEqAlign<T, U>(std::marker::PhantomData<T>, std::marker::PhantomData<U>);
|
struct AssertEqAlign<T, U>(std::marker::PhantomData<T>, std::marker::PhantomData<U>);
|
||||||
impl<T, U> AssertEqAlign<T, U> {
|
impl<T, U> AssertEqAlign<T, U> {
|
||||||
const VAL: usize = {
|
const VAL: usize = {
|
||||||
if std::mem::align_of::<T>() != std::mem::align_of::<U>() {
|
if align_of::<T>() != align_of::<U>() {
|
||||||
panic!("Types have different alignment");
|
panic!("Types have different alignment");
|
||||||
}
|
}
|
||||||
1
|
1
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ use {
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
cell::{Cell, RefCell},
|
cell::{Cell, RefCell},
|
||||||
mem,
|
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::atomic::Ordering::{Relaxed, Release},
|
sync::atomic::Ordering::{Relaxed, Release},
|
||||||
},
|
},
|
||||||
|
|
@ -326,13 +325,13 @@ impl PwClientNode {
|
||||||
let sm = port.supported_metas.get();
|
let sm = port.supported_metas.get();
|
||||||
let mut metas = vec![];
|
let mut metas = vec![];
|
||||||
if sm.contains(SUPPORTED_META_HEADER) {
|
if sm.contains(SUPPORTED_META_HEADER) {
|
||||||
metas.push((SPA_META_Header, mem::size_of::<spa_meta_header>()));
|
metas.push((SPA_META_Header, size_of::<spa_meta_header>()));
|
||||||
}
|
}
|
||||||
if sm.contains(SUPPORTED_META_BUSY) {
|
if sm.contains(SUPPORTED_META_BUSY) {
|
||||||
metas.push((SPA_META_Busy, mem::size_of::<spa_meta_busy>()));
|
metas.push((SPA_META_Busy, size_of::<spa_meta_busy>()));
|
||||||
}
|
}
|
||||||
if sm.contains(SUPPORTED_META_VIDEO_CROP) {
|
if sm.contains(SUPPORTED_META_VIDEO_CROP) {
|
||||||
metas.push((SPA_META_VideoCrop, mem::size_of::<spa_meta_region>()));
|
metas.push((SPA_META_VideoCrop, size_of::<spa_meta_region>()));
|
||||||
}
|
}
|
||||||
let sf = &*port.supported_formats.borrow();
|
let sf = &*port.supported_formats.borrow();
|
||||||
let num_formats = sf.formats.len() as u32;
|
let num_formats = sf.formats.len() as u32;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use {
|
||||||
page_size::page_size,
|
page_size::page_size,
|
||||||
ptr_ext::{MutPtrExt, PtrExt},
|
ptr_ext::{MutPtrExt, PtrExt},
|
||||||
},
|
},
|
||||||
std::{marker::PhantomData, mem, ops::Range, rc::Rc},
|
std::{marker::PhantomData, ops::Range, rc::Rc},
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
uapi::{c, OwnedFd, Pod},
|
uapi::{c, OwnedFd, Pod},
|
||||||
};
|
};
|
||||||
|
|
@ -107,8 +107,8 @@ impl PwMemMap {
|
||||||
|
|
||||||
fn check<T>(&self, offset: usize) {
|
fn check<T>(&self, offset: usize) {
|
||||||
assert!(offset <= self.range.len());
|
assert!(offset <= self.range.len());
|
||||||
assert!(mem::size_of::<T>() <= self.range.len() - offset);
|
assert!(size_of::<T>() <= self.range.len() - offset);
|
||||||
assert_eq!((mem::align_of::<T>() - 1) & (self.range.start + offset), 0);
|
assert_eq!((align_of::<T>() - 1) & (self.range.start + offset), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn typed<T: Pod>(self: &Rc<Self>) -> Rc<PwMemTyped<T>> {
|
pub fn typed<T: Pod>(self: &Rc<Self>) -> Rc<PwMemTyped<T>> {
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,7 @@ use {
|
||||||
},
|
},
|
||||||
ahash::AHashMap,
|
ahash::AHashMap,
|
||||||
bstr::{BStr, BString, ByteSlice},
|
bstr::{BStr, BString, ByteSlice},
|
||||||
std::{
|
std::{fmt::Debug, mem::MaybeUninit, rc::Rc},
|
||||||
fmt::Debug,
|
|
||||||
mem::{self, MaybeUninit},
|
|
||||||
rc::Rc,
|
|
||||||
},
|
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
uapi::{OwnedFd, Pod},
|
uapi::{OwnedFd, Pod},
|
||||||
};
|
};
|
||||||
|
|
@ -52,11 +48,11 @@ impl<'a> PwParser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_raw<T: Pod>(&mut self, offset: usize) -> Result<T, PwParserError> {
|
fn read_raw<T: Pod>(&mut self, offset: usize) -> Result<T, PwParserError> {
|
||||||
if self.pos + offset + mem::size_of::<T>() <= self.data.len() {
|
if self.pos + offset + size_of::<T>() <= self.data.len() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut res = MaybeUninit::uninit();
|
let mut res = MaybeUninit::uninit();
|
||||||
let src = self.data[self.pos + offset..].as_ptr();
|
let src = self.data[self.pos + offset..].as_ptr();
|
||||||
std::ptr::copy_nonoverlapping(src, res.as_mut_ptr() as _, mem::size_of::<T>());
|
std::ptr::copy_nonoverlapping(src, res.as_mut_ptr() as _, size_of::<T>());
|
||||||
Ok(res.assume_init())
|
Ok(res.assume_init())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use std::mem;
|
const SEG_SIZE: usize = usize::BITS as usize;
|
||||||
|
|
||||||
const SEG_SIZE: usize = 8 * mem::size_of::<usize>();
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Bitfield {
|
pub struct Bitfield {
|
||||||
|
|
|
||||||
|
|
@ -313,7 +313,7 @@ pub struct TypedBuf<T: Pod> {
|
||||||
impl<T: Pod> TypedBuf<T> {
|
impl<T: Pod> TypedBuf<T> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
buf: Buf::new(mem::size_of::<T>()),
|
buf: Buf::new(size_of::<T>()),
|
||||||
_phantom: Default::default(),
|
_phantom: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ impl<'a> MsgFormatter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binary<T: ?Sized + Packed>(&mut self, t: &T) -> &mut Self {
|
pub fn binary<T: ?Sized + Packed>(&mut self, t: &T) -> &mut Self {
|
||||||
self.uint(mem::size_of_val(t) as u32);
|
self.uint(size_of_val(t) as u32);
|
||||||
self.write(uapi::as_bytes(t));
|
self.write(uapi::as_bytes(t));
|
||||||
let none = [0; 4];
|
let none = [0; 4];
|
||||||
self.write(&none[..self.meta.write_pos.wrapping_neg() & 3]);
|
self.write(&none[..self.meta.write_pos.wrapping_neg() & 3]);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use {
|
use {
|
||||||
crate::{fixed::Fixed, globals::GlobalName, object::ObjectId, utils::buffd::BufFdIn},
|
crate::{fixed::Fixed, globals::GlobalName, object::ObjectId, utils::buffd::BufFdIn},
|
||||||
bstr::{BStr, ByteSlice},
|
bstr::{BStr, ByteSlice},
|
||||||
std::{mem, ptr, rc::Rc},
|
std::{ptr, rc::Rc},
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
uapi::{OwnedFd, Pod},
|
uapi::{OwnedFd, Pod},
|
||||||
};
|
};
|
||||||
|
|
@ -122,30 +122,30 @@ impl<'a, 'b> MsgParser<'a, 'b> {
|
||||||
|
|
||||||
pub fn binary<T: Pod>(&mut self) -> Result<T, MsgParserError> {
|
pub fn binary<T: Pod>(&mut self) -> Result<T, MsgParserError> {
|
||||||
let array = self.array()?;
|
let array = self.array()?;
|
||||||
if array.len() < mem::size_of::<T>() {
|
if array.len() < size_of::<T>() {
|
||||||
return Err(MsgParserError::UnexpectedEof);
|
return Err(MsgParserError::UnexpectedEof);
|
||||||
}
|
}
|
||||||
if array.len() > mem::size_of::<T>() {
|
if array.len() > size_of::<T>() {
|
||||||
return Err(MsgParserError::BinaryArrayTooLarge);
|
return Err(MsgParserError::BinaryArrayTooLarge);
|
||||||
}
|
}
|
||||||
unsafe { Ok(ptr::read_unaligned(array.as_ptr() as _)) }
|
unsafe { Ok(ptr::read_unaligned(array.as_ptr() as _)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binary_array<T: Pod>(&mut self) -> Result<&'b [T], MsgParserError> {
|
pub fn binary_array<T: Pod>(&mut self) -> Result<&'b [T], MsgParserError> {
|
||||||
if std::mem::align_of::<T>() > 4 {
|
if align_of::<T>() > 4 {
|
||||||
panic!("Alignment of binary array element is too large");
|
panic!("Alignment of binary array element is too large");
|
||||||
};
|
};
|
||||||
if std::mem::size_of::<T>() == 0 {
|
if size_of::<T>() == 0 {
|
||||||
panic!("Size of binary array element is 0");
|
panic!("Size of binary array element is 0");
|
||||||
};
|
};
|
||||||
let array = self.array()?;
|
let array = self.array()?;
|
||||||
if array.len() % mem::size_of::<T>() != 0 {
|
if array.len() % size_of::<T>() != 0 {
|
||||||
return Err(MsgParserError::BinaryArraySize);
|
return Err(MsgParserError::BinaryArraySize);
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
Ok(std::slice::from_raw_parts(
|
Ok(std::slice::from_raw_parts(
|
||||||
array.as_ptr() as _,
|
array.as_ptr() as _,
|
||||||
array.len() / mem::size_of::<T>(),
|
array.len() / size_of::<T>(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use {
|
use {
|
||||||
crate::forker::ForkerError,
|
crate::forker::ForkerError,
|
||||||
std::mem,
|
|
||||||
uapi::{c, OwnedFd},
|
uapi::{c, OwnedFd},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -41,7 +40,7 @@ pub fn fork_with_pidfd(pidfd_for_child: bool) -> Result<Forked, ForkerError> {
|
||||||
let pid = c::syscall(
|
let pid = c::syscall(
|
||||||
c::SYS_clone3,
|
c::SYS_clone3,
|
||||||
&mut args as *const _ as usize,
|
&mut args as *const _ as usize,
|
||||||
mem::size_of::<clone_args>(),
|
size_of::<clone_args>(),
|
||||||
);
|
);
|
||||||
if let Err(e) = uapi::map_err!(pid) {
|
if let Err(e) = uapi::map_err!(pid) {
|
||||||
return Err(ForkerError::Fork(e.into()));
|
return Err(ForkerError::Fork(e.into()));
|
||||||
|
|
|
||||||
|
|
@ -457,26 +457,26 @@ impl DrmMaster {
|
||||||
let mut t = MaybeUninit::<T>::uninit();
|
let mut t = MaybeUninit::<T>::uninit();
|
||||||
match mode_getprobblob(self.raw(), blob.0, &mut t) {
|
match mode_getprobblob(self.raw(), blob.0, &mut t) {
|
||||||
Err(e) => Err(DrmError::GetPropBlob(e)),
|
Err(e) => Err(DrmError::GetPropBlob(e)),
|
||||||
Ok(n) if n != mem::size_of::<T>() => Err(DrmError::InvalidProbSize),
|
Ok(n) if n != size_of::<T>() => Err(DrmError::InvalidProbSize),
|
||||||
_ => unsafe { Ok(t.assume_init()) },
|
_ => unsafe { Ok(t.assume_init()) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getblob_vec<T: Pod>(&self, blob: DrmBlob) -> Result<Vec<T>, DrmError> {
|
pub fn getblob_vec<T: Pod>(&self, blob: DrmBlob) -> Result<Vec<T>, DrmError> {
|
||||||
assert_ne!(mem::size_of::<T>(), 0);
|
assert_ne!(size_of::<T>(), 0);
|
||||||
let mut vec = vec![];
|
let mut vec = vec![];
|
||||||
loop {
|
loop {
|
||||||
let (_, bytes) = vec.split_at_spare_mut_bytes_ext();
|
let (_, bytes) = vec.split_at_spare_mut_bytes_ext();
|
||||||
match mode_getprobblob(self.raw(), blob.0, bytes) {
|
match mode_getprobblob(self.raw(), blob.0, bytes) {
|
||||||
Err(e) => return Err(DrmError::GetPropBlob(e)),
|
Err(e) => return Err(DrmError::GetPropBlob(e)),
|
||||||
Ok(n) if n % mem::size_of::<T>() != 0 => return Err(DrmError::UnalignedPropSize),
|
Ok(n) if n % size_of::<T>() != 0 => return Err(DrmError::UnalignedPropSize),
|
||||||
Ok(n) if n <= bytes.len() => {
|
Ok(n) if n <= bytes.len() => {
|
||||||
unsafe {
|
unsafe {
|
||||||
vec.set_len(n / mem::size_of::<T>());
|
vec.set_len(n / size_of::<T>());
|
||||||
}
|
}
|
||||||
return Ok(vec);
|
return Ok(vec);
|
||||||
}
|
}
|
||||||
Ok(n) => vec.reserve_exact(n / mem::size_of::<T>()),
|
Ok(n) => vec.reserve_exact(n / size_of::<T>()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -499,10 +499,10 @@ impl DrmMaster {
|
||||||
}
|
}
|
||||||
let formats_start = header.formats_offset as usize;
|
let formats_start = header.formats_offset as usize;
|
||||||
let formats_end = formats_start
|
let formats_end = formats_start
|
||||||
.wrapping_add((header.count_formats as usize).wrapping_mul(mem::size_of::<u32>()));
|
.wrapping_add((header.count_formats as usize).wrapping_mul(size_of::<u32>()));
|
||||||
let modifiers_start = header.modifiers_offset as usize;
|
let modifiers_start = header.modifiers_offset as usize;
|
||||||
let modifiers_end = modifiers_start.wrapping_add(
|
let modifiers_end = modifiers_start.wrapping_add(
|
||||||
(header.count_modifiers as usize).wrapping_mul(mem::size_of::<drm_format_modifier>()),
|
(header.count_modifiers as usize).wrapping_mul(size_of::<drm_format_modifier>()),
|
||||||
);
|
);
|
||||||
if blob.len() < formats_end || formats_end < formats_start {
|
if blob.len() < formats_end || formats_end < formats_start {
|
||||||
log::error!("Formats of IN_FORMATS blob don't fit in the blob");
|
log::error!("Formats of IN_FORMATS blob don't fit in the blob");
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ use {
|
||||||
std::{
|
std::{
|
||||||
ffi::CString,
|
ffi::CString,
|
||||||
io::{BufRead, BufReader},
|
io::{BufRead, BufReader},
|
||||||
mem,
|
|
||||||
},
|
},
|
||||||
uapi::{c, pod_zeroed, OwnedFd, Pod, Ustring},
|
uapi::{c, pod_zeroed, OwnedFd, Pod, Ustring},
|
||||||
};
|
};
|
||||||
|
|
@ -921,7 +920,7 @@ const DRM_IOCTL_MODE_CREATEPROPBLOB: u64 = drm_iowr::<drm_mode_create_blob>(0xbd
|
||||||
pub fn mode_create_blob<T>(fd: c::c_int, t: &T) -> Result<DrmBlob, OsError> {
|
pub fn mode_create_blob<T>(fd: c::c_int, t: &T) -> Result<DrmBlob, OsError> {
|
||||||
let mut res = drm_mode_create_blob {
|
let mut res = drm_mode_create_blob {
|
||||||
data: t as *const T as _,
|
data: t as *const T as _,
|
||||||
length: mem::size_of_val(t) as _,
|
length: size_of_val(t) as _,
|
||||||
blob_id: 0,
|
blob_id: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1096,7 +1095,7 @@ pub fn mode_getprobblob<T: Pod + ?Sized>(
|
||||||
) -> Result<usize, OsError> {
|
) -> Result<usize, OsError> {
|
||||||
let mut res = drm_mode_get_blob {
|
let mut res = drm_mode_get_blob {
|
||||||
blob_id,
|
blob_id,
|
||||||
length: mem::size_of_val(t) as _,
|
length: size_of_val(t) as _,
|
||||||
data: t as *const T as *const u8 as _,
|
data: t as *const T as *const u8 as _,
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
||||||
|
|
@ -597,7 +597,7 @@ impl Xcon {
|
||||||
long_offset: 0,
|
long_offset: 0,
|
||||||
long_length: 128,
|
long_length: 128,
|
||||||
};
|
};
|
||||||
let format = mem::size_of::<T>() as u8 * 8;
|
let format = size_of::<T>() as u8 * 8;
|
||||||
loop {
|
loop {
|
||||||
let res = self.call(&gp).await?;
|
let res = self.call(&gp).await?;
|
||||||
let res = res.get();
|
let res = res.get();
|
||||||
|
|
@ -611,10 +611,10 @@ impl Xcon {
|
||||||
if res.format != format {
|
if res.format != format {
|
||||||
return Err(XconError::InvalidPropertyFormat(format, res.format));
|
return Err(XconError::InvalidPropertyFormat(format, res.format));
|
||||||
}
|
}
|
||||||
if res.data.len() % mem::size_of::<T>() != 0 {
|
if res.data.len() % size_of::<T>() != 0 {
|
||||||
return Err(XconError::IrregularPropertyLength);
|
return Err(XconError::IrregularPropertyLength);
|
||||||
}
|
}
|
||||||
let len = res.data.len() / mem::size_of::<T>();
|
let len = res.data.len() / size_of::<T>();
|
||||||
buf.reserve(len);
|
buf.reserve(len);
|
||||||
let (_, uninit) = buf.split_at_spare_mut_bytes_ext();
|
let (_, uninit) = buf.split_at_spare_mut_bytes_ext();
|
||||||
uninit[..res.data.len()].copy_from_slice(uapi::as_maybe_uninit_bytes(res.data));
|
uninit[..res.data.len()].copy_from_slice(uapi::as_maybe_uninit_bytes(res.data));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use {
|
||||||
xcon::{wire_type::Message, XconError},
|
xcon::{wire_type::Message, XconError},
|
||||||
},
|
},
|
||||||
bstr::{BStr, ByteSlice},
|
bstr::{BStr, ByteSlice},
|
||||||
std::{borrow::Cow, mem, rc::Rc},
|
std::{borrow::Cow, rc::Rc},
|
||||||
uapi::{OwnedFd, Pod},
|
uapi::{OwnedFd, Pod},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ impl<'a> Parser<'a> {
|
||||||
pub fn read_pod<T: Pod>(&mut self) -> Result<T, XconError> {
|
pub fn read_pod<T: Pod>(&mut self) -> Result<T, XconError> {
|
||||||
match uapi::pod_read_init(&self.buf[self.pos..]) {
|
match uapi::pod_read_init(&self.buf[self.pos..]) {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
self.pos += mem::size_of::<T>();
|
self.pos += size_of::<T>();
|
||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
_ => Err(XconError::UnexpectedEof),
|
_ => Err(XconError::UnexpectedEof),
|
||||||
|
|
@ -78,13 +78,13 @@ impl<'a> Parser<'a> {
|
||||||
) -> Result<&'a [T], XconError> {
|
) -> Result<&'a [T], XconError> {
|
||||||
let n = match n {
|
let n = match n {
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
_ => self.rem() / mem::size_of::<T>(),
|
_ => self.rem() / size_of::<T>(),
|
||||||
};
|
};
|
||||||
let len = mem::size_of::<T>() * n;
|
let len = size_of::<T>() * n;
|
||||||
if len > self.rem() {
|
if len > self.rem() {
|
||||||
return Err(XconError::UnexpectedEof);
|
return Err(XconError::UnexpectedEof);
|
||||||
}
|
}
|
||||||
if self.buf[self.pos..].as_ptr() as usize & (mem::align_of::<T>() - 1) != 0 {
|
if self.buf[self.pos..].as_ptr() as usize & (align_of::<T>() - 1) != 0 {
|
||||||
return Err(XconError::UnalignedSlice);
|
return Err(XconError::UnalignedSlice);
|
||||||
}
|
}
|
||||||
let res =
|
let res =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue