Merge pull request #326 from mahkoh/jorth/pread-to-end
it: map keymap with MAP_PRIVATE
This commit is contained in:
commit
558fe3d3ce
3 changed files with 25 additions and 3 deletions
|
|
@ -53,6 +53,28 @@ impl ClientMem {
|
||||||
read_only: bool,
|
read_only: bool,
|
||||||
client: Option<&Client>,
|
client: Option<&Client>,
|
||||||
cpu: Option<&Rc<CpuWorker>>,
|
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> {
|
) -> Result<Self, ClientMemError> {
|
||||||
let mut sigbus_impossible = false;
|
let mut sigbus_impossible = false;
|
||||||
if let Ok(seals) = uapi::fcntl_get_seals(fd.raw()) {
|
if let Ok(seals) = uapi::fcntl_get_seals(fd.raw()) {
|
||||||
|
|
@ -79,7 +101,7 @@ impl ClientMem {
|
||||||
false => c::PROT_READ | c::PROT_WRITE,
|
false => c::PROT_READ | c::PROT_WRITE,
|
||||||
};
|
};
|
||||||
unsafe {
|
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 {
|
if data == c::MAP_FAILED {
|
||||||
return Err(ClientMemError::MmapFailed(uapi::Errno::default().into()));
|
return Err(ClientMemError::MmapFailed(uapi::Errno::default().into()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl TestVirtualKeyboard {
|
||||||
uapi::lseek(memfd.raw(), 0, c::SEEK_SET).unwrap();
|
uapi::lseek(memfd.raw(), 0, c::SEEK_SET).unwrap();
|
||||||
uapi::fcntl_add_seals(
|
uapi::fcntl_add_seals(
|
||||||
memfd.raw(),
|
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();
|
.unwrap();
|
||||||
self.tran.send(Keymap {
|
self.tran.send(Keymap {
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ async fn test(run: Rc<TestRun>) -> TestResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_keymap(fd: &Rc<OwnedFd>, size: usize) -> String {
|
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 client_mem = Rc::new(client_mem).offset(0);
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
client_mem.read(&mut v).unwrap();
|
client_mem.read(&mut v).unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue