diff --git a/src/gpu/i915/mod.rs b/src/gpu/i915/mod.rs index 9a39590..02d98d9 100644 --- a/src/gpu/i915/mod.rs +++ b/src/gpu/i915/mod.rs @@ -13,7 +13,7 @@ pub struct DrmDeviceNode { pub path: Option, } -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct GemHandle<'a> { pub handle: DrmGemHandle, pub node: &'a DrmDeviceNode, @@ -39,12 +39,12 @@ impl GemHandle<'_> { }; return Ok(res); } else { - return Err(is_valid.err().unwrap_or(GemIoctlError::PermissionDenied)); + return Err(is_valid.err().unwrap_or(GemIoctlError::InvalidHandle)); } } pub fn close(self) -> Result<(), i32> { - return uapi::i915::close_gem(self.node.fd.as_raw_fd(), self.handle.clone()); + return unsafe { uapi::i915::close_gem_ref(self.node.fd.as_raw_fd(), &self.handle) }; } pub fn has_tiling(&self) -> Result { @@ -59,7 +59,7 @@ impl GemHandle<'_> { impl Drop for GemHandle<'_> { fn drop(&mut self) { // Ignoring the close failing as an invalid Gem handle's drop is a no-op - _ = uapi::i915::close_gem(self.node.fd.as_raw_fd(), self.handle.clone()); + _ = unsafe { uapi::i915::close_gem_ref(self.node.fd.as_raw_fd(), &self.handle) }; } } diff --git a/src/uapi/i915/mod.rs b/src/uapi/i915/mod.rs index 7d05da2..22d622f 100644 --- a/src/uapi/i915/mod.rs +++ b/src/uapi/i915/mod.rs @@ -29,7 +29,7 @@ pub struct EngineInfo { pub capabilities: u64, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq)] pub struct DrmGemHandle { pub handle: u32, } @@ -180,7 +180,7 @@ pub fn make_gem(fd: RawFd, size: u64) -> Option { } } -pub fn close_gem(fd: RawFd, handle: DrmGemHandle) -> Result<(), i32> { +pub unsafe fn close_gem_ref(fd: RawFd, handle: &DrmGemHandle) -> Result<(), i32> { unsafe { let mut close = native::drm_gem_close { handle: handle.handle, @@ -194,6 +194,12 @@ pub fn close_gem(fd: RawFd, handle: DrmGemHandle) -> Result<(), i32> { } } +pub fn close_gem(fd: RawFd, handle: DrmGemHandle) -> Result<(), i32> { + unsafe { + close_gem_ref(fd, &handle) + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum GemIoctlError { InvalidHandle, @@ -210,7 +216,8 @@ pub fn gem_has_tiling(fd: RawFd, handle: &DrmGemHandle) -> Result Ok(true), libc::ENOENT => Err(GemIoctlError::InvalidHandle), libc::EPERM => Err(GemIoctlError::PermissionDenied), @@ -226,11 +233,11 @@ pub fn gem_is_valid(fd: RawFd, handle: &DrmGemHandle) -> Result 0); assert!(i915::gem_is_valid(node.fd.as_raw_fd(), &gem).unwrap()); - i915::close_gem(node.fd.as_raw_fd(), gem.clone()).expect("Failed to close gem"); + let tmp = i915::DrmGemHandle { handle: gem.handle }; + i915::close_gem(node.fd.as_raw_fd(), tmp).expect("Failed to close gem"); assert!(!i915::gem_is_valid(node.fd.as_raw_fd(), &gem).unwrap()); let invalid_fd = File::open("/dev/null").expect("Failed to open /dev/null"); assert!(i915::make_gem(invalid_fd.as_raw_fd(), 4096).is_none());