From bd8a377c784a5e8c777e583e529a52d2927e4ce5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 9 Oct 2017 20:36:16 -0600 Subject: [PATCH] Use capability mode (null namespace) for drivers --- ahcid/src/main.rs | 3 +++ alxd/src/main.rs | 5 ++++- bgad/src/main.rs | 3 +++ e1000d/src/main.rs | 5 ++++- ihdad/src/main.rs | 38 +++++++++++--------------------------- nvmed/src/main.rs | 3 +++ ps2d/src/main.rs | 9 +++++++-- rtl8168d/src/main.rs | 2 ++ vboxd/src/main.rs | 2 ++ vesad/src/main.rs | 2 ++ xhcid/src/main.rs | 2 ++ 11 files changed, 43 insertions(+), 31 deletions(-) diff --git a/ahcid/src/main.rs b/ahcid/src/main.rs index 50bd63467a..d9339c41a4 100644 --- a/ahcid/src/main.rs +++ b/ahcid/src/main.rs @@ -48,6 +48,9 @@ fn main() { let mut event_file = File::open("event:").expect("ahcid: failed to open event file"); let scheme = DiskScheme::new(scheme_name, ahci::disks(address, &name)); + + syscall::setrens(0, 0).expect("ahcid: failed to enter null namespace"); + loop { let mut event = Event::default(); if event_file.read(&mut event).expect("ahcid: failed to read event file") == 0 { diff --git a/alxd/src/main.rs b/alxd/src/main.rs index c38bb99682..9762d68301 100644 --- a/alxd/src/main.rs +++ b/alxd/src/main.rs @@ -41,18 +41,21 @@ fn main() { let socket_fd = syscall::open(":network", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("alxd: failed to create network scheme"); let socket = Arc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) })); + let mut irq_file = File::open(format!("irq:{}", irq)).expect("alxd: failed to open IRQ file"); + let address = unsafe { syscall::physmap(bar, 128*1024, MAP_WRITE).expect("alxd: failed to map address") }; { let device = Arc::new(RefCell::new(unsafe { device::Alx::new(address).expect("alxd: failed to allocate device") })); let mut event_queue = EventQueue::::new().expect("alxd: failed to create event queue"); + syscall::setrens(0, 0).expect("alxd: failed to enter null namespace"); + let todo = Arc::new(RefCell::new(Vec::::new())); let device_irq = device.clone(); let socket_irq = socket.clone(); let todo_irq = todo.clone(); - let mut irq_file = File::open(format!("irq:{}", irq)).expect("alxd: failed to open IRQ file"); event_queue.add(irq_file.as_raw_fd(), move |_count: usize| -> Result> { let mut irq = [0; 8]; irq_file.read(&mut irq)?; diff --git a/bgad/src/main.rs b/bgad/src/main.rs index e5ee67d723..e326899aba 100644 --- a/bgad/src/main.rs +++ b/bgad/src/main.rs @@ -40,6 +40,9 @@ fn main() { bga: bga, display: File::open("display:input").ok() }; + + syscall::setrens(0, 0).expect("bgad: failed to enter null namespace"); + loop { let mut packet = Packet::default(); socket.read(&mut packet).expect("bgad: failed to read events from bga scheme"); diff --git a/e1000d/src/main.rs b/e1000d/src/main.rs index 00a6d81301..2278cc2a57 100644 --- a/e1000d/src/main.rs +++ b/e1000d/src/main.rs @@ -36,18 +36,21 @@ fn main() { let socket_fd = syscall::open(":network", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("e1000d: failed to create network scheme"); let socket = Arc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) })); + let mut irq_file = File::open(format!("irq:{}", irq)).expect("e1000d: failed to open IRQ file"); + let address = unsafe { syscall::physmap(bar, 128*1024, MAP_WRITE).expect("e1000d: failed to map address") }; { let device = Arc::new(unsafe { device::Intel8254x::new(address).expect("e1000d: failed to allocate device") }); let mut event_queue = EventQueue::::new().expect("e1000d: failed to create event queue"); + syscall::setrens(0, 0).expect("e1000d: failed to enter null namespace"); + let todo = Arc::new(RefCell::new(Vec::::new())); let device_irq = device.clone(); let socket_irq = socket.clone(); let todo_irq = todo.clone(); - let mut irq_file = File::open(format!("irq:{}", irq)).expect("e1000d: failed to open IRQ file"); event_queue.add(irq_file.as_raw_fd(), move |_count: usize| -> Result> { let mut irq = [0; 8]; irq_file.read(&mut irq)?; diff --git a/ihdad/src/main.rs b/ihdad/src/main.rs index e914783d00..c6e1d9af05 100755 --- a/ihdad/src/main.rs +++ b/ihdad/src/main.rs @@ -20,7 +20,7 @@ use syscall::error::EWOULDBLOCK; pub mod HDA; - + use HDA::IntelHDA; @@ -28,11 +28,11 @@ use HDA::IntelHDA; -/* +/* VEND:PROD Virtualbox 8086:2668 QEMU ICH9 8086:293E - 82801H ICH8 8086:284B + 82801H ICH8 8086:284B */ fn main() { @@ -47,54 +47,43 @@ fn main() { let irq_str = args.next().expect("ihda: no irq provided"); let irq = irq_str.parse::().expect("ihda: failed to parse irq"); - let vend_str = args.next().expect("ihda: no vendor id provided"); let vend = usize::from_str_radix(&vend_str, 16).expect("ihda: failed to parse vendor id"); - let prod_str = args.next().expect("ihda: no product id provided"); let prod = usize::from_str_radix(&prod_str, 16).expect("ihda: failed to parse product id"); print!("{}", format!(" + ihda {} on: {:X} IRQ: {}\n", name, bar, irq)); - // Daemonize if unsafe { syscall::clone(0).unwrap() } == 0 { - - let address = unsafe { syscall::physmap(bar, 0x4000, MAP_WRITE).expect("ihdad: failed to map address") }; { - let mut irq_file = File::open(format!("irq:{}", irq)).expect("IHDA: failed to open IRQ file"); - - let vend_prod:u32 = ((vend as u32) << 16) | (prod as u32); + let vend_prod:u32 = ((vend as u32) << 16) | (prod as u32); let device = Arc::new(RefCell::new(unsafe { HDA::IntelHDA::new(address, vend_prod).expect("ihdad: failed to allocate device") })); let socket_fd = syscall::open(":audio", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("IHDA: failed to create audio scheme"); let socket = Arc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) })); - - - - let mut event_queue = EventQueue::::new().expect("IHDA: Could not create event queue."); - + + syscall::setrens(0, 0).expect("ihdad: failed to enter null namespace"); + let todo = Arc::new(RefCell::new(Vec::::new())); - - + let todo_irq = todo.clone(); let device_irq = device.clone(); let socket_irq = socket.clone(); let device_loop = device.clone(); - event_queue.add(irq_file.as_raw_fd(), move |_count: usize| -> Result> { let mut irq = [0; 8]; irq_file.read(&mut irq)?; - + let _irq = unsafe { device_irq.borrow_mut().irq()}; - + if _irq { irq_file.write(&mut irq)?; @@ -161,10 +150,7 @@ fn main() { }).expect("IHDA: failed to write event"); } - - - - loop { + loop { { //device_loop.borrow_mut().handle_interrupts(); } @@ -186,5 +172,3 @@ fn main() { unsafe { let _ = syscall::physunmap(address); } } } - - diff --git a/nvmed/src/main.rs b/nvmed/src/main.rs index ee26f6f776..531fc74c9d 100644 --- a/nvmed/src/main.rs +++ b/nvmed/src/main.rs @@ -58,6 +58,9 @@ fn main() { let mut event_file = File::open("event:").expect("nvmed: failed to open event file"); let scheme = DiskScheme::new(nvme::disks(address, &name)); + + syscall::setrens(0, 0).expect("nvmed: failed to enter null namespace"); + loop { let mut event = Event::default(); if event_file.read(&mut event).expect("nvmed: failed to read event file") == 0 { diff --git a/ps2d/src/main.rs b/ps2d/src/main.rs index be59ebc6d3..7d4081a7eb 100644 --- a/ps2d/src/main.rs +++ b/ps2d/src/main.rs @@ -269,11 +269,17 @@ fn daemon(input: File) { }, None => (keymap::us::get_char) }; + + let mut key_irq = File::open("irq:1").expect("ps2d: failed to open irq:1"); + + let mut mouse_irq = File::open("irq:12").expect("ps2d: failed to open irq:12"); + let ps2d = Arc::new(RefCell::new(Ps2d::new(input, keymap))); let mut event_queue = EventQueue::<()>::new().expect("ps2d: failed to create event queue"); - let mut key_irq = File::open("irq:1").expect("ps2d: failed to open irq:1"); + syscall::setrens(0, 0).expect("ps2d: failed to enter null namespace"); + let key_ps2d = ps2d.clone(); event_queue.add(key_irq.as_raw_fd(), move |_count: usize| -> Result> { let mut irq = [0; 8]; @@ -284,7 +290,6 @@ fn daemon(input: File) { Ok(None) }).expect("ps2d: failed to poll irq:1"); - let mut mouse_irq = File::open("irq:12").expect("ps2d: failed to open irq:12"); let mouse_ps2d = ps2d; event_queue.add(mouse_irq.as_raw_fd(), move |_count: usize| -> Result> { let mut irq = [0; 8]; diff --git a/rtl8168d/src/main.rs b/rtl8168d/src/main.rs index 3f7b905a58..5b5cc076d3 100644 --- a/rtl8168d/src/main.rs +++ b/rtl8168d/src/main.rs @@ -44,6 +44,8 @@ fn main() { let mut event_queue = EventQueue::::new().expect("rtl8168d: failed to create event queue"); + syscall::setrens(0, 0).expect("rtl8168d: failed to enter null namespace"); + let todo = Arc::new(RefCell::new(Vec::::new())); let device_irq = device.clone(); diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index d84342a41c..90b5205ab1 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -238,6 +238,8 @@ fn main() { let mut event_queue = EventQueue::<()>::new().expect("vboxd: failed to create event queue"); + syscall::setrens(0, 0).expect("vboxd: failed to enter null namespace"); + let mut bga = Bga::new(); let get_mouse = VboxGetMouse::new().expect("vboxd: failed to map GetMouse"); let display_change = VboxDisplayChange::new().expect("vboxd: failed to map DisplayChange"); diff --git a/vesad/src/main.rs b/vesad/src/main.rs index 5f9211bca1..634f3d4687 100644 --- a/vesad/src/main.rs +++ b/vesad/src/main.rs @@ -62,6 +62,8 @@ fn main() { let mut scheme = DisplayScheme::new(width, height, onscreen, &spec); + syscall::setrens(0, 0).expect("vesad: failed to enter null namespace"); + let mut blocked = Vec::new(); loop { let mut packet = Packet::default(); diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index 18fba44441..dac58b0c49 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -49,6 +49,8 @@ fn main() { let mut event_queue = EventQueue::<()>::new().expect("xhcid: failed to create event queue"); + syscall::setrens(0, 0).expect("xhcid: failed to enter null namespace"); + let todo = Arc::new(RefCell::new(Vec::::new())); let hci_irq = hci.clone();