diff --git a/Makefile b/Makefile index bcdbd9d9..80b4a014 100644 --- a/Makefile +++ b/Makefile @@ -60,8 +60,6 @@ root := ./ domain_list := $(addprefix domains/build/, \ redleaf_init \ dom_proxy \ - dom_a \ - dom_b \ dom_c \ dom_d \ shadow \ diff --git a/domains/Cargo.lock b/domains/Cargo.lock index c46528e8..f21941cf 100644 --- a/domains/Cargo.lock +++ b/domains/Cargo.lock @@ -226,37 +226,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "dom_a" -version = "0.1.0" -dependencies = [ - "console", - "interface", - "lazy_static", - "libsyscalls", - "libtime", - "malloc", - "num-traits", - "spin 0.5.3", - "syscalls", - "tls", -] - -[[package]] -name = "dom_b" -version = "0.1.0" -dependencies = [ - "console", - "interface", - "lazy_static", - "libsyscalls", - "libtime", - "malloc", - "num-traits", - "spin 0.5.3", - "syscalls", -] - [[package]] name = "dom_c" version = "0.1.0" @@ -1036,7 +1005,6 @@ dependencies = [ "libsyscalls", "libtime", "malloc", - "rref", "volatile_accessor", ] @@ -1054,7 +1022,6 @@ dependencies = [ "platform", "protocol", "redhttpd", - "rref", "smolnet", "smoltcp", "spin 0.5.3", @@ -1074,7 +1041,6 @@ dependencies = [ "libtime", "malloc", "pci_driver", - "rref", "spin 0.5.3", "virtio_device", "volatile_accessor", diff --git a/domains/Cargo.toml b/domains/Cargo.toml index e313bee1..739d5ebb 100644 --- a/domains/Cargo.toml +++ b/domains/Cargo.toml @@ -18,8 +18,6 @@ members = [ "usr/test/benchhash", "usr/test/benchnet_inside", "usr/test/benchnvme", - "usr/test/dom_a", - "usr/test/dom_b", "usr/test/dom_c", "usr/test/dom_d", "usr/test/shadow", diff --git a/domains/lib/libbenchtpm/src/lib.rs b/domains/lib/libbenchtpm/src/lib.rs index 427d52aa..ecd71377 100644 --- a/domains/lib/libbenchtpm/src/lib.rs +++ b/domains/lib/libbenchtpm/src/lib.rs @@ -18,24 +18,24 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { // Changing locality let locality = 0; - println!("burst_count {}", tpm.tpm_get_burst(locality)); + println!("burst_count {}", tpm.tpm_get_burst(locality).unwrap()); // Initially we have locality 0 - println!("request locality {}", tpm.tpm_request_locality(locality)); - println!("validate locality {}", tpm.tpm_validate_locality(locality)); + println!("request locality {}", tpm.tpm_request_locality(locality).unwrap()); + println!("validate locality {}", tpm.tpm_validate_locality(locality).unwrap()); // Deactivate all localities tpm.tpm_deactivate_all_localities(); let locality = 2; // Then request target localities - println!("request locality {}", tpm.tpm_request_locality(locality)); - println!("validate locality {}", tpm.tpm_validate_locality(locality)); + println!("request locality {}", tpm.tpm_request_locality(locality).unwrap()); + println!("validate locality {}", tpm.tpm_validate_locality(locality).unwrap()); // Get 1 byte of random value - println!("random {}", tpm.tpm_get_random(locality, 1)); + println!("random {}", tpm.tpm_get_random(locality, 1).unwrap()); // PCR extend // First we obtain "banks" that are allocated in the TPM. // In TPM2, there can be multiple banks, each implementing different hash algorithms. - let tpm_info = tpm.tpm_get_pcr_allocation(locality); + let tpm_info = tpm.tpm_get_pcr_allocation(locality).unwrap(); let mut digests: Vec = Vec::new(); for i in 0..(tpm_info.nr_allocated_banks as usize) { let mut digest: Vec = Vec::new(); @@ -53,7 +53,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { TpmAlgorithms::TPM_ALG_SHA256 as u16, &mut pcr_size, &mut pcr, - ); + ).unwrap(); println!("pre-extend pcr {:x?}", pcr); println!("pcr_size {}", pcr_size); // Then extend the PCR @@ -67,7 +67,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { TpmAlgorithms::TPM_ALG_SHA256 as u16, &mut pcr_size, &mut pcr, - ); + ).unwrap(); println!("post-extend pcr {:x?}", pcr); println!("pcr_size {}", pcr_size); @@ -87,17 +87,17 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { &mut parent_handle, &mut primary_pubkey_size, &mut primary_pubkey, - ); + ).unwrap(); println!("parent_handle {:x?}", parent_handle); // Start authenticated session let mut session_handle: u32 = 0 as u32; let nonce = alloc::vec![0; 32]; - tpm.tpm_start_auth_session(locality, TpmSE::TPM_SE_TRIAL, nonce, &mut session_handle); + tpm.tpm_start_auth_session(locality, TpmSE::TPM_SE_TRIAL, nonce, &mut session_handle).unwrap(); // Tie session to PCR 17 - tpm.tpm_policy_pcr(locality, session_handle, b"".to_vec(), pcr_idx); + tpm.tpm_policy_pcr(locality, session_handle, b"".to_vec(), pcr_idx).unwrap(); // Get digest of authenticated session let mut policy_digest: Vec = Vec::new(); - tpm.tpm_policy_get_digest(locality, session_handle, &mut policy_digest); + tpm.tpm_policy_get_digest(locality, session_handle, &mut policy_digest).unwrap(); // Create Child key wrapped with SRK // Load Child key to TPM // Seal data under PCR 17 using Child key @@ -115,7 +115,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { /*sign=*/ false, &mut create_out_private, &mut create_out_public, - ); + ).unwrap(); let mut item_handle: u32 = 0 as u32; tpm.tpm_load( locality, @@ -123,7 +123,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { create_out_private, create_out_public, &mut item_handle, - ); + ).unwrap(); // Unsealing Data // Start authenticated session @@ -134,18 +134,18 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { TpmSE::TPM_SE_POLICY, nonce, &mut unseal_session_handle, - ); + ).unwrap(); // Tie session to PCR 17 - tpm.tpm_policy_pcr(locality, unseal_session_handle, b"".to_vec(), pcr_idx); + tpm.tpm_policy_pcr(locality, unseal_session_handle, b"".to_vec(), pcr_idx).unwrap(); // Unseal data under PCR 17 using Child key (should succeed) let mut out_data: Vec = Vec::new(); - tpm.tpm_unseal(locality, unseal_session_handle, item_handle, &mut out_data); + tpm.tpm_unseal(locality, unseal_session_handle, item_handle, &mut out_data).unwrap(); // Unload all objects from TPM memory - tpm.tpm_flush_context(locality, parent_handle); - tpm.tpm_flush_context(locality, session_handle); - tpm.tpm_flush_context(locality, item_handle); - tpm.tpm_flush_context(locality, unseal_session_handle); + tpm.tpm_flush_context(locality, parent_handle).unwrap(); + tpm.tpm_flush_context(locality, session_handle).unwrap(); + tpm.tpm_flush_context(locality, item_handle).unwrap(); + tpm.tpm_flush_context(locality, unseal_session_handle).unwrap(); // Create Attestation Identity Key let aik_unique = b"remote_attestation"; @@ -162,7 +162,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { &mut aik_handle, &mut aik_pubkey_size, &mut aik_pubkey, - ); + ).unwrap(); println!("aik_handle {:x?}", aik_handle); // Generate random nonce. This should be generated by remote verifier. let nonce = b"random_nonce"; @@ -180,7 +180,7 @@ pub fn test_tpm(tpm: &dyn UsrTpm) { pcr_idxs, &mut out_pcr_digest, &mut out_sig, - ); + ).unwrap(); println!("out_pcr_digest {:x?}", out_pcr_digest); println!("out_sig {:x?}", out_sig); } diff --git a/domains/sys/driver/pci/src/main.rs b/domains/sys/driver/pci/src/main.rs index 5097ac22..74d8eaef 100644 --- a/domains/sys/driver/pci/src/main.rs +++ b/domains/sys/driver/pci/src/main.rs @@ -15,6 +15,8 @@ use console::println; use core::panic::PanicInfo; use libsyscalls::syscalls::{sys_backtrace, sys_println}; use syscalls::{Heap, Syscall}; +use interface::rpc::RpcResult; +use interface::error::{Result, ErrorKind}; use pci_driver::{PciClass, PciDriver}; @@ -35,36 +37,38 @@ impl interface::pci::PCI for PCI { pci_driver: &mut dyn PciDriver, bar_index: usize, class: Option<(PciClass, u8)>, - ) -> Result<(), ()> { - println!("Register driver called"); - let vendor_id = pci_driver.get_vid(); - let device_id = pci_driver.get_did(); - // match vid, dev_id with the registered pci devices we have and - // typecast the barregion to the appropriate one for this device - let pci_devs = &*PCI_DEVICES.lock(); - let pci_dev: &PciDevice = match class { - Some((class, subclass)) => pci_devs - .iter() - .filter(|header| header.class() == class && header.subclass() == subclass) - .next() - .ok_or(()), - None => pci_devs - .iter() - .filter(|header| header.vendor_id() == vendor_id && header.device_id() == device_id) - .next() - .ok_or(()), - }?; - - // TODO: dont panic here - let bar = pci_dev.get_bar(bar_index, pci_driver.get_driver_type()); - - pci_driver.probe(bar); - - Ok(()) + ) -> RpcResult> { + Ok(|| -> Result<()> { + println!("Register driver called"); + let vendor_id = pci_driver.get_vid(); + let device_id = pci_driver.get_did(); + // match vid, dev_id with the registered pci devices we have and + // typecast the barregion to the appropriate one for this device + let pci_devs = &*PCI_DEVICES.lock(); + let pci_dev = match class { + Some((class, subclass)) => pci_devs + .iter() + .filter(|header| header.class() == class && header.subclass() == subclass) + .next() + .ok_or(ErrorKind::InvalidPciClass), + None => pci_devs + .iter() + .filter(|header| header.vendor_id() == vendor_id && header.device_id() == device_id) + .next() + .ok_or(ErrorKind::InvalidPciDeviceID), + }; + let pci_dev = pci_dev?; + + // TODO: dont panic here + let bar = pci_dev.get_bar(bar_index, pci_driver.get_driver_type()); + + pci_driver.probe(bar); + Ok(()) + }()) } - fn pci_clone(&self) -> Box { - Box::new((*self).clone()) + fn pci_clone(&self) -> RpcResult> { + Ok(Box::new((*self).clone())) } } diff --git a/domains/sys/driver/tpm/src/usr_tpm.rs b/domains/sys/driver/tpm/src/usr_tpm.rs index 1195dfe0..41cea7e8 100644 --- a/domains/sys/driver/tpm/src/usr_tpm.rs +++ b/domains/sys/driver/tpm/src/usr_tpm.rs @@ -1,5 +1,6 @@ use alloc::vec::Vec; use interface::tpm::*; +use interface::rpc::RpcResult; macro_rules! generate_tpm { ($($(#[$attr:meta])* fn $func:ident(&self $(,)? $($arg:ident : $ty:ty),* $(,)? ) $(-> $ret:ty)? );* $(;)?) => { @@ -16,14 +17,14 @@ macro_rules! generate_tpm { } impl ::interface::tpm::UsrTpm for UsrTpm { - fn clone_usrtpm(&self) -> alloc::boxed::Box { - box Self::new(self.tpm.clone_tpmdev()) + fn clone_usrtpm(&self) -> RpcResult> { + Ok(box Self::new(self.tpm.clone_tpmdev())) } $( $(#[$attr])* fn $func(&self, $($arg: $ty,)*) $(-> $ret)? { - ::libtpm::$func(&*self.tpm, $($arg), *) + Ok(::libtpm::$func(&*self.tpm, $($arg), *)) } )* } @@ -31,231 +32,230 @@ macro_rules! generate_tpm { } generate_tpm!( - /// ## Locality related functions - /// - /// Locality tells the TPM where the command originated. - /// Validates the TPM locality, basically means that TPM is ready to listen for commands and - /// perform operation in this locality. - /// Ref: https://ebrary.net/24811/computer_science/locality_command - fn tpm_validate_locality(&self, locality: u32) -> bool; - - /// Explicitly giveup locality. This may not be useful if there is only a single process/user using - /// TPM in an OS. In multi-user scenario, this is more applicable. - fn relinquish_locality(&self, locality: u32) -> bool; - - fn tpm_deactivate_all_localities(&self) -> bool; - - /// Requests the TPM to switch to the locality we choose and wait for TPM to acknowledge our - /// request - fn tpm_request_locality(&self, locality: u32) -> bool; - - /// Reads the TPM ID from device register - fn read_tpm_id(&self, locality: u32); - - /// Reads the burst_count from TPM register. Burst count is the amount of bytes the TPM device is - /// capable of handling in oneshot. - fn tpm_get_burst(&self, locality: u32) -> u16; - - /// Busy-wait in a loop for a particular status flag to be set - fn wait_for_status_flag(&self, locality: u32, flag: u8, timeout_ms: usize) -> bool; - - /// Writes data to the TPM FIFO. - /// Here, `data.len < burst_count` - fn tpm_write_data(&self, locality: u32, data: &[u8]) -> usize; - - /// Checks TPM status register to see if there is any data available - fn is_data_available(&self, locality: u32) -> bool; - - /// Read data from TPM - /// * Wait for data to be available - /// * Receive as much as burst_count - fn tpm_read_data(&self, locality: u32, data: &mut [u8]) -> usize; - - /// Wrapper for `tpm_read_data` - /// This function first tries to read TPM_HEADER_SIZE bytes from the TPM to determine the length of - /// payload data. - /// Then it issues a second read for the length of payload data subtract TPM_HEADER_SIZE - /// Payload consists of the argument that was sent to the TPM during tpm_send_data and the response - fn tpm_recv_data(&self, locality: u32, buf: &mut Vec, rc: &mut u32) -> usize; - - /// Wrapper for `tpm_write_data` - /// This function waits for TPM to be in a state to accept commands before writing data to FIFO. - fn tpm_send_data(&self, locality: u32, buf: &mut Vec) -> usize; - - /// Transmit command to a TPM. - /// This function does a bi-directional communication with TPM. - /// First, it sends a command with headers - /// If successful, try to read the response buffer from TPM - fn tpm_transmit_cmd(&self, locality: u32, buf: &mut Vec); - - /// Table 3:68 - TPM2_GetRandom Command - /// Get a random number from TPM. - /// `num_octets` represents the length of the random number in bytes - fn tpm_get_random(&self, locality: u32, num_octets: usize) -> bool; - - /// Table 3:114 - TPM2_PCR_Read Command - /// Read a PCR register. - /// Since the communication channel between the process and the TPM is untrusted, - /// TPM2_Quote should be the command to retreive PCR values, not TPM2_PCR_Read - fn tpm_pcr_read( - &self, - locality: u32, - pcr_idx: usize, - hash: u16, - digest_size: &mut u16, - digest: &mut Vec, - ) -> bool; - - /// Obtain information about banks that are allocated in TPM - fn tpm_init_bank_info(&self, locality: u32, hash_alg: u16) -> TpmBankInfo; - - /// Table 3:208 - TPM2_PCR_GetCapability Command - /// Obtain the banks that are allocated in TPM - /// TODO: Return true/false, not structure - fn tpm_get_pcr_allocation(&self, locality: u32) -> TpmDevInfo; - - /// Table 3:110 - TPM2_PCR_Read Command - /// Extend PCR register. - /// The value sent to the TPM will be concatenated with the original value and hashed. - fn tpm_pcr_extend( - &self, - locality: u32, - tpm_info: &TpmDevInfo, - pcr_idx: usize, - digest_values: Vec, - ) -> bool; - - /// Table 3:78 - TPM2_HashSequenceStart Command - /// Conduct hash calculation in TPM - fn tpm_hash_sequence_start(&self, locality: u32, hash: TpmAlgorithms, object: &mut u32) - -> bool; - - /// Table 3:80 - TPM2_SequenceUpdate - /// Update hash calculation in TPM - fn tpm_sequence_update(&self, locality: u32, object: u32, buffer: Vec) -> bool; - - /// Table 3:82 - TPM2_SequenceComplete - /// Finalize hash calculation in TPM - fn tpm_sequence_complete( - &self, - locality: u32, - object: u32, - buffer: Vec, - hash_size: &mut u16, - hash: &mut Vec, - ) -> bool; - - /// Table 3:62 - TPM2_Hash - /// Generic hash calculation in TPM when data size is known - fn tpm_hash( - &self, - locality: u32, - hash: TpmAlgorithms, - buffer: Vec, - hash_size: &mut u16, - hash_val: &mut Vec, - ) -> bool; - - /// Table 3:164 - TPM2_PCR_CreatePrimary Command - /// Create Primary Key. - /// This includes Storate Root Keys and Attestation Identity Keys. - fn tpm_create_primary( - &self, - locality: u32, - pcr_idx: Option, - unique_base: &[u8], - restricted: bool, - decrypt: bool, - sign: bool, - parent_handle: &mut u32, - pubkey_size: &mut usize, - pubkey: &mut Vec, - ) -> bool; - - /// Table 3:15 - TPM2_StartAuthSession Command - /// Start Authenticated Session and returns a session handle - fn tpm_start_auth_session( - &self, - locality: u32, - session_type: TpmSE, - nonce: Vec, - session_handle: &mut u32, - ) -> bool; - - /// Table 3:132 - TPM2_PolicyPCR Command - /// Bind a policy to a particular PCR - fn tpm_policy_pcr( - &self, - locality: u32, - session_handle: u32, - digest: Vec, - pcr_idx: usize, - ) -> bool; - - /// Table 3:156 - TPM2_PolicyGetDigest Command - /// Get Policy digest from current policy - fn tpm_policy_get_digest( - &self, - locality: u32, - session_handle: u32, - policy_digest: &mut Vec, - ) -> bool; - - /// Table 3:19 - TPM2_Create Command - /// Create child key - fn tpm_create( - &self, - locality: u32, - pcr_idx: Option, - parent_handle: u32, - policy: Vec, - sensitive_data: Vec, - restricted: bool, - decrypt: bool, - sign: bool, - out_private: &mut Vec, - out_public: &mut Vec, - ) -> bool; - - /// Table 3:21 - TPM2_Load Command - /// Load objects into the TPM. - /// The TPM2B_PUBLIC and TPM2B_PRIVATE objects created by the TPM2_Create command - /// are to be loaded. - fn tpm_load( - &self, - locality: u32, - parent_handle: u32, - in_private: Vec, - in_public: Vec, - item_handle: &mut u32, - ) -> bool; - - /// Table 3:31 - TPM2_Unseal Command - /// Unseal data sealed via TPM_CC_CREATE - fn tpm_unseal( - &self, - locality: u32, - session_handle: u32, - item_handle: u32, - out_data: &mut Vec, - ) -> bool; - - /// Table 3:90 - TPM2_Quote - /// Generate Quote. - /// Since the communication channel between the process and the TPM is untrusted, - /// TPM2_Quote should be the command to retreive PCR values, not TPM2_PCR_Read - fn tpm_quote( - &self, - locality: u32, - handle: u32, - hash: u16, - nonce: Vec, - pcr_idxs: Vec, - out_pcr_digest: &mut Vec, - out_sig: &mut Vec, - ) -> bool; - - /// Table 3:198 - TPM2_FlushContext Command - /// Remove loaded objects, sequence objects, and/or sessions from TPM memory - fn tpm_flush_context(&self, locality: u32, flush_handle: u32) -> bool; + /// ## Locality related functions + /// + /// Locality tells the TPM where the command originated. + /// Validates the TPM locality, basically means that TPM is ready to listen for commands and + /// perform operation in this locality. + /// Ref: https://ebrary.net/24811/computer_science/locality_command + fn tpm_validate_locality(&self, locality: u32) -> RpcResult; + + /// Explicitly giveup locality. This may not be useful if there is only a single process/user using + /// TPM in an OS. In multi-user scenario, this is more applicable. + fn relinquish_locality(&self, locality: u32) -> RpcResult; + + fn tpm_deactivate_all_localities(&self) -> RpcResult; + + /// Requests the TPM to switch to the locality we choose and wait for TPM to acknowledge our + /// request + fn tpm_request_locality(&self, locality: u32) -> RpcResult; + + /// Reads the TPM ID from device register + fn read_tpm_id(&self, locality: u32) -> RpcResult<()>; + + /// Reads the burst_count from TPM register. Burst count is the amount of bytes the TPM device is + /// capable of handling in oneshot. + fn tpm_get_burst(&self, locality: u32) -> RpcResult; + + /// Busy-wait in a loop for a particular status flag to be set + fn wait_for_status_flag(&self, locality: u32, flag: u8, timeout_ms: usize) -> RpcResult; + + /// Writes data to the TPM FIFO. + /// Here, `data.len < burst_count` + fn tpm_write_data(&self, locality: u32, data: &[u8]) -> RpcResult; + + /// Checks TPM status register to see if there is any data available + fn is_data_available(&self, locality: u32) -> RpcResult; + + /// Read data from TPM + /// * Wait for data to be available + /// * Receive as much as burst_count + fn tpm_read_data(&self, locality: u32, data: &mut [u8]) -> RpcResult; + + /// Wrapper for `tpm_read_data` + /// This function first tries to read TPM_HEADER_SIZE bytes from the TPM to determine the length of + /// payload data. + /// Then it issues a second read for the length of payload data subtract TPM_HEADER_SIZE + /// Payload consists of the argument that was sent to the TPM during tpm_send_data and the response + fn tpm_recv_data(&self, locality: u32, buf: &mut Vec, rc: &mut u32) -> RpcResult; + + /// Wrapper for `tpm_write_data` + /// This function waits for TPM to be in a state to accept commands before writing data to FIFO. + fn tpm_send_data(&self, locality: u32, buf: &mut Vec) -> RpcResult; + + /// Transmit command to a TPM. + /// This function does a bi-directional communication with TPM. + /// First, it sends a command with headers + /// If successful, try to read the response buffer from TPM + fn tpm_transmit_cmd(&self, locality: u32, buf: &mut Vec) -> RpcResult<()>; + + /// Table 3:68 - TPM2_GetRandom Command + /// Get a random number from TPM. + /// `num_octets` represents the length of the random number in bytes + fn tpm_get_random(&self, locality: u32, num_octets: usize) -> RpcResult; + + /// Table 3:114 - TPM2_PCR_Read Command + /// Read a PCR register. + /// Since the communication channel between the process and the TPM is untrusted, + /// TPM2_Quote should be the command to retreive PCR values, not TPM2_PCR_Read + fn tpm_pcr_read( + &self, + locality: u32, + pcr_idx: usize, + hash: u16, + digest_size: &mut u16, + digest: &mut Vec, + ) -> RpcResult; + + /// Obtain information about banks that are allocated in TPM + fn tpm_init_bank_info(&self, locality: u32, hash_alg: u16) -> RpcResult; + + /// Table 3:208 - TPM2_PCR_GetCapability Command + /// Obtain the banks that are allocated in TPM + /// TODO: Return true/false, not structure + fn tpm_get_pcr_allocation(&self, locality: u32) -> RpcResult; + + /// Table 3:110 - TPM2_PCR_Read Command + /// Extend PCR register. + /// The value sent to the TPM will be concatenated with the original value and hashed. + fn tpm_pcr_extend( + &self, + locality: u32, + tpm_info: &TpmDevInfo, + pcr_idx: usize, + digest_values: Vec, + ) -> RpcResult; + + /// Table 3:78 - TPM2_HashSequenceStart Command + /// Conduct hash calculation in TPM + fn tpm_hash_sequence_start(&self, locality: u32, hash: TpmAlgorithms, object: &mut u32) -> RpcResult; + + /// Table 3:80 - TPM2_SequenceUpdate + /// Update hash calculation in TPM + fn tpm_sequence_update(&self, locality: u32, object: u32, buffer: Vec) -> RpcResult; + + /// Table 3:82 - TPM2_SequenceComplete + /// Finalize hash calculation in TPM + fn tpm_sequence_complete( + &self, + locality: u32, + object: u32, + buffer: Vec, + hash_size: &mut u16, + hash: &mut Vec, + ) -> RpcResult; + + /// Table 3:62 - TPM2_Hash + /// Generic hash calculation in TPM when data size is known + fn tpm_hash( + &self, + locality: u32, + hash: TpmAlgorithms, + buffer: Vec, + hash_size: &mut u16, + hash_val: &mut Vec, + ) -> RpcResult; + + /// Table 3:164 - TPM2_PCR_CreatePrimary Command + /// Create Primary Key. + /// This includes Storate Root Keys and Attestation Identity Keys. + fn tpm_create_primary( + &self, + locality: u32, + pcr_idx: Option, + unique_base: &[u8], + restricted: bool, + decrypt: bool, + sign: bool, + parent_handle: &mut u32, + pubkey_size: &mut usize, + pubkey: &mut Vec, + ) -> RpcResult; + + /// Table 3:15 - TPM2_StartAuthSession Command + /// Start Authenticated Session and returns a session handle + fn tpm_start_auth_session( + &self, + locality: u32, + session_type: TpmSE, + nonce: Vec, + session_handle: &mut u32, + ) -> RpcResult; + + /// Table 3:132 - TPM2_PolicyPCR Command + /// Bind a policy to a particular PCR + fn tpm_policy_pcr( + &self, + locality: u32, + session_handle: u32, + digest: Vec, + pcr_idx: usize, + ) -> RpcResult; + + /// Table 3:156 - TPM2_PolicyGetDigest Command + /// Get Policy digest from current policy + fn tpm_policy_get_digest( + &self, + locality: u32, + session_handle: u32, + policy_digest: &mut Vec, + ) -> RpcResult; + + /// Table 3:19 - TPM2_Create Command + /// Create child key + fn tpm_create( + &self, + locality: u32, + pcr_idx: Option, + parent_handle: u32, + policy: Vec, + sensitive_data: Vec, + restricted: bool, + decrypt: bool, + sign: bool, + out_private: &mut Vec, + out_public: &mut Vec, + ) -> RpcResult; + + /// Table 3:21 - TPM2_Load Command + /// Load objects into the TPM. + /// The TPM2B_PUBLIC and TPM2B_PRIVATE objects created by the TPM2_Create command + /// are to be loaded. + fn tpm_load( + &self, + locality: u32, + parent_handle: u32, + in_private: Vec, + in_public: Vec, + item_handle: &mut u32, + ) -> RpcResult; + + /// Table 3:31 - TPM2_Unseal Command + /// Unseal data sealed via TPM_CC_CREATE + fn tpm_unseal( + &self, + locality: u32, + session_handle: u32, + item_handle: u32, + out_data: &mut Vec, + ) -> RpcResult; + + /// Table 3:90 - TPM2_Quote + /// Generate Quote. + /// Since the communication channel between the process and the TPM is untrusted, + /// TPM2_Quote should be the command to retreive PCR values, not TPM2_PCR_Read + fn tpm_quote( + &self, + locality: u32, + handle: u32, + hash: u16, + nonce: Vec, + pcr_idxs: Vec, + out_pcr_digest: &mut Vec, + out_sig: &mut Vec, + ) -> RpcResult; + + /// Table 3:198 - TPM2_FlushContext Command + /// Remove loaded objects, sequence objects, and/or sessions from TPM memory + fn tpm_flush_context(&self, locality: u32, flush_handle: u32) -> RpcResult; ); diff --git a/domains/sys/init/src/main.rs b/domains/sys/init/src/main.rs index 8b96ff83..d57af071 100644 --- a/domains/sys/init/src/main.rs +++ b/domains/sys/init/src/main.rs @@ -14,7 +14,7 @@ use alloc::sync::Arc; use alloc::vec::Vec; use console::println; use core::panic::PanicInfo; -use interface::domain_creation::*; +use interface::domain_create::*; use libsyscalls::syscalls::{ sys_backtrace, sys_create_thread, sys_readch_kbd, sys_recv_int, sys_yield, }; @@ -95,35 +95,31 @@ fn test_dummy_syscall() { // rustc --explain E0225 // // We have to re-write in an ugly way +// This entry point must match with the signature in kernel/src/generated_domain_create.rs:create_domain_init #[no_mangle] pub fn trusted_entry( s: Box, heap: Box, ints: Box, - create_proxy: Box, - create_xv6: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_pci: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - _create_hashstore: Arc, - create_tpm: Arc, - create_shadow: Arc, + create_proxy: Arc, + create_pci: Arc, + create_membdev: Arc, + create_bdev_shadow: Arc, + create_ixgbe: Arc, + create_virtio_net: Arc, + create_net_shadow: Arc, + create_nvme_shadow: Arc, + create_nvme: Arc, + create_xv6fs: Arc, + create_xv6net: Arc, + create_xv6net_shadow: Arc, + create_xv6usr: Arc, + create_xv6: Arc, + create_dom_c: Arc, + create_dom_d: Arc, + create_shadow: Arc, + create_benchnvme: Arc, + create_tpm: Arc, ) { libsyscalls::syscalls::init(s); interface::rref::init(heap, libsyscalls::syscalls::sys_get_current_domain_id()); @@ -189,7 +185,7 @@ pub fn trusted_entry( println!("about to create proxy"); let (_dom_proxy, proxy) = create_proxy.create_domain_proxy( create_pci, - create_ahci, + // create_ahci, create_membdev, create_bdev_shadow, create_ixgbe, @@ -197,27 +193,20 @@ pub fn trusted_entry( create_nvme, create_net_shadow, create_nvme_shadow, - create_benchnet, + // create_benchnet, create_benchnvme, create_xv6fs, create_xv6net, create_xv6net_shadow, create_xv6usr, create_xv6, - create_dom_a, - create_dom_b, create_dom_c, create_dom_d, create_shadow, + create_tpm, ); println!("created proxy"); - #[cfg(feature = "test_ab")] - { - let (dom_dom_a, dom_a) = proxy.as_create_dom_a().create_domain_dom_a(); - let dom_dom_b = proxy.as_create_dom_b().create_domain_dom_b(dom_a); - } - #[cfg(feature = "test_cd")] { #[cfg(not(feature = "shadow"))] @@ -230,18 +219,18 @@ pub fn trusted_entry( } #[cfg(feature = "tpm")] - let (_dom_tpm, usr_tpm) = create_tpm.create_domain_tpm(); + let (_dom_tpm, usr_tpm) = proxy.as_domain_create_CreateTpm().create_domain_tpm(); #[cfg(feature = "hashbench")] - let dom_hashstore = create_hashstore.create_domain_hashstore(); + let dom_hashstore = proxy.as_domain_create_CreateSashstore().create_domain_hashstore(); println!("Creating pci"); - let (_dom_pci, pci) = proxy.as_create_pci().create_domain_pci(); + let (_dom_pci, pci) = proxy.as_domain_create_CreatePCI().create_domain_pci(); #[cfg(feature = "virtnet")] let (_, net) = proxy - .as_create_virtio_net() - .create_domain_virtio_net(pci.pci_clone()); + .as_domain_create_CreateVirtioNet() + .create_domain_virtio_net(pci.pci_clone().unwrap()); #[cfg(all(not(feature = "shadow"), not(feature = "virtnet")))] let (_, net) = proxy.as_create_ixgbe().create_domain_ixgbe(pci.pci_clone()); #[cfg(all(feature = "shadow", not(feature = "virtnet")))] @@ -255,22 +244,28 @@ pub fn trusted_entry( #[cfg(feature = "membdev")] #[cfg(not(feature = "shadow"))] // Memfs is linked with the shadow domain so membdev doesn't work without shadow currently. - let (dom_ahci, bdev) = proxy.as_create_membdev().create_domain_membdev(&mut []); + let (dom_ahci, bdev) = proxy.as_domain_create_CreateMemBDev().create_domain_membdev(&mut []); #[cfg(feature = "membdev")] #[cfg(feature = "shadow")] let (_dom_ahci, bdev) = proxy - .as_create_bdev_shadow() - .create_domain_bdev_shadow(proxy.as_create_membdev()); + .as_domain_create_CreateBDevShadow() + .create_domain_bdev_shadow(proxy.as_domain_create_CreateMemBDev()); println!("Creating nvme domain!"); #[cfg(not(feature = "shadow"))] - let (dom_nvme, nvme) = proxy.as_create_nvme().create_domain_nvme(pci.pci_clone()); + let (dom_nvme, nvme) = proxy.as_domain_create_CreateNvme().create_domain_nvme(pci.pci_clone()); #[cfg(feature = "shadow")] let (_dom_nvme, nvme) = proxy - .as_create_nvme_shadow() - .create_domain_nvme_shadow(proxy.as_create_nvme(), pci.pci_clone()); + .as_domain_create_CreateNvmeShadow() + .create_domain_nvme_shadow(proxy.as_domain_create_CreateNvme(), pci.pci_clone().unwrap()); println!("Creating ixgbe"); + #[cfg(not(feature = "shadow"))] + let (dom_ixgbe, net) = proxy.as_domain_create_CreateRv6Net().create_domain_ixgbe(pci.pci_clone()); + #[cfg(feature = "shadow")] + let (_dom_ixgbe, net) = proxy + .as_domain_create_CreateNetShadow() + .create_domain_net_shadow(proxy.as_domain_create_CreateIxgbe(), pci.pci_clone().unwrap()); #[cfg(feature = "benchnet")] let _ = proxy.as_create_benchnet().create_domain_benchnet(net); @@ -281,12 +276,12 @@ pub fn trusted_entry( #[cfg(not(any(feature = "benchnet", feature = "benchnvme")))] { println!("Starting xv6 kernel"); - let (_dom_xv6, rv6) = proxy.as_create_xv6().create_domain_xv6kernel( + let (_dom_xv6, rv6) = proxy.as_domain_create_CreateRv6().create_domain_xv6kernel( ints_clone, - proxy.as_create_xv6fs(), - proxy.as_create_xv6net(), - proxy.as_create_xv6net_shadow(), - proxy.as_create_xv6usr(), + proxy.as_domain_create_CreateRv6FS(), + proxy.as_domain_create_CreateRv6Net(), + proxy.as_domain_create_CreateRv6NetShadow(), + proxy.as_domain_create_CreateRv6Usr(), bdev, net, nvme, diff --git a/domains/usr/proxy/Cargo.toml b/domains/usr/proxy/Cargo.toml index 5076047f..50b2f0f6 100644 --- a/domains/usr/proxy/Cargo.toml +++ b/domains/usr/proxy/Cargo.toml @@ -25,8 +25,11 @@ default-features = false [features] default = [ - "tramp", + #"tramp", + "log", ] # Enable stack unwinding. RPC calls will return an error if the thread unwinds tramp = ["interface/trampoline"] +# Log +log = ["interface/proxy-log-error"] \ No newline at end of file diff --git a/domains/usr/proxy/src/gen.rs b/domains/usr/proxy/src/gen.rs deleted file mode 100644 index 713872cc..00000000 --- a/domains/usr/proxy/src/gen.rs +++ /dev/null @@ -1,991 +0,0 @@ -use alloc::boxed::Box; -use alloc::sync::Arc; -use console::{print, println}; -use core::mem::transmute; -use interface::domain_creation; -use libsyscalls::syscalls::{ - sys_discard_cont, sys_get_current_domain_id, sys_update_current_domain_id, -}; -use interface::proxy; -use interface::rref::{traits::CustomCleanup, RRef, RRefDeque, RRefVec}; -use syscalls::{Domain, Heap, Interrupt}; -use unwind::trampoline; -use interface; -use interface::error::Result; -use interface::rpc::{RpcError, RpcResult}; -use interface::{ - bdev::{BDev, BlkReq, NvmeBDev, BSIZE}, - dom_a::DomA, - dom_c::DomC, - net::{Net, NetworkStats}, - pci::{PciBar, PciResource, PCI}, - rv6::Rv6, - tpm::UsrTpm, - usrnet::UsrNet, - vfs::{UsrVFS, VFS}, -}; - -// TODO: remove once ixgbe on rrefdeque -use alloc::{collections::VecDeque, vec::Vec}; - -#[derive(Clone)] -pub struct Proxy { - create_pci: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_xv6: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - create_shadow: Arc, -} - -unsafe impl Send for Proxy {} -unsafe impl Sync for Proxy {} - -impl Proxy { - pub fn new( - create_pci: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_xv6: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - create_shadow: Arc, - ) -> Proxy { - Proxy { - create_pci, - create_ahci, - create_membdev, - create_bdev_shadow, - create_ixgbe, - create_virtio_net, - create_nvme, - create_net_shadow, - create_nvme_shadow, - create_benchnet, - create_benchnvme, - create_xv6fs, - create_xv6net, - create_xv6net_shadow, - create_xv6usr, - create_xv6, - create_dom_a, - create_dom_b, - create_dom_c, - create_dom_d, - create_shadow, - } - } -} - -impl proxy::Proxy for Proxy { - // TODO: figure out how to do this without Arc::new every time - fn as_create_pci(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_ahci(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_membdev(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_bdev_shadow(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_ixgbe(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_virtio_net(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_net_shadow(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_nvme_shadow(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_benchnet(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_benchnvme(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_nvme(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_xv6fs(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_xv6net(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_xv6net_shadow(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_xv6usr(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_xv6(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_dom_a(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_dom_b(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_dom_c(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_dom_d(&self) -> Arc { - Arc::new(self.clone()) - } - fn as_create_shadow(&self) -> Arc { - Arc::new(self.clone()) - } -} - -impl interface::domain_creation::CreatePCI for Proxy { - fn create_domain_pci(&self) -> (Box, Box) { - self.create_pci.create_domain_pci() - } -} - -impl interface::domain_creation::CreateAHCI for Proxy { - fn create_domain_ahci(&self, pci: Box) -> (Box, Box) { - let (domain, ahci) = self.create_ahci.create_domain_ahci(pci); - let domain_id = domain.get_domain_id(); - return (domain, Box::new(BDevProxy::new(domain_id, ahci))); - } -} - -impl interface::domain_creation::CreateMemBDev for Proxy { - fn create_domain_membdev( - &self, - memdisk: &'static mut [u8], - ) -> (Box, Box) { - let (domain, membdev) = self.create_membdev.create_domain_membdev(memdisk); - let domain_id = domain.get_domain_id(); - return (domain, Box::new(BDevProxy::new(domain_id, membdev))); - } - - fn recreate_domain_membdev( - &self, - dom: Box, - memdisk: &'static mut [u8], - ) -> (Box, Box) { - let (domain, membdev) = self.create_membdev.recreate_domain_membdev(dom, memdisk); - let domain_id = domain.get_domain_id(); - return (domain, Box::new(BDevProxy::new(domain_id, membdev))); - } -} - -impl interface::domain_creation::CreateBDevShadow for Proxy { - fn create_domain_bdev_shadow( - &self, - create: Arc, - ) -> (Box, Box) { - let (domain, shadow) = self.create_bdev_shadow.create_domain_bdev_shadow(create); - let domain_id = domain.get_domain_id(); - return (domain, Box::new(BDevProxy::new(domain_id, shadow))); - } -} - -impl interface::domain_creation::CreateIxgbe for Proxy { - fn create_domain_ixgbe(&self, pci: Box) -> (Box, Box) { - let (domain, ixgbe) = self.create_ixgbe.create_domain_ixgbe(pci); - let domain_id = domain.get_domain_id(); - (domain, Box::new(IxgbeProxy::new(domain_id, ixgbe))) - } -} - -impl interface::domain_creation::CreateVirtioNet for Proxy { - fn create_domain_virtio_net(&self, pci: Box) -> (Box, Box) { - let (domain, virtnet) = self.create_virtio_net.create_domain_virtio_net(pci); - let domain_id = domain.get_domain_id(); - (domain, Box::new(IxgbeProxy::new(domain_id, virtnet))) - } -} - -impl interface::domain_creation::CreateNetShadow for Proxy { - fn create_domain_net_shadow( - &self, - create: Arc, - pci: Box, - ) -> (Box, Box) { - let (domain, shadow) = self.create_net_shadow.create_domain_net_shadow(create, pci); - let domain_id = domain.get_domain_id(); - return (domain, Box::new(IxgbeProxy::new(domain_id, shadow))); - } -} - -impl interface::domain_creation::CreateNvmeShadow for Proxy { - fn create_domain_nvme_shadow( - &self, - create: Arc, - pci: Box, - ) -> (Box, Box) { - let (domain, shadow) = self - .create_nvme_shadow - .create_domain_nvme_shadow(create, pci); - let domain_id = domain.get_domain_id(); - return (domain, Box::new(NvmeBDevProxy::new(domain_id, shadow))); - } -} - -impl interface::domain_creation::CreateNvme for Proxy { - fn create_domain_nvme(&self, pci: Box) -> (Box, Box) { - // TODO: write NvmeBDevProxy - let (domain, nvme) = self.create_nvme.create_domain_nvme(pci); - let domain_id = domain.get_domain_id(); - return (domain, Box::new(NvmeBDevProxy::new(domain_id, nvme))); - } -} - -impl interface::domain_creation::CreateRv6FS for Proxy { - fn create_domain_xv6fs(&self, bdev: Box) -> (Box, Box) { - // TODO: write Rv6FSProxy - self.create_xv6fs.create_domain_xv6fs(bdev) - } -} - -impl interface::domain_creation::CreateRv6Net for Proxy { - fn create_domain_xv6net(&self, net: Box) -> (Box, Box) { - let (domain, xv6net) = self.create_xv6net.create_domain_xv6net(net); - let domain_id = domain.get_domain_id(); - (domain, Box::new(UsrNetProxy::new(domain_id, xv6net))) - } -} - -impl interface::domain_creation::CreateRv6NetShadow for Proxy { - fn create_domain_xv6net_shadow( - &self, - create: Arc, - net: Box, - ) -> (Box, Box) { - let (domain, xv6net) = self - .create_xv6net_shadow - .create_domain_xv6net_shadow(create, net); - let domain_id = domain.get_domain_id(); - (domain, Box::new(UsrNetProxy::new(domain_id, xv6net))) - } -} - -impl interface::domain_creation::CreateRv6Usr for Proxy { - fn create_domain_xv6usr( - &self, - name: &str, - xv6: Box, - blob: &[u8], - args: &str, - ) -> Result> { - // TODO: write Rv6UsrProxy - self.create_xv6usr - .create_domain_xv6usr(name, xv6, blob, args) - } -} - -impl interface::domain_creation::CreateRv6 for Proxy { - fn create_domain_xv6kernel( - &self, - ints: Box, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - bdev: Box, - net: Box, - nvme: Box, - usr_tpm: Box, - ) -> (Box, Box) { - let (domain, rv6) = self.create_xv6.create_domain_xv6kernel( - ints, - create_xv6fs, - create_xv6net, - create_xv6net_shadow, - create_xv6usr, - bdev, - net, - nvme, - usr_tpm, - ); - let domain_id = domain.get_domain_id(); - (domain, Box::new(Rv6Proxy::new(domain_id, rv6))) - } -} - -impl interface::domain_creation::CreateDomA for Proxy { - fn create_domain_dom_a(&self) -> (Box, Box) { - let (domain, dom_a) = self.create_dom_a.create_domain_dom_a(); - let domain_id = domain.get_domain_id(); - return (domain, Box::new(DomAProxy::new(domain_id, dom_a))); - } -} - -impl interface::domain_creation::CreateDomB for Proxy { - fn create_domain_dom_b(&self, dom_a: Box) -> (Box) { - self.create_dom_b.create_domain_dom_b(dom_a) - } -} - -impl interface::domain_creation::CreateDomC for Proxy { - fn create_domain_dom_c(&self) -> (Box, Box) { - let (domain, dom_c) = self.create_dom_c.create_domain_dom_c(); - let domain_id = domain.get_domain_id(); - (domain, Box::new(DomCProxy::new(domain_id, dom_c))) - } - - fn recreate_domain_dom_c(&self, dom: Box) -> (Box, Box) { - let (domain, dom_c) = self.create_dom_c.recreate_domain_dom_c(dom); - let domain_id = domain.get_domain_id(); - (domain, Box::new(DomCProxy::new(domain_id, dom_c))) - } -} - -impl interface::domain_creation::CreateDomD for Proxy { - fn create_domain_dom_d(&self, dom_c: Box) -> (Box) { - self.create_dom_d.create_domain_dom_d(dom_c) - } -} - -impl interface::domain_creation::CreateShadow for Proxy { - fn create_domain_shadow( - &self, - create_dom_c: Arc, - ) -> (Box, Box) { - let (domain, shadow) = self.create_shadow.create_domain_shadow(create_dom_c); - let domain_id = domain.get_domain_id(); - (domain, Box::new(DomCProxy::new(domain_id, shadow))) - } -} - -impl interface::domain_creation::CreateBenchnet for Proxy { - fn create_domain_benchnet(&self, net: Box) -> (Box) { - self.create_benchnet.create_domain_benchnet(net) - } -} - -impl interface::domain_creation::CreateBenchnvme for Proxy { - fn create_domain_benchnvme(&self, nvme: Box) -> (Box) { - self.create_benchnvme.create_domain_benchnvme(nvme) - } -} - -struct IxgbeProxy { - domain: Box, - domain_id: u64, -} - -unsafe impl Sync for IxgbeProxy {} -unsafe impl Send for IxgbeProxy {} - -impl IxgbeProxy { - fn new(domain_id: u64, domain: Box) -> Self { - Self { domain, domain_id } - } -} - -//Code to unwind net_submit_and_poll -#[no_mangle] -pub extern "C" fn net_submit_and_poll( - s: &Box, - packets: &mut VecDeque>, - reap_queue: &mut VecDeque>, - tx: bool, -) -> RpcResult> { - //println!("one_arg: x:{}", x); - s.submit_and_poll(packets, reap_queue, tx) -} - -#[no_mangle] -pub extern "C" fn net_submit_and_poll_err( - s: &Box, - packets: &mut VecDeque>, - reap_queue: &mut VecDeque>, - tx: bool, -) -> RpcResult> { - println!("net_submit_and_poll was aborted"); - Err(unsafe { RpcError::panic() }) -} - -#[no_mangle] -pub extern "C" fn net_submit_and_poll_addr() -> u64 { - net_submit_and_poll_err as u64 -} - -extern "C" { - fn net_submit_and_poll_tramp( - s: &Box, - packets: &mut VecDeque>, - reap_queue: &mut VecDeque>, - tx: bool, - ) -> RpcResult>; -} - -trampoline!(net_submit_and_poll); - -//Code to unwind net_poll -#[no_mangle] -pub extern "C" fn net_poll( - s: &Box, - collect: &mut VecDeque>, - tx: bool, -) -> RpcResult> { - s.poll(collect, tx) -} - -#[no_mangle] -pub extern "C" fn net_poll_err( - s: &Box, - collect: &mut VecDeque>, - tx: bool, -) -> RpcResult> { - println!("net_poll was aborted"); - Err(unsafe { RpcError::panic() }) -} - -#[no_mangle] -pub extern "C" fn net_poll_addr() -> u64 { - net_poll_err as u64 -} - -extern "C" { - fn net_poll_tramp( - s: &Box, - collect: &mut VecDeque>, - tx: bool, - ) -> RpcResult>; -} - -trampoline!(net_poll); - -//Code to unwind net_submit_and_poll_rref -#[no_mangle] -pub extern "C" fn net_submit_and_poll_rref( - s: &Box, - packets: RRefDeque<[u8; 1514], 32>, - collect: RRefDeque<[u8; 1514], 32>, - tx: bool, - pkt_len: usize, -) -> RpcResult, RRefDeque<[u8; 1514], 32>)>> { - s.submit_and_poll_rref(packets, collect, tx, pkt_len) -} - -#[no_mangle] -pub extern "C" fn net_submit_and_poll_rref_err( - s: &Box, - packets: RRefDeque<[u8; 1514], 32>, - collect: RRefDeque<[u8; 1514], 32>, - tx: bool, - pkt_len: usize, -) -> RpcResult, RRefDeque<[u8; 1514], 32>)>> { - println!("net_submit_and_poll_rref was aborted"); - Err(unsafe { RpcError::panic() }) -} - -#[no_mangle] -pub extern "C" fn net_submit_and_poll_rref_addr() -> u64 { - net_submit_and_poll_rref_err as u64 -} - -extern "C" { - fn net_submit_and_poll_rref_tramp( - s: &Box, - packets: RRefDeque<[u8; 1514], 32>, - collect: RRefDeque<[u8; 1514], 32>, - tx: bool, - pkt_len: usize, - ) -> RpcResult, RRefDeque<[u8; 1514], 32>)>>; -} - -trampoline!(net_submit_and_poll_rref); - -//Code to unwind poll_rref -#[no_mangle] -pub extern "C" fn net_poll_rref( - s: &Box, - collect: RRefDeque<[u8; 1514], 512>, - tx: bool, -) -> RpcResult)>> { - s.poll_rref(collect, tx) -} - -#[no_mangle] -pub extern "C" fn net_poll_rref_err( - s: &Box, - collect: RRefDeque<[u8; 1514], 512>, - tx: bool, -) -> RpcResult)>> { - println!("net_poll_rref was aborted"); - Err(unsafe { RpcError::panic() }) -} - -#[no_mangle] -pub extern "C" fn net_poll_rref_addr() -> u64 { - net_poll_rref_err as u64 -} - -extern "C" { - fn net_poll_rref_tramp( - s: &Box, - collect: RRefDeque<[u8; 1514], 512>, - tx: bool, - ) -> RpcResult)>>; -} - -trampoline!(net_poll_rref); - -//Code to unwind get_stats -#[no_mangle] -pub extern "C" fn get_stats(s: &Box) -> RpcResult> { - //println!("one_arg: x:{}", x); - s.get_stats() -} - -#[no_mangle] -pub extern "C" fn get_stats_err(s: &Box) -> RpcResult> { - println!("get_stats was aborted"); - Err(unsafe { RpcError::panic() }) -} - -#[no_mangle] -pub extern "C" fn get_stats_addr() -> u64 { - get_stats_err as u64 -} - -extern "C" { - fn get_stats_tramp(s: &Box) -> RpcResult>; -} - -trampoline!(get_stats); - -impl Net for IxgbeProxy { - fn clone_net(&self) -> RpcResult> { - Ok(box Self::new(self.domain_id, self.domain.clone_net()?)) - } - - fn submit_and_poll( - &self, - packets: &mut VecDeque>, - reap_queue: &mut VecDeque>, - tx: bool, - ) -> RpcResult> { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - #[cfg(not(feature = "tramp"))] - let r = self.domain.submit_and_poll(packets, reap_queue, tx); - #[cfg(feature = "tramp")] - let r = unsafe { net_submit_and_poll_tramp(&self.domain, packets, reap_queue, tx) }; - - #[cfg(feature = "tramp")] - unsafe { - sys_discard_cont(); - } - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn poll(&self, collect: &mut VecDeque>, tx: bool) -> RpcResult> { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - #[cfg(not(feature = "tramp"))] - let r = self.domain.poll(collect, tx); - #[cfg(feature = "tramp")] - let r = unsafe { net_poll_tramp(&self.domain, collect, tx) }; - - #[cfg(feature = "tramp")] - unsafe { - sys_discard_cont(); - } - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn submit_and_poll_rref( - &self, - packets: RRefDeque<[u8; 1514], 32>, - collect: RRefDeque<[u8; 1514], 32>, - tx: bool, - pkt_len: usize, - ) -> RpcResult, RRefDeque<[u8; 1514], 32>)>> { - //println!("ixgbe proxy"); - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - packets.move_to(self.domain_id); - collect.move_to(self.domain_id); - - #[cfg(not(feature = "tramp"))] - let r = self - .domain - .submit_and_poll_rref(packets, collect, tx, pkt_len); - #[cfg(feature = "tramp")] - let r = - unsafe { net_submit_and_poll_rref_tramp(&self.domain, packets, collect, tx, pkt_len) }; - - #[cfg(feature = "tramp")] - unsafe { - sys_discard_cont(); - } - - if let Ok(Ok(r)) = r.as_ref() { - r.1.move_to(caller_domain); - r.2.move_to(caller_domain); - } - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn poll_rref( - &self, - collect: RRefDeque<[u8; 1514], 512>, - tx: bool, - ) -> RpcResult)>> { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - collect.move_to(self.domain_id); - - #[cfg(not(feature = "tramp"))] - let r = self.domain.poll_rref(collect, tx); - #[cfg(feature = "tramp")] - let r = unsafe { net_poll_rref_tramp(&self.domain, collect, tx) }; - - #[cfg(feature = "tramp")] - unsafe { - sys_discard_cont(); - } - - if let Ok(Ok(r)) = r.as_ref() { - r.1.move_to(caller_domain); - } - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn get_stats(&self) -> RpcResult> { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - let r = unsafe { get_stats_tramp(&self.domain) }; - - #[cfg(feature = "tramp")] - unsafe { - sys_discard_cont(); - } - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn test_domain_crossing(&self) -> RpcResult<()> { - self.domain.test_domain_crossing() - } -} - -struct DomAProxy { - domain: Box, - domain_id: u64, -} - -unsafe impl Sync for DomAProxy {} -unsafe impl Send for DomAProxy {} - -impl DomAProxy { - fn new(domain_id: u64, domain: Box) -> Self { - Self { domain, domain_id } - } -} - -impl interface::dom_a::DomA for DomAProxy { - fn ping_pong(&self, buffer: RRef<[u8; 1024]>) -> RRef<[u8; 1024]> { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - buffer.move_to(self.domain_id); - let r = self.domain.ping_pong(buffer); - r.move_to(caller_domain); - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn tx_submit_and_poll( - &mut self, - packets: RRefDeque<[u8; 100], 32>, - reap_queue: RRefDeque<[u8; 100], 32>, - ) -> (usize, RRefDeque<[u8; 100], 32>, RRefDeque<[u8; 100], 32>) { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - packets.move_to(self.domain_id); - reap_queue.move_to(self.domain_id); - let r = self.domain.tx_submit_and_poll(packets, reap_queue); - r.1.move_to(caller_domain); - r.2.move_to(caller_domain); - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn test_owned(&self, rref: RRef) -> RRef { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - rref.move_to(self.domain_id); - let r = self.domain.test_owned(rref); - r.move_to(caller_domain); - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } -} - -use interface::dom_c::DomCProxy; - -use interface::rv6::Rv6Proxy; - -use interface::bdev::BDevProxy; - -use interface::bdev::NvmeBDevProxy; -use interface::dom_a::OwnedTest; - - -/* - * Code to unwind usrnet_read_socket - */ - -#[no_mangle] -pub extern "C" fn usrnet_read_socket( - s: &Box, - socket: usize, - buffer: RRefVec, -) -> RpcResult)>> { - //println!("usrnet_read_socket: x:{}", x); - s.read_socket(socket, buffer) -} - -#[no_mangle] -pub extern "C" fn usrnet_read_socket_err( - s: &Box, - socket: usize, - buffer: RRefVec, -) -> RpcResult)>> { - println!("usrnet_read_socket was aborted"); - Err(unsafe { RpcError::panic() }) -} - -#[no_mangle] -pub extern "C" fn usrnet_read_socket_addr() -> u64 { - usrnet_read_socket_err as u64 -} - -extern "C" { - fn usrnet_read_socket_tramp( - s: &Box, - socket: usize, - buffer: RRefVec, - ) -> RpcResult)>>; -} - -trampoline!(usrnet_read_socket); - -/* - * Code to unwind usrnet_write_socket - */ - -#[no_mangle] -pub extern "C" fn usrnet_write_socket( - s: &Box, - socket: usize, - buffer: RRefVec, - size: usize, -) -> RpcResult)>> { - //println!("usrnet_write_socket: x:{}", x); - s.write_socket(socket, buffer, size) -} - -#[no_mangle] -pub extern "C" fn usrnet_write_socket_err( - s: &Box, - socket: usize, - buffer: RRefVec, - size: usize, -) -> RpcResult)>> { - println!("usrnet_write_socket was aborted"); - Err(unsafe { RpcError::panic() }) -} - -#[no_mangle] -pub extern "C" fn usrnet_write_socket_addr() -> u64 { - usrnet_write_socket_err as u64 -} - -extern "C" { - fn usrnet_write_socket_tramp( - s: &Box, - socket: usize, - buffer: RRefVec, - size: usize, - ) -> RpcResult)>>; -} - -trampoline!(usrnet_write_socket); - -// Rv6 proxy -struct UsrNetProxy { - domain: Box, - domain_id: u64, -} - -unsafe impl Sync for UsrNetProxy {} -unsafe impl Send for UsrNetProxy {} - -impl UsrNetProxy { - fn new(domain_id: u64, domain: Box) -> Self { - Self { domain, domain_id } - } -} - -impl UsrNet for UsrNetProxy { - fn clone_usrnet(&self) -> RpcResult> { - Ok(box Self::new(self.domain_id, self.domain.clone_usrnet()?)) - } - - fn create(&self) -> RpcResult> { - self.domain.create() - } - - fn listen(&self, socket: usize, port: u16) -> RpcResult> { - self.domain.listen(socket, port) - } - - fn read_socket( - &self, - socket: usize, - buffer: RRefVec, - ) -> RpcResult)>> { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - buffer.move_to(self.domain_id); - #[cfg(not(feature = "tramp"))] - let r = self.domain.read_socket(socket, buffer); - #[cfg(feature = "tramp")] - let r = unsafe { usrnet_read_socket_tramp(&self.domain, socket, buffer) }; - - #[cfg(feature = "tramp")] - unsafe { - sys_discard_cont(); - } - - if let Ok(Ok(r)) = r.as_ref() { - r.1.move_to(caller_domain); - } - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn write_socket( - &self, - socket: usize, - buffer: RRefVec, - size: usize, - ) -> RpcResult)>> { - // move thread to next domain - let caller_domain = unsafe { sys_update_current_domain_id(self.domain_id) }; - - buffer.move_to(self.domain_id); - #[cfg(not(feature = "tramp"))] - let r = self.domain.write_socket(socket, buffer, size); - #[cfg(feature = "tramp")] - let r = unsafe { usrnet_write_socket_tramp(&self.domain, socket, buffer, size) }; - - #[cfg(feature = "tramp")] - unsafe { - sys_discard_cont(); - } - - if let Ok(Ok(r)) = r.as_ref() { - r.1.move_to(caller_domain); - } - - // move thread back - unsafe { sys_update_current_domain_id(caller_domain) }; - - r - } - - fn poll(&self, tx: bool) -> RpcResult> { - UsrNet::poll(&*self.domain, tx) - } - - fn can_recv(&self, server: usize) -> RpcResult> { - self.domain.can_recv(server) - } - - fn is_listening(&self, server: usize) -> RpcResult> { - self.domain.is_listening(server) - } - - fn is_active(&self, socket: usize) -> RpcResult> { - self.domain.is_active(socket) - } - - fn close(&self, server: usize) -> RpcResult> { - self.domain.close(server) - } -} diff --git a/domains/usr/proxy/src/main.rs b/domains/usr/proxy/src/main.rs index 32f6d1d9..3d62d46a 100644 --- a/domains/usr/proxy/src/main.rs +++ b/domains/usr/proxy/src/main.rs @@ -5,7 +5,6 @@ box_syntax, type_ascription, )] -mod gen; use interface::proxy; @@ -15,7 +14,7 @@ use alloc::boxed::Box; use alloc::sync::Arc; use console::println; use core::panic::PanicInfo; -use interface::domain_creation; +use interface::domain_create; use libsyscalls; use interface::rref; use syscalls; @@ -24,53 +23,47 @@ use syscalls; pub fn trusted_entry( s: Box, heap: Box, - create_pci: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_xv6: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - create_shadow: Arc, + create_pci: alloc::sync::Arc, + create_membdev: alloc::sync::Arc, + create_bdev_shadow: alloc::sync::Arc, + create_virtio_net: alloc::sync::Arc, + create_ixgbe: alloc::sync::Arc, + create_nvme: alloc::sync::Arc, + create_net_shadow: alloc::sync::Arc, + create_nvme_shadow: alloc::sync::Arc, + create_benchnvme: alloc::sync::Arc, + create_xv6fs: alloc::sync::Arc, + create_xv6net: alloc::sync::Arc, + create_xv6net_shadow: alloc::sync::Arc, + create_xv6usr: alloc::sync::Arc, + create_xv6: alloc::sync::Arc, + create_dom_c: alloc::sync::Arc, + create_dom_d: alloc::sync::Arc, + create_shadow: alloc::sync::Arc, + create_tpm: alloc::sync::Arc, ) -> Arc { libsyscalls::syscalls::init(s); interface::rref::init(heap, libsyscalls::syscalls::sys_get_current_domain_id()); - Arc::new(gen::Proxy::new( + Arc::new(interface::proxy::ProxyObject::new( create_pci, - create_ahci, create_membdev, create_bdev_shadow, create_ixgbe, create_virtio_net, - create_nvme, create_net_shadow, create_nvme_shadow, - create_benchnet, - create_benchnvme, + create_nvme, create_xv6fs, create_xv6net, create_xv6net_shadow, create_xv6usr, create_xv6, - create_dom_a, - create_dom_b, create_dom_c, create_dom_d, create_shadow, + create_benchnvme, + create_tpm, )) } diff --git a/domains/usr/shadow/bdev/src/main.rs b/domains/usr/shadow/bdev/src/main.rs index b8e075a9..56e23258 100644 --- a/domains/usr/shadow/bdev/src/main.rs +++ b/domains/usr/shadow/bdev/src/main.rs @@ -14,7 +14,7 @@ use core::panic::PanicInfo; use interface::rref::RRef; -use interface::domain_creation::CreateMemBDev; +use interface::domain_create::CreateMemBDev; use spin::Mutex; use interface::bdev::{BDev, BSIZE}; use interface::rpc::RpcResult; diff --git a/domains/usr/shadow/net/src/main.rs b/domains/usr/shadow/net/src/main.rs index 718b33b8..18e11118 100644 --- a/domains/usr/shadow/net/src/main.rs +++ b/domains/usr/shadow/net/src/main.rs @@ -15,7 +15,7 @@ use console::println; use core::panic::PanicInfo; use alloc::vec::Vec; -use interface::domain_creation::CreateIxgbe; +use interface::domain_create::CreateIxgbe; use interface::rref::RRefDeque; use spin::Mutex; use interface::error::Result; diff --git a/domains/usr/shadow/nvme/src/main.rs b/domains/usr/shadow/nvme/src/main.rs index 98af8a72..d70bdaae 100644 --- a/domains/usr/shadow/nvme/src/main.rs +++ b/domains/usr/shadow/nvme/src/main.rs @@ -16,7 +16,7 @@ use core::panic::PanicInfo; use interface::rref::RRefDeque; -use interface::domain_creation::CreateNvme; +use interface::domain_create::CreateNvme; use spin::Mutex; use interface::bdev::{BlkReq, NvmeBDev}; use interface::error::Result; diff --git a/domains/usr/shadow/xv6net/src/main.rs b/domains/usr/shadow/xv6net/src/main.rs index fd2cdb06..23558f41 100644 --- a/domains/usr/shadow/xv6net/src/main.rs +++ b/domains/usr/shadow/xv6net/src/main.rs @@ -15,7 +15,7 @@ use core::panic::PanicInfo; use interface::rref::RRefVec; -use interface::domain_creation::CreateRv6Net; +use interface::domain_create::CreateRv6Net; use spin::Mutex; use interface::error::Result; use interface::net::Net; diff --git a/domains/usr/test/dom_a/Cargo.lock b/domains/usr/test/dom_a/Cargo.lock deleted file mode 100644 index 29997dac..00000000 --- a/domains/usr/test/dom_a/Cargo.lock +++ /dev/null @@ -1,338 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "ahash" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f33b5018f120946c1dcf279194f238a9f146725593ead1c08fa47ff22b0b5d3" -dependencies = [ - "const-random", -] - -[[package]] -name = "ahci" -version = "0.1.0" - -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - -[[package]] -name = "autocfg" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" - -[[package]] -name = "bitfield" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "byteorder" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "console" -version = "0.1.0" -dependencies = [ - "libsyscalls", - "spin 0.5.3", -] - -[[package]] -name = "const-random" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f1af9ac737b2dd2d577701e59fd09ba34822f6f2ebdb30a7647405d9e55e16a" -dependencies = [ - "const-random-macro", - "proc-macro-hack", -] - -[[package]] -name = "const-random-macro" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25e4c606eb459dd29f7c57b2e0879f2b6f14ee130918c2b78ccb58a9624e6c7a" -dependencies = [ - "getrandom", - "proc-macro-hack", -] - -[[package]] -name = "create" -version = "0.1.0" -dependencies = [ - "syscalls", - "usr", -] - -[[package]] -name = "dom_a" -version = "0.1.0" -dependencies = [ - "console", - "create", - "lazy_static", - "libsyscalls", - "libtime", - "malloc", - "num-traits", - "proxy", - "rref", - "spin 0.5.3", - "syscalls", - "tls", - "usr", -] - -[[package]] -name = "getrandom" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e6073d0ca812575946eb5f35ff68dbe519907b25c42530389ff946dc84c6ead" -dependencies = [ - "ahash", - "autocfg 0.1.7", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] - -[[package]] -name = "libc" -version = "0.2.76" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" - -[[package]] -name = "libsyscalls" -version = "0.1.0" -dependencies = [ - "pc-keyboard", - "platform", - "spin 0.5.3", - "syscalls", -] - -[[package]] -name = "libtime" -version = "0.1.0" -dependencies = [ - "console", - "libsyscalls", -] - -[[package]] -name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "malloc" -version = "0.1.0" -dependencies = [ - "libsyscalls", - "slabmalloc", - "spin 0.5.3", -] - -[[package]] -name = "num-derive" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c8b15b261814f992e33760b1fca9fe8b693d8a65299f20c9901688636cfb746" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "num-traits" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" -dependencies = [ - "autocfg 1.0.0", -] - -[[package]] -name = "pc-keyboard" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff50ab09ba31bcebc0669f4e64c0952fae1acdca9e6e0587e68e4e8443808ac" - -[[package]] -name = "pci_driver" -version = "0.1.0" -dependencies = [ - "ahci", - "platform", -] - -[[package]] -name = "platform" -version = "0.1.0" - -[[package]] -name = "proc-macro-hack" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" - -[[package]] -name = "proc-macro2" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "protocol" -version = "0.1.0" -dependencies = [ - "bitfield", -] - -[[package]] -name = "proxy" -version = "0.1.0" -dependencies = [ - "create", - "syscalls", - "usr", -] - -[[package]] -name = "quote" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rref" -version = "0.1.0" -dependencies = [ - "console", - "libsyscalls", - "spin 0.5.3", - "syscalls", -] - -[[package]] -name = "slabmalloc" -version = "0.7.0" -dependencies = [ - "log", -] - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "spin" -version = "0.5.3" - -[[package]] -name = "syn" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "syscalls" -version = "0.1.0" -dependencies = [ - "pc-keyboard", - "platform", - "protocol", - "spin 0.5.3", -] - -[[package]] -name = "tls" -version = "0.1.0" -dependencies = [ - "hashbrown", - "lazy_static", - "libsyscalls", - "spin 0.5.3", -] - -[[package]] -name = "unicode-xid" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" - -[[package]] -name = "usr" -version = "0.1.0" -dependencies = [ - "bitflags", - "byteorder", - "num-derive", - "num-traits", - "pci_driver", - "rref", - "syscalls", -] - -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" diff --git a/domains/usr/test/dom_a/Cargo.toml b/domains/usr/test/dom_a/Cargo.toml deleted file mode 100644 index 8fb07f05..00000000 --- a/domains/usr/test/dom_a/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "dom_a" -version = "0.1.0" -authors = ["RedLeaf Team"] -edition = "2018" - -[dependencies] -syscalls = { path = "../../../../lib/core/interfaces/syscalls" } -interface = { path = "../../../../interface/generated" } -libsyscalls = { path = "../../../../lib/core/libsyscalls" } -libtime = { path = "../../../../lib/core/libtime" } -console = { path = "../../../../lib/core/console" } -malloc = { path = "../../../../lib/core/malloc" } -tls = { path = "../../../../lib/core/tls" } -spin = { path = "../../../../lib/core/spin-rs" } - -[dependencies.lazy_static] -version = "1.3.0" -features = ["spin_no_std"] - -[dependencies.num-traits] -version = "0.2.8" -default-features = false diff --git a/domains/usr/test/dom_a/src/main.rs b/domains/usr/test/dom_a/src/main.rs deleted file mode 100644 index 444779e9..00000000 --- a/domains/usr/test/dom_a/src/main.rs +++ /dev/null @@ -1,112 +0,0 @@ -#![no_std] -#![no_main] -extern crate alloc; -extern crate malloc; - -use alloc::boxed::Box; -use console::println; -use core::panic::PanicInfo; -use syscalls::{Heap, Syscall}; - -use libtime::get_rdtsc as rdtsc; -use interface::rref::{RRef, RRefDeque}; -use tls::ThreadLocal; -#[macro_use] -use lazy_static::lazy_static; - -struct DomA {} - -impl DomA { - fn new() -> Self { - Self {} - } -} - -use interface::dom_a::OwnedTest; - -impl interface::dom_a::DomA for DomA { - fn ping_pong(&self, mut buffer: RRef<[u8; 1024]>) -> RRef<[u8; 1024]> { - println!("[dom_a]: ping pong"); - for i in 0..buffer.len() { - buffer[i] *= 2_u8; - } - buffer - } - - fn tx_submit_and_poll( - &mut self, - mut packets: RRefDeque<[u8; 100], 32>, - mut reap_queue: RRefDeque<[u8; 100], 32>, - ) -> (usize, RRefDeque<[u8; 100], 32>, RRefDeque<[u8; 100], 32>) { - let mut read = 0; - - while let Some(buf) = packets.pop_front() { - reap_queue.push_back(buf); - read += 1; - } - - (read, packets, reap_queue) - } - - fn test_owned(&self, mut rref: RRef) -> RRef { - match rref.owned.take() { - None => rref, - Some(mut inner) => { - *inner += 1; - rref.owned.replace(inner); - rref - } - } - } -} - -lazy_static! { - pub static ref COUNTER: ThreadLocal = ThreadLocal::new(|| 0usize); -} - -fn bench_tls() { - let ops = 10_000_000; - - let start = rdtsc(); - for _ in 0..ops { - COUNTER.with(|counter| { - *counter += 1; - }); - } - let end = rdtsc(); - println!( - "ops: {}, delta: {}, delta/ops: {}", - ops, - end - start, - (end - start) / ops - ); -} - -#[no_mangle] -pub fn trusted_entry( - s: Box, - heap: Box, -) -> Box { - libsyscalls::syscalls::init(s); - interface::rref::init(heap, libsyscalls::syscalls::sys_get_current_domain_id()); - - println!( - "In domain A, id: {}", - libsyscalls::syscalls::sys_get_current_domain_id() - ); - - println!("Bench tls"); - for _ in 0..10 { - bench_tls(); - } - - Box::new(DomA::new()) -} - -// This function is called on panic. -#[panic_handler] -fn panic(info: &PanicInfo) -> ! { - println!("domain A panic: {:?}", info); - libsyscalls::syscalls::sys_backtrace(); - loop {} -} diff --git a/domains/usr/test/dom_b/Cargo.lock b/domains/usr/test/dom_b/Cargo.lock deleted file mode 100644 index f839cef2..00000000 --- a/domains/usr/test/dom_b/Cargo.lock +++ /dev/null @@ -1,253 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "ahci" -version = "0.1.0" - -[[package]] -name = "autocfg" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" - -[[package]] -name = "bitfield" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "byteorder" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "console" -version = "0.1.0" -dependencies = [ - "libsyscalls", - "spin 0.5.3", -] - -[[package]] -name = "create" -version = "0.1.0" -dependencies = [ - "syscalls", - "usr", -] - -[[package]] -name = "dom_b" -version = "0.1.0" -dependencies = [ - "console", - "create", - "lazy_static", - "libsyscalls", - "libtime", - "malloc", - "num-traits", - "proxy", - "rref", - "spin 0.5.3", - "syscalls", - "usr", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] - -[[package]] -name = "libsyscalls" -version = "0.1.0" -dependencies = [ - "pc-keyboard", - "platform", - "spin 0.5.3", - "syscalls", -] - -[[package]] -name = "libtime" -version = "0.1.0" -dependencies = [ - "console", - "libsyscalls", -] - -[[package]] -name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "malloc" -version = "0.1.0" -dependencies = [ - "libsyscalls", - "slabmalloc", - "spin 0.5.3", -] - -[[package]] -name = "num-derive" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c8b15b261814f992e33760b1fca9fe8b693d8a65299f20c9901688636cfb746" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "num-traits" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" -dependencies = [ - "autocfg", -] - -[[package]] -name = "pc-keyboard" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff50ab09ba31bcebc0669f4e64c0952fae1acdca9e6e0587e68e4e8443808ac" - -[[package]] -name = "pci_driver" -version = "0.1.0" -dependencies = [ - "ahci", - "platform", -] - -[[package]] -name = "platform" -version = "0.1.0" - -[[package]] -name = "proc-macro2" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "protocol" -version = "0.1.0" -dependencies = [ - "bitfield", -] - -[[package]] -name = "proxy" -version = "0.1.0" -dependencies = [ - "create", - "syscalls", - "usr", -] - -[[package]] -name = "quote" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rref" -version = "0.1.0" -dependencies = [ - "console", - "libsyscalls", - "spin 0.5.3", - "syscalls", -] - -[[package]] -name = "slabmalloc" -version = "0.7.0" -dependencies = [ - "log", -] - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "spin" -version = "0.5.3" - -[[package]] -name = "syn" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "syscalls" -version = "0.1.0" -dependencies = [ - "pc-keyboard", - "platform", - "protocol", - "spin 0.5.3", -] - -[[package]] -name = "unicode-xid" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" - -[[package]] -name = "usr" -version = "0.1.0" -dependencies = [ - "bitflags", - "byteorder", - "num-derive", - "num-traits", - "pci_driver", - "rref", - "syscalls", -] diff --git a/domains/usr/test/dom_b/Cargo.toml b/domains/usr/test/dom_b/Cargo.toml deleted file mode 100644 index b098fcec..00000000 --- a/domains/usr/test/dom_b/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "dom_b" -version = "0.1.0" -authors = ["RedLeaf Team"] -edition = "2018" - -[dependencies] -syscalls = { path = "../../../../lib/core/interfaces/syscalls" } -interface = { path = "../../../../interface/generated" } -libsyscalls = { path = "../../../../lib/core/libsyscalls" } -libtime = { path = "../../../../lib/core/libtime" } -console = { path = "../../../../lib/core/console" } -malloc = { path = "../../../../lib/core/malloc" } -spin = { path = "../../../../lib/core/spin-rs" } - -[dependencies.lazy_static] -version = "1.3.0" -features = ["spin_no_std"] - -[dependencies.num-traits] -version = "0.2.8" -default-features = false diff --git a/domains/usr/test/dom_b/src/main.rs b/domains/usr/test/dom_b/src/main.rs deleted file mode 100644 index 1c49ae7d..00000000 --- a/domains/usr/test/dom_b/src/main.rs +++ /dev/null @@ -1,118 +0,0 @@ -#![no_std] -#![no_main] -extern crate alloc; -extern crate malloc; -use syscalls::{Heap, Syscall}; - -use alloc::boxed::Box; - -use console::println; - -use core::panic::PanicInfo; -use libtime::get_rdtsc as rdtsc; -use interface::rref::{RRef, RRefDeque, Owned}; -use interface::dom_a::{DomA, OwnedTest}; -use core::ops::Deref; - -fn test_submit_and_poll(dom_a: &mut Box) { - let mut packets = RRefDeque::<[u8; 100], 32>::default(); - let reap_queue = RRefDeque::<[u8; 100], 32>::default(); - for i in 0..32 { - packets.push_back(RRef::<[u8; 100]>::new([i; 100])); - } - - let ops = 10_000_000; - - let start = rdtsc(); - let mut packets = Some(packets); - let mut reap_queue = Some(reap_queue); - for _i in 0..ops { - // need options as a workaround to destructured assignment - // https://github.com/rust-lang/rfcs/issues/372 - let (_num, packets_, reap_queue_) = - dom_a.tx_submit_and_poll(packets.take().unwrap(), reap_queue.take().unwrap()); - - packets.replace(reap_queue_); - reap_queue.replace(packets_); - } - let end = rdtsc(); - println!( - "ops: {}, delta: {}, delta/ops: {}", - ops, - end - start, - (end - start) / ops - ); - - // let mut packets = packets.take().unwrap(); - // let mut reap_queue = reap_queue.take().unwrap(); - // for i in 0..32 { - // if let Some(rref) = packets.pop_front() { - // drop(rref); - // } - // if let Some(rref) = reap_queue.pop_front() { - // drop(rref); - // } - // } -} - -#[no_mangle] -pub fn trusted_entry( - s: Box, - heap: Box, - dom_a: Box, -) { - libsyscalls::syscalls::init(s); - interface::rref::init(heap, libsyscalls::syscalls::sys_get_current_domain_id()); - - println!( - "In domain B, id: {}", - libsyscalls::syscalls::sys_get_current_domain_id() - ); - - // { - // println!("rref drop test"); - // let rref1 = RRef::new(10usize); - // let rref2 = RRef::new(rref1); // RRef> - // println!("dropping rref2, should print drop_t::RRef> then drop_t::RRef"); - // drop(rref2); - // } - - { - println!("RRef::Owned test"); - let mut outer = RRef::new(OwnedTest { - owned: Owned::new(RRef::new(0)) - }); - outer = dom_a.test_owned(outer); - assert_eq!(outer.owned.take().as_deref().unwrap(), &1); - } - - let mut dom_a = dom_a; - test_submit_and_poll(&mut dom_a); - /* - let mut buffer = RRef::<[u8; 1024]>::new([0;1024]); - for i in 0..1024 { - buffer[i] = (i % 256) as u8; - } - println!("before pingpong"); - println!("---------------"); - for i in 0..1024 { - println!("buffer[{}]: {}", i, buffer[i]); - } - println!("---------------"); - buffer = dom_a.ping_pong(buffer); - println!("after pingpong"); - println!("---------------"); - for i in 0..1024 { - println!("buffer[{}]: {}", i, buffer[i]); - } - println!("---------------"); - */ -} - -// This function is called on panic. -#[panic_handler] -fn panic(info: &PanicInfo) -> ! { - println!("domain B panic: {:?}", info); - libsyscalls::syscalls::sys_backtrace(); - loop {} -} diff --git a/domains/usr/test/shadow/src/main.rs b/domains/usr/test/shadow/src/main.rs index 999f0a3c..93b8dd76 100644 --- a/domains/usr/test/shadow/src/main.rs +++ b/domains/usr/test/shadow/src/main.rs @@ -19,13 +19,13 @@ use interface::rpc::RpcResult; struct ShadowDomain { dom: Option>, dom_c: Box, - create_dom_c: Arc, + create_dom_c: Arc, } impl ShadowDomain { fn new( dom: Box, - create_dom_c: Arc, + create_dom_c: Arc, dom_c: Box, ) -> Self { Self { @@ -43,7 +43,7 @@ struct Shadow { impl Shadow { fn new( dom: Box, - create_dom_c: Arc, + create_dom_c: Arc, dom_c: Box, ) -> Self { Self { @@ -85,7 +85,7 @@ impl interface::dom_c::DomC for Shadow { pub fn trusted_entry( s: Box, heap: Box, - create_dom_c: Arc, + create_dom_c: Arc, ) -> Box { libsyscalls::syscalls::init(s); interface::rref::init(heap, libsyscalls::syscalls::sys_get_current_domain_id()); diff --git a/domains/usr/xv6/kernel/core/src/main.rs b/domains/usr/xv6/kernel/core/src/main.rs index 4462ec68..12bda07c 100644 --- a/domains/usr/xv6/kernel/core/src/main.rs +++ b/domains/usr/xv6/kernel/core/src/main.rs @@ -15,7 +15,7 @@ use core::panic::PanicInfo; use console::println; -use interface::domain_creation; +use interface::domain_create; use syscalls::{Heap, Syscall}; use interface::bdev::BDev; @@ -27,10 +27,10 @@ pub fn trusted_entry( s: Box, heap: Box, ints: Box, - create_xv6fs: Arc, - create_xv6net: Arc, - _create_xv6net_shadow: Arc, - create_xv6usr: Arc, + create_xv6fs: Arc, + create_xv6net: Arc, + _create_xv6net_shadow: Arc, + create_xv6usr: Arc, bdev: Box, net: Box, nvme: Box, @@ -51,7 +51,7 @@ pub fn trusted_entry( #[cfg(not(feature = "shadow"))] let (_dom_xv6net, usrnet) = create_xv6net.create_domain_xv6net(net.clone_net().unwrap()); // Init kernel - box rv6_syscalls::Rv6Syscalls::new(create_xv6usr, fs.clone(), usrnet, net, nvme, usr_tpm) + box rv6_syscalls::Rv6Syscalls::new(create_xv6usr, fs, usrnet, net, nvme, usr_tpm) } // This function is called on panic. diff --git a/domains/usr/xv6/kernel/core/src/rv6_syscalls.rs b/domains/usr/xv6/kernel/core/src/rv6_syscalls.rs index 486b0b91..45d92a69 100644 --- a/domains/usr/xv6/kernel/core/src/rv6_syscalls.rs +++ b/domains/usr/xv6/kernel/core/src/rv6_syscalls.rs @@ -7,7 +7,7 @@ use alloc::vec::Vec; use spin::Mutex; use console::println; -use interface::domain_creation::CreateRv6Usr; +use interface::domain_create::CreateRv6Usr; use interface::rref::{RRefDeque, RRefVec}; use interface::bdev::{BlkReq, NvmeBDev}; use interface::net::{Net, NetworkStats}; @@ -51,11 +51,11 @@ impl Rv6Syscalls { Ok(Self { start_time: self.start_time, create_xv6usr: self.create_xv6usr.clone(), - fs: self.fs.clone(), + fs: self.fs.clone()?, usrnet: self.usrnet.clone_usrnet()?, net: self.net.clone_net()?, nvme: self.nvme.clone(), - usrtpm: self.usrtpm.clone_usrtpm(), + usrtpm: self.usrtpm.clone_usrtpm()?, }) } } @@ -78,7 +78,7 @@ impl Rv6 for Rv6Syscalls { } fn get_usrtpm(&self) -> RpcResult> { - Ok(self.usrtpm.clone_usrtpm()) + self.usrtpm.clone_usrtpm() } fn as_net(&self) -> RpcResult> { @@ -96,7 +96,7 @@ impl Rv6 for Rv6Syscalls { ) -> RpcResult>> { Ok((|| { let name = core::str::from_utf8(name.as_slice())?; - Ok(crate::thread::spawn_thread(self.fs.clone(), &name, func)) + Ok(crate::thread::spawn_thread(self.fs.clone().unwrap(), &name, func)) })()) } @@ -123,9 +123,9 @@ impl Rv6 for Rv6Syscalls { // Create a seperate copy of all the objects we want to pass to the new thread // and transfer the ownership over - let fs_copy = self.fs.clone(); + let fs_copy = self.fs.clone()?; let create_copy = self.create_xv6usr.clone(); - let tmp_storage_id = fs_copy.sys_save_threadlocal(fds)?; + let tmp_storage_id = fs_copy.sys_save_threadlocal(fds)??; Ok(self .sys_spawn_thread( path, @@ -133,8 +133,8 @@ impl Rv6 for Rv6Syscalls { fs_copy.sys_set_threadlocal(tmp_storage_id).unwrap(); create_copy.create_domain_xv6usr( &path_copy, - rv6, blob.as_slice(), + rv6, &args_copy, ); }), diff --git a/domains/usr/xv6/kernel/fs/src/main.rs b/domains/usr/xv6/kernel/fs/src/main.rs index 86ea53a1..c45949d9 100644 --- a/domains/usr/xv6/kernel/fs/src/main.rs +++ b/domains/usr/xv6/kernel/fs/src/main.rs @@ -52,24 +52,22 @@ impl Rv6FS { } impl VFS for Rv6FS { - fn clone(&self) -> Box { - box Self {} + fn clone(&self) -> RpcResult> { + Ok(box Self {}) } -} -impl KernelVFS for Rv6FS { - fn sys_save_threadlocal(&self, fds: [Option; NFILE]) -> Result { - sysfile::sys_save_threadlocal(fds) + // KernelVFS part + fn sys_save_threadlocal(&self, fds: [Option; NFILE]) -> RpcResult> { + Ok(sysfile::sys_save_threadlocal(fds)) } - fn sys_set_threadlocal(&self, id: usize) -> Result<()> { - sysfile::sys_set_threadlocal(id) + fn sys_set_threadlocal(&self, id: usize) -> RpcResult> { + Ok(sysfile::sys_set_threadlocal(id)) } - fn sys_thread_exit(&self) { - sysfile::sys_thread_exit() + fn sys_thread_exit(&self) -> RpcResult<()> { + Ok(sysfile::sys_thread_exit()) } -} -impl UsrVFS for Rv6FS { + // UsrVFS part fn sys_open( &self, path: RRefVec, diff --git a/interface/Makefile b/interface/Makefile index 598e4fb2..94b84bf0 100644 --- a/interface/Makefile +++ b/interface/Makefile @@ -3,6 +3,7 @@ OUTPUT_DIR = generated LIB_RS = $(OUTPUT_DIR)/src/lib.rs MANIFEST_PATH = $(OUTPUT_DIR)/Cargo.toml NGC = RUST_LOG=INFO RUST_BACKTRACE=1 cargo run --manifest-path $(ROOT)/tools/redIDL/codegen/ngc/Cargo.toml --release +DOMAIN_CREATE_OUTPUT_PATH = ../kernel/src/generated_domain_create.rs .PHONY: all all: $(LIB_RS) $(MANIFEST_PATH) @@ -22,11 +23,12 @@ $(OUTPUT_DIR)/merged.rs: # Inject use statements $(LIB_RS): $(OUTPUT_DIR)/merged.rs mkdir -p $(OUTPUT_DIR)/src - $(NGC) $< $@ + $(NGC) $< $@ --domain_create_output=$(DOMAIN_CREATE_OUTPUT_PATH) .PHONY: clean clean: -rm -rf $(OUTPUT_DIR) + -rm -f $(DOMAIN_CREATE_OUTPUT_PATH) diff --git a/interface/README.md b/interface/README.md new file mode 100644 index 00000000..d91d89e4 --- /dev/null +++ b/interface/README.md @@ -0,0 +1,36 @@ +# RPC Types +1. Types that implements `core::marker::Copy` trait beside function pointers + +# Interface syntax. +## RPC +See [RPC Types](#rpc_types) for valid RPC Types. +``` +#[interface] +pub trait YourInterface { + fn method_name(&self, [arg: RPCType],*) -> RpcResult; + ... more methods ... +} +``` + + +# How to add a new domain. +1. Add a domain create interface inside of the `domain_create` module. + ``` + #[domain_create(path = "my_domain_name")] + pub trait CreateYourDomain: Send + Sync { + fn create_domain_your_domain(&self) -> (Box, Box); + } + ``` +1. Add it inside of `interface::proxy::Proxy` as a method of the proxy. + ``` + fn as_domain_create_CreateDomC1(&self) -> Arc; + ``` +1. Update the proxy object instantiation in _domains/usr/proxy/src/main.rs:trusted\_entry_ so the + proxy will contain an instance of `CreateYourDomain`. +1. Update the proxy domain entry point in both `interface::domain_create::CreateProxy` and + _domains/usr/proxy/src/main.rs:trusted\_entry_ to allow the instance of `CreateYourDomain` be + passed down from domain `redleaf_init` to domain `proxy`. +1. Update the entry point and the instantiation of the proxy domain of `redleaf_init` in + _domains/sys/init/src/main.rs:trusted\_entry_. Make sure the signature of the entry point is + the same as the one _kernel/src/generated\_domain\_create.rs:create\_domain\_init_ + diff --git a/interface/missing_dependencies.toml b/interface/missing_dependencies.toml index 1e5e7d8a..3bd0a18f 100644 --- a/interface/missing_dependencies.toml +++ b/interface/missing_dependencies.toml @@ -8,4 +8,5 @@ path = "../../lib/core/libsyscalls" [features] trampoline = [] proxy = [] +proxy-log-error = [] # --- Auto generated end --- \ No newline at end of file diff --git a/interface/src/dom_a.rs b/interface/src/dom_a.rs deleted file mode 100644 index 9c1dc002..00000000 --- a/interface/src/dom_a.rs +++ /dev/null @@ -1,19 +0,0 @@ -/// RedLeaf block device interface -use alloc::boxed::Box; -use crate::rref::{RRef, RRefDeque, Owned}; - -pub struct OwnedTest { - pub owned: Owned, -} - -pub trait DomA { - fn ping_pong(&self, buffer: RRef<[u8; 1024]>) -> RRef<[u8; 1024]>; - fn tx_submit_and_poll(&mut self, - packets: RRefDeque<[u8; 100], 32>, - reap_queue: RRefDeque<[u8; 100], 32>) -> ( - usize, - RRefDeque<[u8; 100], 32>, - RRefDeque<[u8; 100], 32> - ); - fn test_owned(&self, rref: RRef) -> RRef; -} diff --git a/interface/src/domain_creation.rs b/interface/src/domain_create.rs similarity index 55% rename from interface/src/domain_creation.rs rename to interface/src/domain_create.rs index d965cc33..ba50646a 100644 --- a/interface/src/domain_creation.rs +++ b/interface/src/domain_create.rs @@ -1,111 +1,152 @@ +/// Domain create related interfaces + + use alloc::boxed::Box; use alloc::sync::Arc; use syscalls::{Heap, Domain, Interrupt}; -use crate::{bdev::{BDev, NvmeBDev}, vfs::VFS, usrnet::UsrNet, rv6::Rv6, dom_a::DomA, dom_c::DomC, net::Net, pci::{PCI, PciBar, PciResource}}; +use crate::{bdev::{BDev, NvmeBDev}, vfs::VFS, usrnet::UsrNet, rv6::Rv6, dom_c::DomC, net::Net, pci::{PCI, PciBar, PciResource}}; use crate::error::Result; +use crate::tpm::UsrTpm; + +#[domain_create(path = "dom_proxy")] +pub trait CreateProxy { + fn create_domain_proxy( + &self, + create_pci: Arc, + create_membdev: Arc, + create_bdev_shadow: Arc, + create_ixgbe: Arc, + create_virtio_net: Arc, + create_nvme: Arc, + create_net_shadow: Arc, + create_nvme_shadow: Arc, + create_benchnvme: Arc, + create_xv6fs: Arc, + create_xv6net: Arc, + create_xv6net_shadow: Arc, + create_xv6usr: Arc, + create_xv6: Arc, + create_dom_c: Arc, + create_dom_d: Arc, + create_shadow: Arc, + create_tpm: Arc) -> (Box, Arc); +} /* AB: XXX: first thing: change all names to create_domain -- it's absurd */ +#[domain_create(path = "pci")] pub trait CreatePCI: Send + Sync { fn create_domain_pci(&self) -> (Box, Box); } +// #[domain_create(path = "ahci")] pub trait CreateAHCI: Send + Sync { fn create_domain_ahci(&self, pci: Box) -> (Box, Box); } +#[domain_create(path = "membdev")] pub trait CreateMemBDev: Send + Sync { fn create_domain_membdev(&self, memdisk: &'static mut [u8]) -> (Box, Box); fn recreate_domain_membdev(&self, dom: Box, memdisk: &'static mut [u8]) -> (Box, Box); } +#[domain_create(path = "bdev_shadow")] pub trait CreateBDevShadow: Send + Sync { fn create_domain_bdev_shadow(&self, create: Arc) -> (Box, Box); } +#[domain_create(path = "ixgbe")] pub trait CreateIxgbe: Send + Sync { fn create_domain_ixgbe(&self, pci: Box) -> (Box, Box); } +#[domain_create(path = "virtio_net")] pub trait CreateVirtioNet: Send + Sync { fn create_domain_virtio_net(&self, pci: Box) -> (Box, Box); } +#[domain_create(path = "net_shadow")] pub trait CreateNetShadow: Send + Sync { fn create_domain_net_shadow(&self, create: Arc, pci: Box) -> (Box, Box); } +#[domain_create(path = "nvme_shadow")] pub trait CreateNvmeShadow: Send + Sync { fn create_domain_nvme_shadow(&self, create: Arc, pci: Box) -> (Box, Box); } +#[domain_create(path = "nvme")] pub trait CreateNvme: Send + Sync { - fn create_domain_nvme(&self, pci: Box) -> (Box, Box); + fn create_domain_nvme(&self, pci: Box) -> (Box, Box); } +#[domain_create(path = "xv6fs")] pub trait CreateRv6FS: Send + Sync { fn create_domain_xv6fs(&self, bdev: Box) ->(Box, Box); } +#[domain_create(path = "xv6net")] pub trait CreateRv6Net: Send + Sync { fn create_domain_xv6net(&self, net: Box) ->(Box, Box); } +#[domain_create(path = "xv6net_shadow")] pub trait CreateRv6NetShadow: Send + Sync { fn create_domain_xv6net_shadow(&self, create: Arc, net: Box) ->(Box, Box); } +#[domain_create_blob(path = "xv6_user")] pub trait CreateRv6Usr: Send + Sync { - fn create_domain_xv6usr(&self, name: &str, xv6: Box, blob: &[u8], args: &str) -> Result>; + fn create_domain_xv6usr(&self, name: &str, blob: &[u8], xv6: Box, args: &str) -> (Box, ()); } pub type CreateRv6UsrPtr = Box; +#[domain_create(path = "xv6kernel")] pub trait CreateRv6: Send + Sync { fn create_domain_xv6kernel(&self, ints: Box, create_xv6fs: Arc, create_xv6net: Arc, create_xv6net_shadow: Arc, - create_xv6usr: Arc, + create_xv6usr: Arc, bdev: Box, - net: Box, - nvme: Box, - usr_tpm: Box, + net: Box, + nvme: Box, + usr_tpm: Box, ) -> (Box, Box); } -pub trait CreateDomA: Send + Sync { - fn create_domain_dom_a(&self) -> (Box, Box); -} - -pub trait CreateDomB: Send + Sync { - fn create_domain_dom_b(&self, dom_a: Box) -> Box; -} - +#[domain_create(path = "dom_c")] pub trait CreateDomC: Send + Sync { fn create_domain_dom_c(&self) -> (Box, Box); fn recreate_domain_dom_c(&self, dom: Box) -> (Box, Box); } +#[domain_create(path = "dom_d")] pub trait CreateDomD: Send + Sync { - fn create_domain_dom_d(&self, dom_c: Box) -> Box; + fn create_domain_dom_d(&self, dom_c: Box) -> (Box, ()); } +#[domain_create(path = "shadow")] pub trait CreateShadow: Send + Sync { fn create_domain_shadow(&self, create_dom_c: Arc) -> (Box, Box); } +// #[domain_create(path = "benchnet")] pub trait CreateBenchnet: Send + Sync { - fn create_domain_benchnet(&self, net: Box) -> Box; + fn create_domain_benchnet(&self, net: Box) -> (Box, ()); } +#[domain_create(path = "benchnvme")] pub trait CreateBenchnvme: Send + Sync { - fn create_domain_benchnvme(&self, nvme: Box) -> Box; + fn create_domain_benchnvme(&self, nvme: Box) -> (Box, ()); } +// #[domain_create(path = "sashstore")] pub trait CreateHashStore: Send + Sync { - fn create_domain_hashstore(&self) -> Box; + fn create_domain_hashstore(&self) -> (Box, ()); } +#[domain_create(path = "tpm")] pub trait CreateTpm: Send + Sync { - fn create_domain_tpm(&self) -> (Box, Box); + fn create_domain_tpm(&self) -> (Box, Box); } diff --git a/interface/src/error.rs b/interface/src/error.rs index 4a19789b..1a603183 100644 --- a/interface/src/error.rs +++ b/interface/src/error.rs @@ -148,6 +148,10 @@ pub enum ErrorKind { Utf8Error, /// One or more parameter is invalid InvalidParameter, + /// Failed to find Pci class/subclass. + InvalidPciClass, + /// Failed to find Pci device/vendor ID. + InvalidPciDeviceID, } // impl ErrorKind { diff --git a/interface/src/lib.rs b/interface/src/lib.rs index fa2efe61..898618b3 100644 --- a/interface/src/lib.rs +++ b/interface/src/lib.rs @@ -21,7 +21,6 @@ extern crate num_derive; extern crate bitflags; pub mod bdev; -pub mod dom_a; pub mod dom_c; pub mod error; pub mod net; @@ -36,4 +35,4 @@ pub mod typeid; pub mod proxy; -pub mod domain_creation; +pub mod domain_create; diff --git a/interface/src/pci.rs b/interface/src/pci.rs index c5239887..69f0a3f7 100644 --- a/interface/src/pci.rs +++ b/interface/src/pci.rs @@ -2,12 +2,15 @@ use alloc::boxed::Box; use crate::rref::{RRef, RRefDeque}; use pci_driver::{PciDriver, PciClass, BarRegions, PciDrivers}; +use crate::error::Result; +use crate::rpc::RpcResult; +#[interface] pub trait PCI: Send { - fn pci_register_driver(&self, pci_driver: &mut dyn pci_driver::PciDriver, bar_index: usize, class: Option<(PciClass, u8)>) -> Result<(), ()>; + fn pci_register_driver(&self, pci_driver: &mut dyn pci_driver::PciDriver, bar_index: usize, class: Option<(PciClass, u8)>) -> RpcResult>; /// Boxed trait objects cannot be cloned trivially! /// https://users.rust-lang.org/t/solved-is-it-possible-to-clone-a-boxed-trait-object/1714/6 - fn pci_clone(&self) -> Box; + fn pci_clone(&self) -> RpcResult>; } pub trait PciResource { diff --git a/interface/src/proxy.rs b/interface/src/proxy.rs index 7f715e77..08ccb203 100644 --- a/interface/src/proxy.rs +++ b/interface/src/proxy.rs @@ -1,8 +1,8 @@ use alloc::boxed::Box; use alloc::sync::Arc; use syscalls::{Domain}; -use crate::{bdev, domain_creation::CreateVirtioNet}; -use crate::domain_creation::{CreatePCI, +use crate::{bdev}; +use crate::domain_create::{CreatePCI, CreateAHCI, CreateMemBDev, CreateBDevShadow, @@ -16,77 +16,52 @@ use crate::domain_creation::{CreatePCI, CreateRv6Net, CreateRv6NetShadow, CreateRv6Usr, - CreateRv6, - CreateDomA, - CreateDomB, + CreateRv6, CreateDomC, CreateDomD, - CreateShadow + CreateShadow, + CreateVirtioNet, }; -pub trait CreateProxy { - fn create_domain_proxy( - &self, - create_pci: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_xv6: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - create_shadow: Arc) -> (Box, Arc); -} - pub trait Proxy: CreatePCI + - CreateAHCI + CreateMemBDev + - CreateBDevShadow + CreateIxgbe + CreateNetShadow + CreateNvmeShadow + - CreateBenchnet + CreateBenchnvme + CreateRv6FS + CreateRv6Usr + CreateRv6 + - CreateDomA + - CreateDomB + CreateDomC + CreateDomD + CreateShadow { // necessary because rust doesn't support trait object upcasting - fn as_create_pci(&self) -> Arc; - fn as_create_ahci(&self) -> Arc; - fn as_create_membdev(&self) -> Arc; - fn as_create_bdev_shadow(&self) -> Arc; - fn as_create_ixgbe(&self) -> Arc; - fn as_create_virtio_net(&self) -> Arc; - fn as_create_nvme(&self) -> Arc; - fn as_create_net_shadow(&self) -> Arc; - fn as_create_nvme_shadow(&self) -> Arc; - fn as_create_benchnet(&self) -> Arc; - fn as_create_benchnvme(&self) -> Arc; - fn as_create_xv6fs(&self) -> Arc; - fn as_create_xv6net(&self) -> Arc; - fn as_create_xv6net_shadow(&self) -> Arc; - fn as_create_xv6usr(&self) -> Arc; - fn as_create_xv6(&self) -> Arc; - fn as_create_dom_a(&self) -> Arc; - fn as_create_dom_b(&self) -> Arc; - fn as_create_dom_c(&self) -> Arc; - fn as_create_dom_d(&self) -> Arc; - fn as_create_shadow(&self) -> Arc; + fn as_domain_create_CreateVirtioNet(&self) -> Arc; + fn as_domain_create_CreateIxgbe(&self) -> Arc; + fn as_domain_create_CreateDomD(&self) -> Arc; + fn as_domain_create_CreateMemBDev(&self) -> Arc; + fn as_domain_create_CreateRv6(&self) -> Arc; + fn as_domain_create_CreatePCI(&self) -> Arc; + fn as_domain_create_CreateRv6Net(&self) -> Arc; + fn as_domain_create_CreateDomC(&self) -> Arc; + fn as_domain_create_CreateTpm(&self) -> Arc; + fn as_domain_create_CreateBDevShadow( + &self, + ) -> Arc; + fn as_domain_create_CreateBenchnvme( + &self, + ) -> Arc; + fn as_domain_create_CreateRv6NetShadow( + &self, + ) -> Arc; + fn as_domain_create_CreateNvmeShadow( + &self, + ) -> Arc; + fn as_domain_create_CreateShadow(&self) -> Arc; + fn as_domain_create_CreateNetShadow( + &self, + ) -> Arc; + fn as_domain_create_CreateRv6Usr(&self) -> Arc; + fn as_domain_create_CreateNvme(&self) -> Arc; + fn as_domain_create_CreateRv6FS(&self) -> Arc; } diff --git a/interface/src/tpm.rs b/interface/src/tpm.rs index fb9f1c68..98f4d142 100644 --- a/interface/src/tpm.rs +++ b/interface/src/tpm.rs @@ -2,6 +2,8 @@ use alloc::vec::Vec; use alloc::boxed::Box; use core::mem; +use crate::rpc::RpcResult; + #[derive(Copy, Clone, Debug)] pub enum TpmRegs { TPM_ACCESS = 0x0000, @@ -118,10 +120,10 @@ pub enum TpmSE { } // Rv6 user -[UsrTpm]-> driver -[TpmDev]-> TPM -// #[interface] +#[interface] pub trait UsrTpm: Send + Sync { /// Create a clone of the TPM interface that points to the same driver. - fn clone_usrtpm(&self) -> Box; + fn clone_usrtpm(&self) -> RpcResult>; /// ## Locality related functions /// @@ -129,61 +131,61 @@ pub trait UsrTpm: Send + Sync { /// Validates the TPM locality, basically means that TPM is ready to listen for commands and /// perform operation in this locality. /// Ref: https://ebrary.net/24811/computer_science/locality_command - fn tpm_validate_locality(&self, locality: u32) -> bool; + fn tpm_validate_locality(&self, locality: u32) -> RpcResult; /// Explicitly giveup locality. This may not be useful if there is only a single process/user using /// TPM in an OS. In multi-user scenario, this is more applicable. - fn relinquish_locality(&self, locality: u32) -> bool; + fn relinquish_locality(&self, locality: u32) -> RpcResult; - fn tpm_deactivate_all_localities(&self) -> bool; + fn tpm_deactivate_all_localities(&self) -> RpcResult; /// Requests the TPM to switch to the locality we choose and wait for TPM to acknowledge our /// request - fn tpm_request_locality(&self, locality: u32) -> bool; + fn tpm_request_locality(&self, locality: u32) -> RpcResult; /// Reads the TPM ID from device register - fn read_tpm_id(&self, locality: u32); + fn read_tpm_id(&self, locality: u32) -> RpcResult<()>; /// Reads the burst_count from TPM register. Burst count is the amount of bytes the TPM device is /// capable of handling in oneshot. - fn tpm_get_burst(&self, locality: u32) -> u16; + fn tpm_get_burst(&self, locality: u32) -> RpcResult; /// Busy-wait in a loop for a particular status flag to be set - fn wait_for_status_flag(&self, locality: u32, flag: u8, timeout_ms: usize) -> bool; + fn wait_for_status_flag(&self, locality: u32, flag: u8, timeout_ms: usize) -> RpcResult; /// Writes data to the TPM FIFO. /// Here, `data.len < burst_count` - fn tpm_write_data(&self, locality: u32, data: &[u8]) -> usize; + fn tpm_write_data(&self, locality: u32, data: &[u8]) -> RpcResult; /// Checks TPM status register to see if there is any data available - fn is_data_available(&self, locality: u32) -> bool; + fn is_data_available(&self, locality: u32) -> RpcResult; /// Read data from TPM /// * Wait for data to be available /// * Receive as much as burst_count - fn tpm_read_data(&self, locality: u32, data: &mut [u8]) -> usize; + fn tpm_read_data(&self, locality: u32, data: &mut [u8]) -> RpcResult; /// Wrapper for `tpm_read_data` /// This function first tries to read TPM_HEADER_SIZE bytes from the TPM to determine the length of /// payload data. /// Then it issues a second read for the length of payload data subtract TPM_HEADER_SIZE /// Payload consists of the argument that was sent to the TPM during tpm_send_data and the response - fn tpm_recv_data(&self, locality: u32, buf: &mut Vec, rc: &mut u32) -> usize; + fn tpm_recv_data(&self, locality: u32, buf: &mut Vec, rc: &mut u32) -> RpcResult; /// Wrapper for `tpm_write_data` /// This function waits for TPM to be in a state to accept commands before writing data to FIFO. - fn tpm_send_data(&self, locality: u32, buf: &mut Vec) -> usize; + fn tpm_send_data(&self, locality: u32, buf: &mut Vec) -> RpcResult; /// Transmit command to a TPM. /// This function does a bi-directional communication with TPM. /// First, it sends a command with headers /// If successful, try to read the response buffer from TPM - fn tpm_transmit_cmd(&self, locality: u32, buf: &mut Vec); + fn tpm_transmit_cmd(&self, locality: u32, buf: &mut Vec) -> RpcResult<()>; /// Table 3:68 - TPM2_GetRandom Command /// Get a random number from TPM. /// `num_octets` represents the length of the random number in bytes - fn tpm_get_random(&self, locality: u32, num_octets: usize) -> bool; + fn tpm_get_random(&self, locality: u32, num_octets: usize) -> RpcResult; /// Table 3:114 - TPM2_PCR_Read Command /// Read a PCR register. @@ -196,15 +198,15 @@ pub trait UsrTpm: Send + Sync { hash: u16, digest_size: &mut u16, digest: &mut Vec, - ) -> bool; + ) -> RpcResult; /// Obtain information about banks that are allocated in TPM - fn tpm_init_bank_info(&self, locality: u32, hash_alg: u16) -> TpmBankInfo; + fn tpm_init_bank_info(&self, locality: u32, hash_alg: u16) -> RpcResult; /// Table 3:208 - TPM2_PCR_GetCapability Command /// Obtain the banks that are allocated in TPM /// TODO: Return true/false, not structure - fn tpm_get_pcr_allocation(&self, locality: u32) -> TpmDevInfo; + fn tpm_get_pcr_allocation(&self, locality: u32) -> RpcResult; /// Table 3:110 - TPM2_PCR_Read Command /// Extend PCR register. @@ -215,15 +217,15 @@ pub trait UsrTpm: Send + Sync { tpm_info: &TpmDevInfo, pcr_idx: usize, digest_values: Vec, - ) -> bool; + ) -> RpcResult; /// Table 3:78 - TPM2_HashSequenceStart Command /// Conduct hash calculation in TPM - fn tpm_hash_sequence_start(&self, locality: u32, hash: TpmAlgorithms, object: &mut u32) -> bool; + fn tpm_hash_sequence_start(&self, locality: u32, hash: TpmAlgorithms, object: &mut u32) -> RpcResult; /// Table 3:80 - TPM2_SequenceUpdate /// Update hash calculation in TPM - fn tpm_sequence_update(&self, locality: u32, object: u32, buffer: Vec) -> bool; + fn tpm_sequence_update(&self, locality: u32, object: u32, buffer: Vec) -> RpcResult; /// Table 3:82 - TPM2_SequenceComplete /// Finalize hash calculation in TPM @@ -234,7 +236,7 @@ pub trait UsrTpm: Send + Sync { buffer: Vec, hash_size: &mut u16, hash: &mut Vec, - ) -> bool; + ) -> RpcResult; /// Table 3:62 - TPM2_Hash /// Generic hash calculation in TPM when data size is known @@ -245,7 +247,7 @@ pub trait UsrTpm: Send + Sync { buffer: Vec, hash_size: &mut u16, hash_val: &mut Vec, - ) -> bool; + ) -> RpcResult; /// Table 3:164 - TPM2_PCR_CreatePrimary Command /// Create Primary Key. @@ -261,7 +263,7 @@ pub trait UsrTpm: Send + Sync { parent_handle: &mut u32, pubkey_size: &mut usize, pubkey: &mut Vec, - ) -> bool; + ) -> RpcResult; /// Table 3:15 - TPM2_StartAuthSession Command /// Start Authenticated Session and returns a session handle @@ -271,7 +273,7 @@ pub trait UsrTpm: Send + Sync { session_type: TpmSE, nonce: Vec, session_handle: &mut u32, - ) -> bool; + ) -> RpcResult; /// Table 3:132 - TPM2_PolicyPCR Command /// Bind a policy to a particular PCR @@ -281,7 +283,7 @@ pub trait UsrTpm: Send + Sync { session_handle: u32, digest: Vec, pcr_idx: usize, - ) -> bool; + ) -> RpcResult; /// Table 3:156 - TPM2_PolicyGetDigest Command /// Get Policy digest from current policy @@ -290,7 +292,7 @@ pub trait UsrTpm: Send + Sync { locality: u32, session_handle: u32, policy_digest: &mut Vec, - ) -> bool; + ) -> RpcResult; /// Table 3:19 - TPM2_Create Command /// Create child key @@ -306,7 +308,7 @@ pub trait UsrTpm: Send + Sync { sign: bool, out_private: &mut Vec, out_public: &mut Vec, - ) -> bool; + ) -> RpcResult; /// Table 3:21 - TPM2_Load Command /// Load objects into the TPM. @@ -319,7 +321,7 @@ pub trait UsrTpm: Send + Sync { in_private: Vec, in_public: Vec, item_handle: &mut u32, - ) -> bool; + ) -> RpcResult; /// Table 3:31 - TPM2_Unseal Command /// Unseal data sealed via TPM_CC_CREATE @@ -329,7 +331,7 @@ pub trait UsrTpm: Send + Sync { session_handle: u32, item_handle: u32, out_data: &mut Vec, - ) -> bool; + ) -> RpcResult; /// Table 3:90 - TPM2_Quote /// Generate Quote. @@ -344,9 +346,9 @@ pub trait UsrTpm: Send + Sync { pcr_idxs: Vec, out_pcr_digest: &mut Vec, out_sig: &mut Vec, - ) -> bool; + ) -> RpcResult; /// Table 3:198 - TPM2_FlushContext Command /// Remove loaded objects, sequence objects, and/or sessions from TPM memory - fn tpm_flush_context(&self, locality: u32, flush_handle: u32) -> bool; + fn tpm_flush_context(&self, locality: u32, flush_handle: u32) -> RpcResult; } diff --git a/interface/src/vfs/mod.rs b/interface/src/vfs/mod.rs index 68d12010..65f355e1 100644 --- a/interface/src/vfs/mod.rs +++ b/interface/src/vfs/mod.rs @@ -37,13 +37,40 @@ pub trait UsrVFS: Send + Sync { pub trait KernelVFS: Send + Sync { // Save threadlocal objects to a temporary storage and return its id // For fdtable, only save the selected ones specified by `fds` - fn sys_save_threadlocal(&self, fds: [Option; NFILE]) -> Result; + fn sys_save_threadlocal(&self, fds: [Option; NFILE]) -> RpcResult>; // Set threadlocal objects to a temporary object identify by the `id` - fn sys_set_threadlocal(&self, id: usize) -> Result<()>; + fn sys_set_threadlocal(&self, id: usize) -> RpcResult>; // Tell the file system that this thread is exiting and thread local objects should be cleaned up - fn sys_thread_exit(&self); + fn sys_thread_exit(&self) -> RpcResult<()>; } -pub trait VFS: UsrVFS + KernelVFS + Send + Sync { - fn clone(&self) -> Box; +/// Super trait of UsrVFS and KernelVFS. +/// Since super trait is not supported by ngc, we copied and pasted UsrVFS and KernelVFS in here. +#[interface] +pub trait VFS: Send + Sync { + // UserVFS starts. + fn sys_open(&self, path: RRefVec, mode: FileMode) -> RpcResult)>>; + fn sys_close(&self, fd: usize) -> RpcResult>; + fn sys_read(&self, fd: usize, buffer: RRefVec) -> RpcResult)>>; + fn sys_write(&self, fd: usize, buffer: RRefVec) -> RpcResult)>>; + fn sys_seek(&self, fd: usize, offset: usize) -> RpcResult>; + fn sys_fstat(&self, fd: usize) -> RpcResult>; + fn sys_mknod(&self, path: RRefVec, major: i16, minor: i16) -> RpcResult>; + fn sys_dup(&self, fd: usize) -> RpcResult>; + fn sys_pipe(&self) -> RpcResult>; + fn sys_link(&self, old_path: RRefVec, new_path: RRefVec) -> RpcResult>; + fn sys_unlink(&self, path: RRefVec) -> RpcResult>; + fn sys_mkdir(&self, path: RRefVec) -> RpcResult>; + fn sys_dump_inode(&self) -> RpcResult>; + + // KernelVFS starts. + // Save threadlocal objects to a temporary storage and return its id + // For fdtable, only save the selected ones specified by `fds` + fn sys_save_threadlocal(&self, fds: [Option; NFILE]) -> RpcResult>; + // Set threadlocal objects to a temporary object identify by the `id` + fn sys_set_threadlocal(&self, id: usize) -> RpcResult>; + // Tell the file system that this thread is exiting and thread local objects should be cleaned up + fn sys_thread_exit(&self) -> RpcResult<()>; + + fn clone(&self) -> RpcResult>; } diff --git a/kernel/.gitignore b/kernel/.gitignore index ffd09c62..19ef89ed 100644 --- a/kernel/.gitignore +++ b/kernel/.gitignore @@ -1,2 +1,3 @@ /redleaf.key /redleaf.pub +src/generated_domain_create.rs diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 5daf955d..6da421e4 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -80,6 +80,9 @@ rand = "0.7" ed25519-dalek = "1.0.0-pre.3" [features] +default = [ + "domain_create_log", +] smp = [ ] trace_alloc = [ ] trace_vspace = [] @@ -88,3 +91,4 @@ large_mem = [] c220g2_ixgbe = [] trace_sched = [] baremetal = [] +domain_create_log = [] diff --git a/kernel/src/gen.rs b/kernel/src/gen.rs deleted file mode 100644 index 3a0f8782..00000000 --- a/kernel/src/gen.rs +++ /dev/null @@ -1,1960 +0,0 @@ -use interface::domain_creation; -use interface::proxy; -use syscalls; -use interface; - -use alloc::boxed::Box; -use alloc::sync::Arc; - -use interface::error::Result; - -use crate::domain::load_domain; -use crate::heap::PHeap; -use crate::interrupt::{disable_irq, enable_irq}; -use crate::syscalls::{Interrupt, Mmap, PDomain}; -use crate::thread; - -impl domain_creation::CreatePCI for PDomain { - fn create_domain_pci(&self) -> (Box, Box) { - disable_irq(); - let r = create_domain_pci(); - enable_irq(); - r - } -} - -impl domain_creation::CreateAHCI for PDomain { - fn create_domain_ahci( - &self, - pci: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_ahci(pci); - enable_irq(); - r - } -} - -impl domain_creation::CreateMemBDev for PDomain { - fn create_domain_membdev( - &self, - memdisk: &'static mut [u8], - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_membdev(memdisk); - enable_irq(); - r - } - - fn recreate_domain_membdev( - &self, - _dom: Box, - memdisk: &'static mut [u8], - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_membdev(memdisk); - enable_irq(); - r - } -} - -impl domain_creation::CreateBDevShadow for PDomain { - fn create_domain_bdev_shadow( - &self, - create: Arc, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_bdev_shadow(create); - enable_irq(); - r - } -} - -impl domain_creation::CreateIxgbe for PDomain { - fn create_domain_ixgbe( - &self, - pci: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_ixgbe(pci); - enable_irq(); - r - } -} - -impl domain_creation::CreateVirtioNet for PDomain { - fn create_domain_virtio_net( - &self, - pci: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_virtio_net(pci); - enable_irq(); - r - } -} - - -impl domain_creation::CreateNetShadow for PDomain { - fn create_domain_net_shadow( - &self, - create: Arc, - pci: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_net_shadow(create, pci); - enable_irq(); - r - } -} - -impl domain_creation::CreateNvmeShadow for PDomain { - fn create_domain_nvme_shadow( - &self, - create: Arc, - pci: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_nvme_shadow(create, pci); - enable_irq(); - r - } -} - -impl domain_creation::CreateNvme for PDomain { - fn create_domain_nvme( - &self, - pci: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_nvme(pci); - enable_irq(); - r - } -} - -impl domain_creation::CreateRv6 for PDomain { - fn create_domain_xv6kernel( - &self, - ints: Box, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - bdev: Box, - net: Box, - nvme: Box, - usr_tpm: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_xv6kernel( - ints, - create_xv6fs, - create_xv6net, - create_xv6net_shadow, - create_xv6usr, - bdev, - net, - nvme, - usr_tpm, - ); - enable_irq(); - r - } -} - -impl domain_creation::CreateRv6FS for PDomain { - fn create_domain_xv6fs( - &self, - bdev: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_xv6fs(bdev); - enable_irq(); - r - } -} - -impl domain_creation::CreateRv6Net for PDomain { - fn create_domain_xv6net( - &self, - net: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_xv6net(net); - enable_irq(); - r - } -} - -impl domain_creation::CreateRv6NetShadow for PDomain { - fn create_domain_xv6net_shadow( - &self, - create: Arc, - net: Box, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_xv6net_shadow(create, net); - enable_irq(); - r - } -} - -impl domain_creation::CreateRv6Usr for PDomain { - fn create_domain_xv6usr( - &self, - name: &str, - xv6: Box, - blob: &[u8], - args: &str, - ) -> Result> { - disable_irq(); - let r = create_domain_xv6usr(name, xv6, blob, args); - enable_irq(); - r - } -} - -impl domain_creation::CreateDomA for PDomain { - fn create_domain_dom_a(&self) -> (Box, Box) { - disable_irq(); - let r = create_domain_dom_a(); - enable_irq(); - r - } -} - -impl domain_creation::CreateDomB for PDomain { - fn create_domain_dom_b(&self, dom_a: Box) -> Box { - disable_irq(); - let r = create_domain_dom_b(dom_a); - enable_irq(); - r - } -} - -impl domain_creation::CreateDomC for PDomain { - fn create_domain_dom_c(&self) -> (Box, Box) { - disable_irq(); - let r = create_domain_dom_c(); - enable_irq(); - r - } - - fn recreate_domain_dom_c( - &self, - dom: Box, - ) -> (Box, Box) { - disable_irq(); - let r = recreate_domain_dom_c(dom); - enable_irq(); - r - } -} - -impl domain_creation::CreateDomD for PDomain { - fn create_domain_dom_d(&self, dom_c: Box) -> Box { - disable_irq(); - let r = create_domain_dom_d(dom_c); - enable_irq(); - r - } -} - -impl domain_creation::CreateShadow for PDomain { - fn create_domain_shadow( - &self, - create_dom_c: Arc, - ) -> (Box, Box) { - disable_irq(); - let r = create_domain_shadow(create_dom_c); - enable_irq(); - r - } -} - -impl domain_creation::CreateBenchnet for PDomain { - fn create_domain_benchnet(&self, net: Box) -> Box { - disable_irq(); - let r = create_domain_benchnet(net); - enable_irq(); - r - } -} - -impl domain_creation::CreateBenchnvme for PDomain { - fn create_domain_benchnvme( - &self, - nvme: Box, - ) -> Box { - disable_irq(); - let r = create_domain_benchnvme(nvme); - enable_irq(); - r - } -} - -impl domain_creation::CreateHashStore for PDomain { - fn create_domain_hashstore(&self) -> Box { - disable_irq(); - let r = create_domain_hashstore(); - enable_irq(); - r - } -} - -impl domain_creation::CreateTpm for PDomain { - fn create_domain_tpm(&self) -> (Box, Box) { - disable_irq(); - let r = create_domain_tpm(); - enable_irq(); - r - } -} - -impl proxy::CreateProxy for PDomain { - fn create_domain_proxy( - &self, - create_pci: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_xv6: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - create_shadow: Arc, - ) -> (Box, Arc) { - disable_irq(); - let r = create_domain_proxy( - create_pci, - create_ahci, - create_membdev, - create_bdev_shadow, - create_ixgbe, - create_virtio_net, - create_nvme, - create_net_shadow, - create_nvme_shadow, - create_benchnet, - create_benchnvme, - create_xv6fs, - create_xv6net, - create_xv6net_shadow, - create_xv6usr, - create_xv6, - create_dom_a, - create_dom_b, - create_dom_c, - create_dom_d, - create_shadow, - ); - enable_irq(); - r - } -} - -pub fn create_domain_init() -> Box { - extern "C" { - fn _binary_domains_build_redleaf_init_start(); - fn _binary_domains_build_redleaf_init_end(); - } - - let binary_range = ( - _binary_domains_build_redleaf_init_start as *const u8, - _binary_domains_build_redleaf_init_end as *const u8, - ); - - return build_domain_init("sys_init", binary_range); -} - -pub fn create_domain_pci() -> (Box, Box) { - extern "C" { - fn _binary_domains_build_pci_start(); - fn _binary_domains_build_pci_end(); - } - - let binary_range = ( - _binary_domains_build_pci_start as *const u8, - _binary_domains_build_pci_end as *const u8, - ); - - create_domain_pci_bus("pci", binary_range) -} - -pub fn create_domain_ahci( - _pci: Box, -) -> (Box, Box) { - // extern "C" { - // fn _binary_domains_build_ahci_driver_start(); - // fn _binary_domains_build_ahci_driver_end(); - // } - - // let binary_range = ( - // _binary_domains_build_ahci_driver_start as *const u8, - // _binary_domains_build_ahci_driver_end as *const u8 - // ); - - // create_domain_bdev("ahci", binary_range, pci) - unimplemented!() -} - -pub fn create_domain_ixgbe( - pci: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_ixgbe_start(); - fn _binary_domains_build_ixgbe_end(); - } - - let binary_range = ( - _binary_domains_build_ixgbe_start as *const u8, - _binary_domains_build_ixgbe_end as *const u8, - ); - - create_domain_net("ixgbe_driver", binary_range, pci) -} - -pub fn create_domain_virtio_net( - pci: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_virtio_net_start(); - fn _binary_domains_build_virtio_net_end(); - } - - let binary_range = ( - _binary_domains_build_virtio_net_start as *const u8, - _binary_domains_build_virtio_net_end as *const u8, - ); - - create_domain_net("virtnet_driver", binary_range, pci) -} - -pub fn create_domain_net_shadow( - create: Arc, - pci: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_net_shadow_start(); - fn _binary_domains_build_net_shadow_end(); - } - - let binary_range = ( - _binary_domains_build_net_shadow_start as *const u8, - _binary_domains_build_net_shadow_end as *const u8, - ); - - build_domain_net_shadow("net_shadow", binary_range, create, pci) -} - -pub fn create_domain_nvme_shadow( - create: Arc, - pci: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_nvme_shadow_start(); - fn _binary_domains_build_nvme_shadow_end(); - } - - let binary_range = ( - _binary_domains_build_nvme_shadow_start as *const u8, - _binary_domains_build_nvme_shadow_end as *const u8, - ); - - build_domain_nvme_shadow("nvme_shadow", binary_range, create, pci) -} - -pub fn create_domain_nvme( - pci: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_nvme_start(); - fn _binary_domains_build_nvme_end(); - } - - let binary_range = ( - _binary_domains_build_nvme_start as *const u8, - _binary_domains_build_nvme_end as *const u8, - ); - - create_domain_nvmedev("nvme_driver", binary_range, pci) -} - -pub fn create_domain_membdev( - memdisk: &'static mut [u8], -) -> (Box, Box) { - #[cfg(debug_assertions)] - let binary_range = { - extern "C" { - fn _binary_domains_build_membdev_start(); - fn _binary_domains_build_membdev_end(); - } - - ( - _binary_domains_build_membdev_start as *const u8, - _binary_domains_build_membdev_end as *const u8, - ) - }; - #[cfg(not(debug_assertions))] - let binary_range = { - extern "C" { - fn _binary_domains_build_membdev_start(); - fn _binary_domains_build_membdev_end(); - } - - ( - _binary_domains_build_membdev_start as *const u8, - _binary_domains_build_membdev_end as *const u8, - ) - }; - - create_domain_bdev_mem("membdev", binary_range, memdisk) -} - -pub fn create_domain_bdev_shadow( - create: Arc, -) -> (Box, Box) { - #[cfg(debug_assertions)] - let binary_range = { - extern "C" { - fn _binary_domains_build_bdev_shadow_start(); - fn _binary_domains_build_bdev_shadow_end(); - } - - ( - _binary_domains_build_bdev_shadow_start as *const u8, - _binary_domains_build_bdev_shadow_end as *const u8, - ) - }; - #[cfg(not(debug_assertions))] - let binary_range = { - extern "C" { - fn _binary_domains_build_bdev_shadow_start(); - fn _binary_domains_build_bdev_shadow_end(); - } - - ( - _binary_domains_build_bdev_shadow_start as *const u8, - _binary_domains_build_bdev_shadow_end as *const u8, - ) - }; - - create_domain_bdev_shadow_helper("bdev_shadow", binary_range, create) -} - -pub fn create_domain_xv6kernel( - ints: Box, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - bdev: Box, - net: Box, - nvme: Box, - usr_tpm: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_xv6kernel_start(); - fn _binary_domains_build_xv6kernel_end(); - } - - let binary_range = ( - _binary_domains_build_xv6kernel_start as *const u8, - _binary_domains_build_xv6kernel_end as *const u8, - ); - - build_domain_xv6kernel( - "xv6kernel", - binary_range, - ints, - create_xv6fs, - create_xv6net, - create_xv6net_shadow, - create_xv6usr, - bdev, - net, - nvme, - usr_tpm, - ) -} - -pub fn create_domain_xv6fs( - bdev: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_xv6fs_start(); - fn _binary_domains_build_xv6fs_end(); - } - - let binary_range = ( - _binary_domains_build_xv6fs_start as *const u8, - _binary_domains_build_xv6fs_end as *const u8, - ); - - build_domain_fs("xv6fs", binary_range, bdev) -} - -// AB: We have to split ukern syscalls into some that are -// accessible to xv6 user, e.g., memory management, and the rest -// which is hidden, e.g., create_thread, etc. -pub fn create_domain_xv6usr( - name: &str, - xv6: Box, - blob: &[u8], - args: &str, -) -> Result> { - // TODO: verify that the blob is signed - // if !signed(blob) return Err("Not signed") - - Ok(build_domain_xv6usr(name, xv6, blob, args)) -} - -pub fn create_domain_xv6net( - net: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_xv6net_start(); - fn _binary_domains_build_xv6net_end(); - } - - let binary_range = ( - _binary_domains_build_xv6net_start as *const u8, - _binary_domains_build_xv6net_end as *const u8, - ); - - build_domain_xv6net("xv6net", binary_range, net) -} - -pub fn create_domain_xv6net_shadow( - create: Arc, - net: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_xv6net_shadow_start(); - fn _binary_domains_build_xv6net_shadow_end(); - } - - let binary_range = ( - _binary_domains_build_xv6net_shadow_start as *const u8, - _binary_domains_build_xv6net_shadow_end as *const u8, - ); - - build_domain_xv6net_shadow("xv6net_shadow", binary_range, create, net) -} - -pub fn create_domain_dom_a() -> (Box, Box) { - extern "C" { - fn _binary_domains_build_dom_a_start(); - fn _binary_domains_build_dom_a_end(); - } - - let binary_range = ( - _binary_domains_build_dom_a_start as *const u8, - _binary_domains_build_dom_a_end as *const u8, - ); - - build_domain_dom_a("dom_a", binary_range) -} - -pub fn create_domain_dom_b(dom_a: Box) -> Box { - extern "C" { - fn _binary_domains_build_dom_b_start(); - fn _binary_domains_build_dom_b_end(); - } - - let binary_range = ( - _binary_domains_build_dom_b_start as *const u8, - _binary_domains_build_dom_b_end as *const u8, - ); - - build_domain_dom_b("dom_b", binary_range, dom_a) -} - -pub fn create_domain_dom_c() -> (Box, Box) { - extern "C" { - fn _binary_domains_build_dom_c_start(); - fn _binary_domains_build_dom_c_end(); - } - - let binary_range = ( - _binary_domains_build_dom_c_start as *const u8, - _binary_domains_build_dom_c_end as *const u8, - ); - - build_domain_dom_c("dom_c", binary_range) -} - -pub fn recreate_domain_dom_c( - _dom: Box, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_dom_c_start(); - fn _binary_domains_build_dom_c_end(); - } - - let binary_range = ( - _binary_domains_build_dom_c_start as *const u8, - _binary_domains_build_dom_c_end as *const u8, - ); - - build_domain_dom_c("dom_c", binary_range) -} - -pub fn create_domain_dom_d(dom_c: Box) -> Box { - extern "C" { - fn _binary_domains_build_dom_d_start(); - fn _binary_domains_build_dom_d_end(); - } - - let binary_range = ( - _binary_domains_build_dom_d_start as *const u8, - _binary_domains_build_dom_d_end as *const u8, - ); - - build_domain_dom_d("dom_d", binary_range, dom_c) -} - -pub fn create_domain_shadow( - create_dom_c: Arc, -) -> (Box, Box) { - extern "C" { - fn _binary_domains_build_shadow_start(); - fn _binary_domains_build_shadow_end(); - } - - let binary_range = ( - _binary_domains_build_shadow_start as *const u8, - _binary_domains_build_shadow_end as *const u8, - ); - - build_domain_shadow("shadow", binary_range, create_dom_c) -} - -pub fn create_domain_benchnet(net: Box) -> Box { - extern "C" { - fn _binary_domains_build_benchnet_inside_start(); - fn _binary_domains_build_benchnet_inside_end(); - } - - let binary_range = ( - _binary_domains_build_benchnet_inside_start as *const u8, - _binary_domains_build_benchnet_inside_end as *const u8, - ); - - build_domain_benchnet_helper("benchnet", binary_range, net) -} - -pub fn create_domain_benchnvme(nvme: Box) -> Box { - extern "C" { - fn _binary_domains_build_benchnvme_start(); - fn _binary_domains_build_benchnvme_end(); - } - - let binary_range = ( - _binary_domains_build_benchnvme_start as *const u8, - _binary_domains_build_benchnvme_end as *const u8, - ); - - build_domain_benchnvme("benchnvme", binary_range, nvme) -} - -pub fn create_domain_hashstore() -> Box { - extern "C" { - fn _binary_domains_build_benchhash_start(); - fn _binary_domains_build_benchhash_end(); - } - - let binary_range = ( - _binary_domains_build_benchhash_start as *const u8, - _binary_domains_build_benchhash_end as *const u8, - ); - - build_domain_hashstore("benchhash", binary_range) -} - -pub fn create_domain_tpm() -> (Box, Box) { - extern "C" { - fn _binary_domains_build_tpm_start(); - fn _binary_domains_build_tpm_end(); - } - - let binary_range = ( - _binary_domains_build_tpm_start as *const u8, - _binary_domains_build_tpm_end as *const u8, - ); - - build_domain_tpm("tpm_driver", binary_range) -} - -pub fn create_domain_proxy( - create_pci: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_xv6: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - create_shadow: Arc, -) -> (Box, Arc) { - extern "C" { - fn _binary_domains_build_dom_proxy_start(); - fn _binary_domains_build_dom_proxy_end(); - } - - let binary_range = ( - _binary_domains_build_dom_proxy_start as *const u8, - _binary_domains_build_dom_proxy_end as *const u8, - ); - - build_domain_proxy( - "dom_proxy", - binary_range, - create_pci, - create_ahci, - create_membdev, - create_bdev_shadow, - create_ixgbe, - create_virtio_net, - create_nvme, - create_net_shadow, - create_nvme_shadow, - create_benchnet, - create_benchnvme, - create_xv6fs, - create_xv6net, - create_xv6net_shadow, - create_xv6usr, - create_xv6, - create_dom_a, - create_dom_b, - create_dom_c, - create_dom_d, - create_shadow, - ) -} - -pub fn create_domain_pci_bus( - name: &str, - binary_range: (*const u8, *const u8), -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let mmap = Box::new(Mmap::new()); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let pci = user_ep(pdom, mmap, pheap); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), pci) -} - -pub fn create_domain_bdev( - name: &str, - binary_range: (*const u8, *const u8), - pci: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let bdev = user_ep(pdom, pheap, pci); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), bdev) -} - -pub fn create_domain_bdev_mem( - name: &str, - binary_range: (*const u8, *const u8), - memdisk: &'static mut [u8], -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - &'static mut [u8], - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let bdev = user_ep(pdom, pheap, memdisk); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), bdev) -} - -pub fn create_domain_bdev_shadow_helper( - name: &str, - binary_range: (*const u8, *const u8), - create: Arc, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Arc, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let bdev = user_ep(pdom, pheap, create); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), bdev) -} - -pub fn create_domain_net( - name: &str, - binary_range: (*const u8, *const u8), - pci: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let net = user_ep(pdom, pheap, pci); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), net) -} - -pub fn build_domain_net_shadow( - name: &str, - binary_range: (*const u8, *const u8), - create: Arc, - pci: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Arc, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let net = user_ep(pdom, pheap, create, pci); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), net) -} - -pub fn build_domain_nvme_shadow( - name: &str, - binary_range: (*const u8, *const u8), - create: Arc, - pci: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Arc, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let net = user_ep(pdom, pheap, create, pci); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), net) -} - -pub fn create_domain_nvmedev( - name: &str, - binary_range: (*const u8, *const u8), - pci: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let nvme = user_ep(pdom, pheap, pci); - disable_irq(); - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), nvme) -} - -// AB: XXX: The following is is not supported in Rust at the moment -// -//pub fn init(s: Box) -// See -// rustc --explain E0225 -// -// We have to re-write in an ugly way - -pub fn build_domain_init( - name: &str, - binary_range: (*const u8, *const u8), -) -> Box { - type UserInit = fn( - Box, - Box, - Box, - Box, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - create_nvme_shadow: Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - Arc, - ); - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - user_ep( - Box::new(PDomain::new(Arc::clone(&dom))), - Box::new(PHeap::new()), - Box::new(Interrupt::new()), - Box::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - Arc::new(PDomain::new(Arc::clone(&dom))), - ); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - Box::new(PDomain::new(Arc::clone(&dom))) -} - -pub fn build_domain_fs( - name: &str, - binary_range: (*const u8, *const u8), - bdev: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let vfs = user_ep(pdom, pheap, bdev); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), vfs) -} - -pub fn build_domain_xv6net( - name: &str, - binary_range: (*const u8, *const u8), - net: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let usrnet = user_ep(pdom, pheap, net); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), usrnet) -} - -pub fn build_domain_xv6net_shadow( - name: &str, - binary_range: (*const u8, *const u8), - create: Arc, - net: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Arc, - Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let usrnet = user_ep(pdom, pheap, create, net); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), usrnet) -} - -pub fn build_domain_proxy( - name: &str, - binary_range: (*const u8, *const u8), - create_pci: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_xv6: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - create_shadow: Arc, -) -> (Box, Arc) { - type UserInit = fn( - Box, - Box, - create_pci: Arc, - create_ahci: Arc, - create_membdev: Arc, - create_bdev_shadow: Arc, - create_ixgbe: Arc, - create_virtio_net: Arc, - create_nvme: Arc, - create_net_shadow: Arc, - create_nvme_shadow: Arc, - create_benchnet: Arc, - create_benchnvme: Arc, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - create_xv6: Arc, - create_dom_a: Arc, - create_dom_b: Arc, - create_dom_c: Arc, - create_dom_d: Arc, - create_shadow: Arc, - ) -> Arc; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let proxy = user_ep( - pdom, - pheap, - create_pci, - create_ahci, - create_membdev, - create_bdev_shadow, - create_ixgbe, - create_virtio_net, - create_nvme, - create_net_shadow, - create_nvme_shadow, - create_benchnet, - create_benchnvme, - create_xv6fs, - create_xv6net, - create_xv6net_shadow, - create_xv6usr, - create_xv6, - create_dom_a, - create_dom_b, - create_dom_c, - create_dom_d, - create_shadow, - ); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), proxy) -} - -pub fn build_domain_xv6kernel( - name: &str, - binary_range: (*const u8, *const u8), - ints: Box, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6usr: Arc, - bdev: Box, - net: Box, - nvme: Box, - usr_tpm: Box, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - Box, - create_xv6fs: Arc, - create_xv6net: Arc, - create_xv6net_shadow: Arc, - create_xv6kernel: Arc, - bdev: Box, - net: Box, - nvme: Box, - usr_tpm: Box, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let rv6 = user_ep( - pdom, - pheap, - ints, - create_xv6fs, - create_xv6net, - create_xv6net_shadow, - create_xv6usr, - bdev, - net, - nvme, - usr_tpm, - ); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), rv6) -} - -pub fn build_domain_xv6usr( - name: &str, - xv6: Box, - blob: &[u8], - args: &str, -) -> Box { - type UserInit = - fn(Box, Box, Box, &str); - - let begin = blob.as_ptr(); - let end = unsafe { begin.offset(blob.len() as isize) }; - let (dom, entry) = unsafe { load_domain(name, (begin, end)) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - user_ep(pdom, pheap, xv6, args); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!( - "domain/{}: returned from entry point with return code", - name - ); - Box::new(PDomain::new(Arc::clone(&dom))) -} - -pub fn build_domain_dom_a( - name: &str, - binary_range: (*const u8, *const u8), -) -> (Box, Box) { - type UserInit = - fn(Box, Box) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let dom_a = user_ep(pdom, pheap); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), dom_a) -} - -pub fn build_domain_dom_b( - name: &str, - binary_range: (*const u8, *const u8), - dom_a: Box, -) -> Box { - type UserInit = - fn(Box, Box, Box); - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - user_ep(pdom, pheap, dom_a); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - Box::new(PDomain::new(Arc::clone(&dom))) -} - -pub fn build_domain_dom_c( - name: &str, - binary_range: (*const u8, *const u8), -) -> (Box, Box) { - type UserInit = - fn(Box, Box) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let dom_c = user_ep(pdom, pheap); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), dom_c) -} - -pub fn build_domain_dom_d( - name: &str, - binary_range: (*const u8, *const u8), - dom_c: Box, -) -> Box { - type UserInit = - fn(Box, Box, Box); - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - user_ep(pdom, pheap, dom_c); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - Box::new(PDomain::new(Arc::clone(&dom))) -} - -pub fn build_domain_shadow( - name: &str, - binary_range: (*const u8, *const u8), - create_dom_c: Arc, -) -> (Box, Box) { - type UserInit = fn( - Box, - Box, - create_dom_c: Arc, - ) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let shadow = user_ep(pdom, pheap, create_dom_c); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), shadow) -} - -pub fn build_domain_benchnet_helper( - name: &str, - binary_range: (*const u8, *const u8), - net: Box, -) -> Box { - type UserInit = - fn(Box, Box, net: Box); - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let _shadow = user_ep(pdom, pheap, net); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - Box::new(PDomain::new(Arc::clone(&dom))) -} - -pub fn build_domain_benchnvme( - name: &str, - binary_range: (*const u8, *const u8), - nvme: Box, -) -> Box { - type UserInit = - fn(Box, Box, nvme: Box); - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let _shadow = user_ep(pdom, pheap, nvme); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - Box::new(PDomain::new(Arc::clone(&dom))) -} - -pub fn build_domain_hashstore( - name: &str, - binary_range: (*const u8, *const u8), -) -> Box { - type UserInit = fn(Box, Box); - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let _shadow = user_ep(pdom, pheap); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - Box::new(PDomain::new(Arc::clone(&dom))) -} - -pub fn build_domain_tpm( - name: &str, - binary_range: (*const u8, *const u8), -) -> (Box, Box) { - type UserInit = - fn(Box, Box) -> Box; - - let (dom, entry) = unsafe { load_domain(name, binary_range) }; - - let user_ep: UserInit = unsafe { core::mem::transmute::<*const (), UserInit>(entry) }; - - let pdom = Box::new(PDomain::new(Arc::clone(&dom))); - let pheap = Box::new(PHeap::new()); - - // update current domain id - let thread = thread::get_current_ref(); - let old_id = { - let mut thread = thread.lock(); - let old_id = thread.current_domain_id; - thread.current_domain_id = dom.lock().id; - old_id - }; - - // Enable interrupts on exit to user so it can be preempted - enable_irq(); - let tpmdev = user_ep(pdom, pheap); - disable_irq(); - - // change domain id back - { - thread.lock().current_domain_id = old_id; - } - - println!("domain/{}: returned from entry point", name); - (Box::new(PDomain::new(Arc::clone(&dom))), tpmdev) -} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 0c845125..15c4c156 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -15,7 +15,8 @@ panic_info_message, asm, llvm_asm, - global_asm + global_asm, + type_ascription, )] extern crate x86; @@ -57,7 +58,7 @@ pub mod arch; mod dev; mod domain; -mod gen; +mod generated_domain_create; mod panic; mod pci; mod sync; @@ -187,7 +188,7 @@ extern "C" fn init_user() { // die() enables interrupts as it thinks it is // starting a user thead, lets disable them disable_irq(); - gen::create_domain_init(); + generated_domain_create::create_domain_init(); enable_irq(); } diff --git a/tools/redIDL b/tools/redIDL index 49ed5dfd..1a17b657 160000 --- a/tools/redIDL +++ b/tools/redIDL @@ -1 +1 @@ -Subproject commit 49ed5dfdfdc17792157160e0a96e8153e53daf02 +Subproject commit 1a17b657167d2bbb66ea1b40e0ef9ab3de6f3a88 diff --git a/tools/rv6-mkfs/Cargo.lock b/tools/rv6-mkfs/Cargo.lock index 7ad7dd52..7102abc6 100644 --- a/tools/rv6-mkfs/Cargo.lock +++ b/tools/rv6-mkfs/Cargo.lock @@ -1,5 +1,11 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" + [[package]] name = "ahci" version = "0.1.0" @@ -36,17 +42,29 @@ dependencies = [ "spin", ] +[[package]] +name = "hashbrown" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf" +dependencies = [ + "ahash", + "autocfg", +] + [[package]] name = "interface" version = "0.1.0" dependencies = [ "bitflags", "byteorder", + "console", + "hashbrown", "libsyscalls", "num-derive", "num-traits", "pci_driver", - "rref", + "spin", "syscalls", "unwind", ] @@ -124,16 +142,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rref" -version = "0.1.0" -dependencies = [ - "console", - "libsyscalls", - "spin", - "syscalls", -] - [[package]] name = "rv6-mkfs" version = "0.1.0"