@@ -14,10 +14,8 @@ use crate::PEB;
14
14
/// This usually requires a host function to be called first using `call_host_function`.
15
15
pub fn get_host_return_value < T : TryFrom < ReturnValue > > ( ) -> Result < T > {
16
16
let input_data_section: InputDataSection =
17
- unsafe { ( * PEB ) . clone ( ) } . get_input_data_region ( ) . into ( ) ;
18
- let return_value = input_data_section
19
- . try_pop_shared_input_data_into :: < ReturnValue > ( )
20
- . expect ( "Unable to deserialize a return value from host" ) ;
17
+ unsafe { ( * PEB ) . clone ( ) } . get_input_data_region ( ) ?. into ( ) ;
18
+ let return_value = input_data_section. try_pop_shared_input_data_into :: < ReturnValue > ( ) ?;
21
19
22
20
T :: try_from ( return_value) . map_err ( |_| {
23
21
anyhow:: anyhow!(
@@ -42,24 +40,22 @@ pub fn call_host_function(
42
40
return_type,
43
41
) ;
44
42
45
- let host_function_call_buffer: Vec < u8 > = host_function_call
46
- . try_into ( )
47
- . expect ( "Unable to serialize host function call" ) ;
43
+ let host_function_call_buffer: Vec < u8 > = host_function_call. try_into ( ) ?;
48
44
49
45
let output_data_section: OutputDataSection =
50
- unsafe { ( * PEB ) . clone ( ) } . get_output_data_region ( ) . into ( ) ;
46
+ unsafe { ( * PEB ) . clone ( ) } . get_output_data_region ( ) ? . into ( ) ;
51
47
output_data_section. push_shared_output_data ( host_function_call_buffer) ?;
52
48
53
- outb ( OutBAction :: CallFunction as u16 , 0 ) ;
54
-
55
- Ok ( ( ) )
49
+ outb ( OutBAction :: CallFunction as u16 , 0 )
56
50
}
57
51
58
52
/// Uses `hloutb` to issue multiple `DebugPrint` `OutBAction`s to print a message.
59
- pub fn print ( message : & str ) {
53
+ pub fn print ( message : & str ) -> Result < ( ) > {
60
54
for byte in message. bytes ( ) {
61
- outb ( OutBAction :: DebugPrint as u16 , byte) ;
55
+ outb ( OutBAction :: DebugPrint as u16 , byte) ? ;
62
56
}
57
+
58
+ Ok ( ( ) )
63
59
}
64
60
65
61
/// Exposes a C API to allow the guest to print a string, byte by byte
@@ -68,5 +64,6 @@ pub fn print(message: &str) {
68
64
/// This function is not thread safe and assumes `outb` is safe to call directly.
69
65
#[ no_mangle]
70
66
pub unsafe extern "C" fn _putchar ( c : c_char ) {
71
- outb ( OutBAction :: DebugPrint as u16 , c as u8 ) ;
67
+ #[ allow( clippy:: expect_used) ] // allow `expect` over C API functions
68
+ outb ( OutBAction :: DebugPrint as u16 , c as u8 ) . expect ( "Failed to print character" ) ;
72
69
}
0 commit comments