mirror of
				https://github.com/edera-dev/krata.git
				synced 2025-11-04 07:39:39 +00:00 
			
		
		
		
	hypha: move libraries to libs/
This commit is contained in:
		
							
								
								
									
										11
									
								
								libs/xen/xenevtchn/src/error.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								libs/xen/xenevtchn/src/error.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
use std::io;
 | 
			
		||||
 | 
			
		||||
#[derive(thiserror::Error, Debug)]
 | 
			
		||||
pub enum Error {
 | 
			
		||||
    #[error("kernel error")]
 | 
			
		||||
    Kernel(#[from] nix::errno::Errno),
 | 
			
		||||
    #[error("io issue encountered")]
 | 
			
		||||
    Io(#[from] io::Error),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub type Result<T> = std::result::Result<T, Error>;
 | 
			
		||||
							
								
								
									
										66
									
								
								libs/xen/xenevtchn/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								libs/xen/xenevtchn/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,66 @@
 | 
			
		||||
pub mod error;
 | 
			
		||||
pub mod sys;
 | 
			
		||||
 | 
			
		||||
use crate::error::Result;
 | 
			
		||||
use crate::sys::{BindInterdomain, BindUnboundPort, BindVirq, Notify, UnbindPort};
 | 
			
		||||
 | 
			
		||||
use std::fs::{File, OpenOptions};
 | 
			
		||||
use std::os::fd::AsRawFd;
 | 
			
		||||
 | 
			
		||||
pub struct EventChannel {
 | 
			
		||||
    pub handle: File,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl EventChannel {
 | 
			
		||||
    pub fn open() -> Result<EventChannel> {
 | 
			
		||||
        let file = OpenOptions::new()
 | 
			
		||||
            .read(true)
 | 
			
		||||
            .write(true)
 | 
			
		||||
            .open("/dev/xen/evtchn")?;
 | 
			
		||||
        Ok(EventChannel { handle: file })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn bind_virq(&mut self, virq: u32) -> Result<u32> {
 | 
			
		||||
        unsafe {
 | 
			
		||||
            let mut request = BindVirq { virq };
 | 
			
		||||
            Ok(sys::bind_virq(self.handle.as_raw_fd(), &mut request)? as u32)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn bind_interdomain(&mut self, domid: u32, port: u32) -> Result<u32> {
 | 
			
		||||
        unsafe {
 | 
			
		||||
            let mut request = BindInterdomain {
 | 
			
		||||
                remote_domain: domid,
 | 
			
		||||
                remote_port: port,
 | 
			
		||||
            };
 | 
			
		||||
            Ok(sys::bind_interdomain(self.handle.as_raw_fd(), &mut request)? as u32)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn bind_unbound_port(&mut self, domid: u32) -> Result<u32> {
 | 
			
		||||
        unsafe {
 | 
			
		||||
            let mut request = BindUnboundPort {
 | 
			
		||||
                remote_domain: domid,
 | 
			
		||||
            };
 | 
			
		||||
            Ok(sys::bind_unbound_port(self.handle.as_raw_fd(), &mut request)? as u32)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn unbind(&mut self, port: u32) -> Result<u32> {
 | 
			
		||||
        unsafe {
 | 
			
		||||
            let mut request = UnbindPort { port };
 | 
			
		||||
            Ok(sys::unbind(self.handle.as_raw_fd(), &mut request)? as u32)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn notify(&mut self, port: u32) -> Result<u32> {
 | 
			
		||||
        unsafe {
 | 
			
		||||
            let mut request = Notify { port };
 | 
			
		||||
            Ok(sys::notify(self.handle.as_raw_fd(), &mut request)? as u32)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn reset(&mut self) -> Result<u32> {
 | 
			
		||||
        unsafe { Ok(sys::reset(self.handle.as_raw_fd())? as u32) }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										43
									
								
								libs/xen/xenevtchn/src/sys.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								libs/xen/xenevtchn/src/sys.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,43 @@
 | 
			
		||||
use nix::{ioctl_none, ioctl_readwrite_bad, request_code_none};
 | 
			
		||||
use std::ffi::c_uint;
 | 
			
		||||
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct BindVirq {
 | 
			
		||||
    pub virq: c_uint,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct BindInterdomain {
 | 
			
		||||
    pub remote_domain: c_uint,
 | 
			
		||||
    pub remote_port: c_uint,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct BindUnboundPort {
 | 
			
		||||
    pub remote_domain: c_uint,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct UnbindPort {
 | 
			
		||||
    pub port: c_uint,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct Notify {
 | 
			
		||||
    pub port: c_uint,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ioctl_readwrite_bad!(bind_virq, request_code_none!(b'E', 0), BindVirq);
 | 
			
		||||
ioctl_readwrite_bad!(
 | 
			
		||||
    bind_interdomain,
 | 
			
		||||
    request_code_none!(b'E', 1),
 | 
			
		||||
    BindInterdomain
 | 
			
		||||
);
 | 
			
		||||
ioctl_readwrite_bad!(
 | 
			
		||||
    bind_unbound_port,
 | 
			
		||||
    request_code_none!(b'E', 2),
 | 
			
		||||
    BindUnboundPort
 | 
			
		||||
);
 | 
			
		||||
ioctl_readwrite_bad!(unbind, request_code_none!(b'E', 3), UnbindPort);
 | 
			
		||||
ioctl_readwrite_bad!(notify, request_code_none!(b'E', 4), Notify);
 | 
			
		||||
ioctl_none!(reset, b'E', 5);
 | 
			
		||||
		Reference in New Issue
	
	Block a user