11use core:: ptr;
22
3- use memory_addresses:: VirtAddr ;
4- use uhyve_interface:: parameters:: { ExitParams , SerialWriteBufferParams } ;
5- use uhyve_interface:: { Hypercall , HypercallAddress } ;
3+ use memory_addresses:: { PhysAddr , VirtAddr } ;
4+ use uhyve_interface:: v2 :: parameters:: { ExitParams , SerialWriteBufferParams } ;
5+ use uhyve_interface:: v2 :: { Hypercall , HypercallAddress } ;
66
77use crate :: arch;
88use crate :: arch:: mm:: paging:: { self , virtual_to_physical} ;
99use crate :: syscalls:: interfaces:: SyscallInterface ;
1010
11- /// perform a SerialWriteBuffer hypercall with `buf` as payload.
11+ /// perform a SerialWriteBuffer hypercall with `buf` as payload
1212#[ inline]
1313#[ cfg_attr( target_arch = "riscv64" , expect( dead_code) ) ]
1414pub ( crate ) fn serial_buf_hypercall ( buf : & [ u8 ] ) {
@@ -31,9 +31,7 @@ fn data_addr<T>(data: &T) -> u64 {
3131#[ inline]
3232fn hypercall_data ( hypercall : & Hypercall < ' _ > ) -> u64 {
3333 match hypercall {
34- Hypercall :: Cmdsize ( data) => data_addr ( * data) ,
35- Hypercall :: Cmdval ( data) => data_addr ( * data) ,
36- Hypercall :: Exit ( data) => data_addr ( * data) ,
34+ Hypercall :: Exit ( exit_code) => u64:: try_from ( * exit_code) . unwrap ( ) ,
3735 Hypercall :: FileClose ( data) => data_addr ( * data) ,
3836 Hypercall :: FileLseek ( data) => data_addr ( * data) ,
3937 Hypercall :: FileOpen ( data) => data_addr ( * data) ,
@@ -50,24 +48,21 @@ fn hypercall_data(hypercall: &Hypercall<'_>) -> u64 {
5048#[ inline]
5149#[ allow( unused_variables) ] // until riscv64 is implemented
5250pub ( crate ) fn uhyve_hypercall ( hypercall : Hypercall < ' _ > ) {
53- let ptr = HypercallAddress :: from ( & hypercall) as u16 ;
51+ let mut ptr = HypercallAddress :: from ( & hypercall) as u64 ;
5452 let data = hypercall_data ( & hypercall) ;
5553
5654 #[ cfg( target_arch = "x86_64" ) ]
57- unsafe {
58- use x86_64:: instructions:: port:: Port ;
59-
60- let data =
61- u32:: try_from ( data) . expect ( "Hypercall data must lie in the first 4GiB of memory" ) ;
62- Port :: new ( ptr) . write ( data) ;
55+ {
56+ let ptr = ptr as * mut u64 ;
57+ unsafe { ptr. write_volatile ( data) } ;
6358 }
6459
6560 #[ cfg( target_arch = "aarch64" ) ]
6661 unsafe {
6762 use core:: arch:: asm;
6863 asm ! (
6964 "str x8, [{ptr}]" ,
70- ptr = in( reg) u64 :: from ( ptr) ,
65+ ptr = in( reg) ptr,
7166 in( "x8" ) data,
7267 options( nostack) ,
7368 ) ;
@@ -82,7 +77,7 @@ pub struct Uhyve;
8277impl SyscallInterface for Uhyve {
8378 fn shutdown ( & self , error_code : i32 ) -> ! {
8479 let sysexit = ExitParams { arg : error_code } ;
85- uhyve_hypercall ( Hypercall :: Exit ( & sysexit ) ) ;
80+ uhyve_hypercall ( Hypercall :: Exit ( error_code ) ) ;
8681
8782 loop {
8883 arch:: processor:: halt ( ) ;
0 commit comments