Skip to content

Commit

Permalink
it: map keymap with MAP_PRIVATE
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Nov 28, 2024
1 parent 723608c commit bfe76e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src/clientmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ impl ClientMem {
read_only: bool,
client: Option<&Client>,
cpu: Option<&Rc<CpuWorker>>,
) -> Result<Self, ClientMemError> {
Self::new2(fd, len, read_only, client, cpu, c::MAP_SHARED)
}

#[cfg_attr(not(feature = "it"), expect(dead_code))]
pub fn new_private(
fd: &Rc<OwnedFd>,
len: usize,
read_only: bool,
client: Option<&Client>,
cpu: Option<&Rc<CpuWorker>>,
) -> Result<Self, ClientMemError> {
Self::new2(fd, len, read_only, client, cpu, c::MAP_PRIVATE)
}

fn new2(
fd: &Rc<OwnedFd>,
len: usize,
read_only: bool,
client: Option<&Client>,
cpu: Option<&Rc<CpuWorker>>,
flags: c::c_int,
) -> Result<Self, ClientMemError> {
let mut sigbus_impossible = false;
if let Ok(seals) = uapi::fcntl_get_seals(fd.raw()) {
Expand All @@ -79,7 +101,7 @@ impl ClientMem {
false => c::PROT_READ | c::PROT_WRITE,
};
unsafe {
let data = c::mmap64(ptr::null_mut(), len, prot, c::MAP_SHARED, fd.raw(), 0);
let data = c::mmap64(ptr::null_mut(), len, prot, flags, fd.raw(), 0);
if data == c::MAP_FAILED {
return Err(ClientMemError::MmapFailed(uapi::Errno::default().into()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/it/test_ifs/test_virtual_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl TestVirtualKeyboard {
uapi::lseek(memfd.raw(), 0, c::SEEK_SET).unwrap();
uapi::fcntl_add_seals(
memfd.raw(),
c::F_SEAL_SEAL | c::F_SEAL_GROW | c::F_SEAL_SHRINK | c::F_SEAL_WRITE,
c::F_SEAL_SEAL | c::F_SEAL_GROW | c::F_SEAL_SHRINK,
)
.unwrap();
self.tran.send(Keymap {
Expand Down
2 changes: 1 addition & 1 deletion src/it/tests/t0040_virtual_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn test(run: Rc<TestRun>) -> TestResult {
}

fn read_keymap(fd: &Rc<OwnedFd>, size: usize) -> String {
let client_mem = ClientMem::new(fd, size - 1, true, None, None).unwrap();
let client_mem = ClientMem::new_private(fd, size - 1, true, None, None).unwrap();
let client_mem = Rc::new(client_mem).offset(0);
let mut v = vec![];
client_mem.read(&mut v).unwrap();
Expand Down

0 comments on commit bfe76e1

Please sign in to comment.