diff --git a/Cargo.lock b/Cargo.lock index 9bffb936bd..95af9bb638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,6 +25,7 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "redox_syscall" version = "0.3.5" +source = "git+https://gitlab.redox-os.org/4lDO2/syscall.git?branch=better_fmap#f0976e1d6020e6854ca30ed1f6d61b10dfc4fa58" dependencies = [ "bitflags", ] diff --git a/Cargo.toml b/Cargo.toml index 846a17fd2b..05de5520a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,4 @@ name = "ipcd" version = "0.1.0" [dependencies] libc = "0.2" -redox_syscall = { path = "../../kernel/source/syscall" } +redox_syscall = { git = "https://gitlab.redox-os.org/4lDO2/syscall.git", branch = "better_fmap" } diff --git a/src/main.rs b/src/main.rs index 0c45d7d102..bde573ea2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![feature(int_roundings)] + use std::{ collections::VecDeque, fs::File, @@ -113,7 +115,7 @@ fn main() -> Result<(), Box> { Ok(0) => break true, Ok(_) => { unsafe { - shm.do_handle(&mut packet); + shm.handle(&mut packet); } shm.socket.write(&packet)?; }, diff --git a/src/shm.rs b/src/shm.rs index f1855e1ee9..db7c8a1ce7 100644 --- a/src/shm.rs +++ b/src/shm.rs @@ -33,41 +33,6 @@ impl ShmScheme { .open(":shm")? }) } - pub unsafe fn do_handle(&mut self, packet: &mut Packet) { - match packet.a { - KSMSG_MMAP_PREP | KSMSG_MMAP => { - let req_file = packet.b; - let req_flags = MapFlags::from_bits_truncate(packet.c); - let req_page_count = packet.d; - let req_offset = u64::from(packet.uid) | (u64::from(packet.gid) << 32); - - let res = self.ksmsg_mmap(req_file, req_flags, req_offset, req_page_count); - - *packet = Packet { - id: packet.id, - a: syscall::Error::mux(res), - ..Packet::default() - }; - } - _ => self.handle(packet), - } - } - pub fn ksmsg_mmap(&mut self, id: usize, _flags: MapFlags, offset: u64, page_count: usize) -> Result { - let path = self.handles.get(&id).ok_or(Error::new(EBADF))?; - let total_size = offset as usize + page_count * PAGE_SIZE; - match self.maps.get_mut(path).expect("handle pointing to nothing").buffer { - Some(ref mut buf) => { - if total_size > buf.len() { - return Err(Error::new(ERANGE)); - } - Ok(buf.as_ptr() + offset as usize) - }, - ref mut buf @ None => { - *buf = Some(MmapGuard::alloc(page_count)?); - Ok(buf.as_mut().unwrap().as_ptr() + offset as usize) - } - } - } } impl SchemeMut for ShmScheme { @@ -110,6 +75,22 @@ impl SchemeMut for ShmScheme { } Ok(0) } + fn mmap_prep(&mut self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result { + let path = self.handles.get(&id).ok_or(Error::new(EBADF))?; + let total_size = offset as usize + size; + match self.maps.get_mut(path).expect("handle pointing to nothing").buffer { + Some(ref mut buf) => { + if total_size > buf.len() { + return Err(Error::new(ERANGE)); + } + Ok(buf.as_ptr() + offset as usize) + }, + ref mut buf @ None => { + *buf = Some(MmapGuard::alloc(size.div_ceil(PAGE_SIZE))?); + Ok(buf.as_mut().unwrap().as_ptr() + offset as usize) + } + } + } } pub struct MmapGuard {