@@ -18,39 +18,34 @@ use std::sync::{Arc, Mutex};
1818
1919use tracing:: { Span , instrument} ;
2020
21+ use crate :: mem:: shared_mem:: HostSharedMemory ;
22+ use crate :: sandbox:: host_funcs:: FunctionRegistry ;
23+ use crate :: sandbox:: mem_mgr:: MemMgrWrapper ;
2124use crate :: { Result , new_error} ;
2225
23- /// Type alias for the function that handles outb operations
24- type OutBHandlerFunction = Box < dyn FnMut ( u16 , u32 ) -> Result < ( ) > + Send > ;
25-
26- /// A `OutBHandler` implementation using a function closure
26+ /// A `OutBHandler` implementation that holds the memory manager and function registry directly
2727///
2828/// Note: This handler must live no longer than the `Sandbox` to which it belongs
2929pub ( crate ) struct OutBHandler {
30- func : Arc < Mutex < OutBHandlerFunction > > ,
30+ mem_mgr : MemMgrWrapper < HostSharedMemory > ,
31+ host_funcs : Arc < Mutex < FunctionRegistry > > ,
3132}
3233
3334impl OutBHandler {
34- pub fn new ( func : OutBHandlerFunction ) -> Self {
35+ pub fn new (
36+ mem_mgr : MemMgrWrapper < HostSharedMemory > ,
37+ host_funcs : Arc < Mutex < FunctionRegistry > > ,
38+ ) -> Self {
3539 Self {
36- func : Arc :: new ( Mutex :: new ( func) ) ,
40+ mem_mgr,
41+ host_funcs,
3742 }
3843 }
3944
4045 #[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
41- pub fn handle_outb ( & self , port : u16 , payload : u32 ) -> Result < ( ) > {
42- let mut func = self
43- . func
44- . try_lock ( )
45- . map_err ( |e| new_error ! ( "Error locking at {}:{}: {}" , file!( ) , line!( ) , e) ) ?;
46- func ( port, payload)
47- }
48- }
49-
50- impl From < OutBHandlerFunction > for OutBHandler {
51- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
52- fn from ( func : OutBHandlerFunction ) -> Self {
53- Self :: new ( func)
46+ pub fn handle_outb ( & mut self , port : u16 , payload : u32 ) -> Result < ( ) > {
47+ // Call the handle_outb function directly
48+ crate :: sandbox:: outb:: handle_outb ( & mut self . mem_mgr , self . host_funcs . clone ( ) , port, payload)
5449 }
5550}
5651
0 commit comments