diff --git a/src/wayland/shm/mod.rs b/src/wayland/shm/mod.rs index a148ca9..a8c25f6 100644 --- a/src/wayland/shm/mod.rs +++ b/src/wayland/shm/mod.rs @@ -145,24 +145,26 @@ pub enum BufferAccessError { /// /// If the buffer is not managed by the provided `ShmGlobal`, the closure is not called /// and this method will return `Err(())` (this will be the case for an EGL buffer for example). -pub fn with_buffer_contents(buffer: &Resource, f: F) -> Result<(), BufferAccessError> +pub fn with_buffer_contents( + buffer: &Resource, + f: F, +) -> Result where - F: FnOnce(&[u8], BufferData), + F: FnOnce(&[u8], BufferData) -> T, { if !buffer.is_implemented_with::() { return Err(BufferAccessError::NotManaged); } let data = unsafe { &*(buffer.get_user_data() as *mut InternalBufferData) }; - if data.pool - .with_data_slice(|slice| f(slice, data.data)) - .is_err() - { - // SIGBUS error occured - buffer.post_error(wl_shm::Error::InvalidFd as u32, "Bad pool size.".into()); - return Err(BufferAccessError::BadMap); + match data.pool.with_data_slice(|slice| f(slice, data.data)) { + Ok(t) => Ok(t), + Err(()) => { + // SIGBUS error occured + buffer.post_error(wl_shm::Error::InvalidFd as u32, "Bad pool size.".into()); + Err(BufferAccessError::BadMap) + } } - Ok(()) } impl Implementation, wl_shm::Request> for ShmGlobalData { diff --git a/src/wayland/shm/pool.rs b/src/wayland/shm/pool.rs index 2bbcaab..55ccac5 100644 --- a/src/wayland/shm/pool.rs +++ b/src/wayland/shm/pool.rs @@ -46,7 +46,7 @@ impl Pool { }) } - pub fn with_data_slice(&self, f: F) -> Result<(), ()> { + pub fn with_data_slice T>(&self, f: F) -> Result { // Place the sigbus handler SIGBUS_INIT.call_once(|| unsafe { place_sigbus_handler(); @@ -67,7 +67,7 @@ impl Pool { }); let slice = pool_guard.get_slice(); - f(slice); + let t = f(slice); // Cleanup Post-access SIGBUS_GUARD.with(|guard| { @@ -77,7 +77,7 @@ impl Pool { debug!(self.log, "SIGBUS caught on access on shm pool"; "fd" => self.fd); Err(()) } else { - Ok(()) + Ok(t) } }) }