fn cmdval(&self, args_ptr: usize) {
		let syscmdval = unsafe { &*(args_ptr as *const SysCmdval) };

		let mut counter: i32 = 0;
		let argv = self.host_address(syscmdval.argv as usize);
		let mut found_separator = false;
		let mut separator_pos: i32 = 0;

		// copy kernel path as first argument
		{
			let path = self.kernel_path().as_os_str();

			let argvptr = unsafe { self.host_address(*(argv as *mut *mut u8) as usize) };
			let len = path.len();
			let slice = unsafe { slice::from_raw_parts_mut(argvptr as *mut u8, len + 1) };

			// Create string for environment variable
			slice[0..len].copy_from_slice(path.as_bytes());
			slice[len] = 0;
		}

		// Copy the application arguments into the vm memory
		for argument in std::env::args() {
			if !found_separator && argument == "--" {
				separator_pos = counter + 1;
				found_separator = true;
			}

			if found_separator && counter >= separator_pos {
				let argvptr = unsafe {
					self.host_address(
						*((argv + (counter - separator_pos + 1) as usize * mem::size_of::<usize>())
							as *mut *mut u8) as usize,
					)
				};
				let len = argument.len();
				let slice = unsafe { slice::from_raw_parts_mut(argvptr as *mut u8, len + 1) };

				// Create string for environment variable
				slice[0..len].copy_from_slice(argument.as_bytes());
				slice[len] = 0;
			}

			counter += 1;
		}

		// Copy the environment variables into the vm memory
		counter = 0;
		let envp = self.host_address(syscmdval.envp as usize);
		for (key, value) in std::env::vars() {
			if counter < MAX_ENVC.try_into().unwrap() {
				let envptr = unsafe {
					self.host_address(
						*((envp + counter as usize * mem::size_of::<usize>()) as *mut *mut u8)
							as usize,
					)
				};
				let len = key.len() + value.len();
				let slice = unsafe { slice::from_raw_parts_mut(envptr as *mut u8, len + 2) };

				// Create string for environment variable
				slice[0..key.len()].copy_from_slice(key.as_bytes());
				slice[key.len()..(key.len() + 1)].copy_from_slice("=".as_bytes());
				slice[(key.len() + 1)..(len + 1)].copy_from_slice(value.as_bytes());
				slice[len + 1] = 0;
				counter += 1;
			}
		}
	}
/// Copies the arguments end environment of the application into the VM's memory.
Copies the arguments end environment of the application into the VM's memory.
Copies the arguments end environment of the application into the VM ' s memory .
fn cmdval(&self, args_ptr: usize) {
		let syscmdval = unsafe { &*(args_ptr as *const SysCmdval) };
		let mut counter: i32 = 0;
		let argv = self.host_address(syscmdval.argv as usize);
		let mut found_separator = false;
		let mut separator_pos: i32 = 0;
		// copy kernel path as first argument
		{
			let path = self.kernel_path().as_os_str();
			let argvptr = unsafe { self.host_address(*(argv as *mut *mut u8) as usize) };
			let len = path.len();
			let slice = unsafe { slice::from_raw_parts_mut(argvptr as *mut u8, len + 1) };
			// Create string for environment variable
			slice[0..len].copy_from_slice(path.as_bytes());
			slice[len] = 0;
		}
		// Copy the application arguments into the vm memory
		for argument in std::env::args() {
			if !found_separator && argument == "--" {
				separator_pos = counter + 1;
				found_separator = true;
			}
			if found_separator && counter >= separator_pos {
				let argvptr = unsafe {
					self.host_address(
						*((argv + (counter - separator_pos + 1) as usize * mem::size_of::<usize>())
							as *mut *mut u8) as usize,
					)
				};
				let len = argument.len();
				let slice = unsafe { slice::from_raw_parts_mut(argvptr as *mut u8, len + 1) };
				// Create string for environment variable
				slice[0..len].copy_from_slice(argument.as_bytes());
				slice[len] = 0;
			}
			counter += 1;
		}
		// Copy the environment variables into the vm memory
		counter = 0;
		let envp = self.host_address(syscmdval.envp as usize);
		for (key, value) in std::env::vars() {
			if counter < MAX_ENVC.try_into().unwrap() {
				let envptr = unsafe {
					self.host_address(
						*((envp + counter as usize * mem::size_of::<usize>()) as *mut *mut u8)
							as usize,
					)
				};
				let len = key.len() + value.len();
				let slice = unsafe { slice::from_raw_parts_mut(envptr as *mut u8, len + 2) };
				// Create string for environment variable
				slice[0..key.len()].copy_from_slice(key.as_bytes());
				slice[key.len()..(key.len() + 1)].copy_from_slice("=".as_bytes());
				slice[(key.len() + 1)..(len + 1)].copy_from_slice(value.as_bytes());
				slice[len + 1] = 0;
				counter += 1;
			}
		}
	}
fn cmdval ( & self , args_ptr : usize ) { let syscmdval = unsafe { & * ( args_ptr as * const SysCmdval ) } ; let mut counter : i32 = 0 ; let argv = self . host_address ( syscmdval . argv as usize ) ; let mut found_separator = false ; let mut separator_pos : i32 = 0 ; // copy kernel path as first argument { let path = self . kernel_path ( ) . as_os_str ( ) ; let argvptr = unsafe { self . host_address ( * ( argv as * mut * mut u8 ) as usize ) } ; let len = path . len ( ) ; let slice = unsafe { slice :: from_raw_parts_mut ( argvptr as * mut u8 , len + 1 ) } ; // Create string for environment variable slice [ 0 .. len ] . copy_from_slice ( path . as_bytes ( ) ) ; slice [ len ] = 0 ; } // Copy the application arguments into the vm memory for argument in std :: env :: args ( ) { if ! found_separator && argument == " " { separator_pos = counter + 1 ; found_separator = true ; } if found_separator && counter >= separator_pos { let argvptr = unsafe { self . host_address ( * ( ( argv + ( counter - separator_pos + 1 ) as usize * mem :: size_of :: < usize > ( ) ) as * mut * mut u8 ) as usize , ) } ; let len = argument . len ( ) ; let slice = unsafe { slice :: from_raw_parts_mut ( argvptr as * mut u8 , len + 1 ) } ; // Create string for environment variable slice [ 0 .. len ] . copy_from_slice ( argument . as_bytes ( ) ) ; slice [ len ] = 0 ; } counter += 1 ; } // Copy the environment variables into the vm memory counter = 0 ; let envp = self . host_address ( syscmdval . envp as usize ) ; for ( key , value ) in std :: env :: vars ( ) { if counter < MAX_ENVC . try_into ( ) . unwrap ( ) { let envptr = unsafe { self . host_address ( * ( ( envp + counter as usize * mem :: size_of :: < usize > ( ) ) as * mut * mut u8 ) as usize , ) } ; let len = key . len ( ) + value . len ( ) ; let slice = unsafe { slice :: from_raw_parts_mut ( envptr as * mut u8 , len + 2 ) } ; // Create string for environment variable slice [ 0 .. key . len ( ) ] . copy_from_slice ( key . as_bytes ( ) ) ; slice [ key . len ( ) .. ( key . len ( ) + 1 ) ] . copy_from_slice ( " " . as_bytes ( ) ) ; slice [ ( key . len ( ) + 1 ) .. ( len + 1 ) ] . copy_from_slice ( value . as_bytes ( ) ) ; slice [ len + 1 ] = 0 ; counter += 1 ; } } }
Copies the arguments end environment of the application into the VM's memory.
Copies the arguments end environment of the application into the VM ' s memory .
&self
args_ptr
usize
&self
args_ptr
usize