Fix closing mmap on provider::release_shmem (#2298)

This commit is contained in:
Valentin Huber 2024-06-10 17:59:51 +02:00 committed by GitHub
parent f4699ba385
commit df40db5ae8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -646,6 +646,7 @@ pub mod unix_shmem {
mod default { mod default {
use alloc::string::ToString; use alloc::string::ToString;
use core::{ use core::{
ffi::CStr,
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
ptr, slice, ptr, slice,
}; };
@ -822,6 +823,16 @@ pub mod unix_shmem {
) -> Result<Self::ShMem, Error> { ) -> Result<Self::ShMem, Error> {
MmapShMem::shmem_from_id_and_size(id, size) MmapShMem::shmem_from_id_and_size(id, size)
} }
fn release_shmem(&mut self, shmem: &mut Self::ShMem) {
let fd = CStr::from_bytes_until_nul(shmem.id().as_array())
.unwrap()
.to_str()
.unwrap()
.parse()
.unwrap();
unsafe { close(fd) };
}
} }
impl ShMem for MmapShMem { impl ShMem for MmapShMem {
@ -1032,6 +1043,7 @@ pub mod unix_shmem {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
#[allow(non_camel_case_types)]
struct ashmem_pin { struct ashmem_pin {
pub offset: c_uint, pub offset: c_uint,
pub len: c_uint, pub len: c_uint,