@@ -72,7 +72,7 @@ pub struct GuestContext {
7272 g2h_producer : G2hProducer ,
7373 h2g_producer : H2gProducer ,
7474 generation : u16 ,
75- last_host_return : Option < ReturnValue > ,
75+ last_host_result : Option < Result < ReturnValue > > ,
7676}
7777
7878impl GuestContext {
@@ -101,7 +101,7 @@ impl GuestContext {
101101 g2h_producer,
102102 h2g_producer,
103103 generation,
104- last_host_return : None ,
104+ last_host_result : None ,
105105 } ;
106106
107107 ctx. prefill_h2g ( ) ;
@@ -309,6 +309,7 @@ impl GuestContext {
309309 // restore_h2g_prefill() wrote matching descriptors to the
310310 // zeroed ring memory. Both sides are in sync.
311311 self . generation = new_generation;
312+ self . last_host_result = None ;
312313 }
313314
314315 pub ( super ) fn generation ( & self ) -> u16 {
@@ -346,24 +347,27 @@ impl GuestContext {
346347 self . g2h_producer . submit ( entry)
347348 }
348349
349- /// Stash a host function return value for later retrieval.
350+ /// Stash a host function result for later retrieval.
350351 ///
351352 /// Used by the C API's two-step calling convention where
352353 /// `hl_call_host_function` and `hl_get_host_return_value_as_*`
353354 /// are separate calls.
354- pub fn stash_host_return ( & mut self , value : ReturnValue ) {
355- self . last_host_return = Some ( value ) ;
355+ pub fn stash_host_result ( & mut self , result : Result < ReturnValue > ) {
356+ self . last_host_result = Some ( result ) ;
356357 }
357358
358359 /// Take the stashed host return value.
359360 ///
360361 /// Panics if no value was stashed or if the type conversion fails.
362+ /// If the stashed result was an error, panics with the error message.
361363 pub fn take_host_return < T : TryFrom < ReturnValue > > ( & mut self ) -> T {
362- let rv = self
363- . last_host_return
364+ let val = self
365+ . last_host_result
364366 . take ( )
365- . expect ( "No host return value available" ) ;
366- match T :: try_from ( rv) {
367+ . expect ( "No host return value available" )
368+ . expect ( "Host function returned an error" ) ;
369+
370+ match T :: try_from ( val) {
367371 Ok ( v) => v,
368372 Err ( _) => panic ! ( "Host return value type mismatch" ) ,
369373 }
0 commit comments