Use updated syscall crate.
This commit is contained in:
Generated
+1
@@ -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",
|
||||
]
|
||||
|
||||
+1
-1
@@ -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" }
|
||||
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
#![feature(int_roundings)]
|
||||
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
fs::File,
|
||||
@@ -113,7 +115,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(0) => break true,
|
||||
Ok(_) => {
|
||||
unsafe {
|
||||
shm.do_handle(&mut packet);
|
||||
shm.handle(&mut packet);
|
||||
}
|
||||
shm.socket.write(&packet)?;
|
||||
},
|
||||
|
||||
+16
-35
@@ -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<usize> {
|
||||
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<usize> {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user