@@ -33,29 +33,29 @@ fn copy_range_to_buf(data: &[u8], offset: u64, length: usize, buf: &mut [u8]) ->
3333 copy_to_buf ( data, buf)
3434}
3535
36- fn step_cb ( uc : & mut Unicorn < ( ) > , _addr : u64 , _size : u32 ) {
36+ fn step_cb < T : ' static > ( uc : & mut Unicorn < T > , _addr : u64 , _size : u32 ) {
3737 if * STEP_STATE . get ( ) {
3838 STEP_STATE . replace ( false ) ;
3939 return ;
4040 }
4141 if let Some ( step_hook) = STEP_HOOK . take ( ) {
4242 uc. remove_hook ( step_hook) . expect ( "Failed to remove step hook" ) ;
4343 }
44- crate :: udbserver_resume ( WATCH_ADDR . take ( ) ) . expect ( "Failed to resume udbserver" ) ;
44+ crate :: udbserver_resume :: < T > ( WATCH_ADDR . take ( ) ) . expect ( "Failed to resume udbserver" ) ;
4545}
4646
47- fn watch_cb ( uc : & mut Unicorn < ( ) > , _mem_type : MemType , addr : u64 , _size : usize , _value : i64 ) -> bool {
47+ fn watch_cb < T : ' static > ( uc : & mut Unicorn < T > , _mem_type : MemType , addr : u64 , _size : usize , _value : i64 ) -> bool {
4848 if WATCH_ADDR . is_none ( ) {
4949 WATCH_ADDR . replace ( addr) ;
5050 if STEP_HOOK . is_none ( ) {
51- STEP_HOOK . replace ( uc. add_code_hook ( 1 , 0 , step_cb) . expect ( "Failed to add code hook" ) ) ;
51+ STEP_HOOK . replace ( uc. add_code_hook ( 1 , 0 , step_cb :: < T > ) . expect ( "Failed to add code hook" ) ) ;
5252 }
5353 }
5454 true
5555}
5656
57- pub struct Emu {
58- uc : & ' static mut Unicorn < ' static , ( ) > ,
57+ pub struct Emu < T : ' static > {
58+ uc : & ' static mut Unicorn < ' static , T > ,
5959 reg : Register ,
6060 code_hook : UcHookId ,
6161 mem_hook : UcHookId ,
@@ -66,8 +66,8 @@ pub struct Emu {
6666 wp_rw_hooks : HashMap < u64 , HashMap < u64 , UcHookId > > ,
6767}
6868
69- impl Emu {
70- pub fn new ( uc : & ' static mut Unicorn < ' static , ( ) > , code_hook : UcHookId , mem_hook : UcHookId ) -> DynResult < Emu > {
69+ impl < T : ' static > Emu < T > {
70+ pub fn new ( uc : & ' static mut Unicorn < ' static , T > , code_hook : UcHookId , mem_hook : UcHookId ) -> DynResult < Emu < T > > {
7171 let arch = uc. get_arch ( ) ;
7272 let query_mode = uc. query ( Query :: MODE ) . expect ( "Failed to query mode" ) ;
7373 let mode = Mode :: try_from ( query_mode as i32 ) . unwrap ( ) ;
@@ -86,14 +86,14 @@ impl Emu {
8686 }
8787}
8888
89- impl Drop for Emu {
89+ impl < T : ' static > Drop for Emu < T > {
9090 fn drop ( & mut self ) {
9191 self . uc . remove_hook ( self . code_hook ) . expect ( "Failed to remove empty code hook" ) ;
9292 self . uc . remove_hook ( self . mem_hook ) . expect ( "Failed to remove empty mem hook" ) ;
9393 }
9494}
9595
96- impl target:: Target for Emu {
96+ impl < T : ' static > target:: Target for Emu < T > {
9797 type Arch = arch:: GenericArch ;
9898 type Error = & ' static str ;
9999
@@ -113,7 +113,7 @@ impl target::Target for Emu {
113113 }
114114}
115115
116- impl target:: ext:: base:: singlethread:: SingleThreadBase for Emu {
116+ impl < T : ' static > target:: ext:: base:: singlethread:: SingleThreadBase for Emu < T > {
117117 fn read_registers ( & mut self , regs : & mut arch:: GenericRegs ) -> TargetResult < ( ) , Self > {
118118 regs. buf = Vec :: new ( ) ;
119119 for reg in self . reg . list ( ) {
@@ -166,7 +166,7 @@ impl target::ext::base::singlethread::SingleThreadBase for Emu {
166166 }
167167}
168168
169- impl target:: ext:: base:: singlethread:: SingleThreadResume for Emu {
169+ impl < T : ' static > target:: ext:: base:: singlethread:: SingleThreadResume for Emu < T > {
170170 fn resume ( & mut self , _signal : Option < Signal > ) -> Result < ( ) , Self :: Error > {
171171 Ok ( ( ) )
172172 }
@@ -177,20 +177,20 @@ impl target::ext::base::singlethread::SingleThreadResume for Emu {
177177 }
178178}
179179
180- impl target:: ext:: base:: singlethread:: SingleThreadSingleStep for Emu {
180+ impl < T : ' static > target:: ext:: base:: singlethread:: SingleThreadSingleStep for Emu < T > {
181181 fn step ( & mut self , signal : Option < Signal > ) -> Result < ( ) , Self :: Error > {
182182 if signal. is_some ( ) {
183183 return Err ( "no support for stepping with signal" ) ;
184184 }
185185
186186 STEP_STATE . replace ( true ) ;
187- STEP_HOOK . replace ( self . uc . add_code_hook ( 1 , 0 , step_cb) . map_err ( |_| "Failed to add code hook" ) ?) ;
187+ STEP_HOOK . replace ( self . uc . add_code_hook ( 1 , 0 , step_cb :: < T > ) . map_err ( |_| "Failed to add code hook" ) ?) ;
188188
189189 Ok ( ( ) )
190190 }
191191}
192192
193- impl target:: ext:: breakpoints:: Breakpoints for Emu {
193+ impl < T : ' static > target:: ext:: breakpoints:: Breakpoints for Emu < T > {
194194 #[ inline( always) ]
195195 fn support_sw_breakpoint ( & mut self ) -> Option < target:: ext:: breakpoints:: SwBreakpointOps < ' _ , Self > > {
196196 Some ( self )
@@ -209,15 +209,18 @@ impl target::ext::breakpoints::Breakpoints for Emu {
209209
210210macro_rules! add_breakpoint {
211211 ( $self: ident, $addr: ident, $hook_map: ident ) => { {
212- let hook = match $self. uc. add_code_hook( $addr. into( ) , $addr. into( ) , step_cb) {
212+ let hook = match $self. uc. add_code_hook( $addr. into( ) , $addr. into( ) , step_cb:: < T > ) {
213213 Ok ( h) => h,
214214 Err ( _) => return Ok ( false ) ,
215215 } ;
216216 $self. $hook_map. insert( $addr. into( ) , hook) ;
217217 Ok ( true )
218218 } } ;
219219 ( $self: ident, $mem_type: ident, $addr: ident, $len: ident, $hook_map: ident ) => { {
220- let hook = match $self. uc. add_mem_hook( HookType :: $mem_type, $addr. into( ) , ( $addr + $len - 1 ) . into( ) , watch_cb) {
220+ let hook = match $self
221+ . uc
222+ . add_mem_hook( HookType :: $mem_type, $addr. into( ) , ( $addr + $len - 1 ) . into( ) , watch_cb:: <T >)
223+ {
221224 Ok ( h) => h,
222225 Err ( _) => return Ok ( false ) ,
223226 } ;
@@ -253,7 +256,7 @@ macro_rules! remove_breakpoint {
253256 } } ;
254257}
255258
256- impl target:: ext:: breakpoints:: SwBreakpoint for Emu {
259+ impl < T : ' static > target:: ext:: breakpoints:: SwBreakpoint for Emu < T > {
257260 fn add_sw_breakpoint ( & mut self , addr : u64 , _kind : usize ) -> TargetResult < bool , Self > {
258261 add_breakpoint ! ( self , addr, bp_sw_hooks)
259262 }
@@ -263,7 +266,7 @@ impl target::ext::breakpoints::SwBreakpoint for Emu {
263266 }
264267}
265268
266- impl target:: ext:: breakpoints:: HwBreakpoint for Emu {
269+ impl < T : ' static > target:: ext:: breakpoints:: HwBreakpoint for Emu < T > {
267270 fn add_hw_breakpoint ( & mut self , addr : u64 , _kind : usize ) -> TargetResult < bool , Self > {
268271 add_breakpoint ! ( self , addr, bp_hw_hooks)
269272 }
@@ -273,7 +276,7 @@ impl target::ext::breakpoints::HwBreakpoint for Emu {
273276 }
274277}
275278
276- impl target:: ext:: breakpoints:: HwWatchpoint for Emu {
279+ impl < T : ' static > target:: ext:: breakpoints:: HwWatchpoint for Emu < T > {
277280 fn add_hw_watchpoint ( & mut self , addr : u64 , len : u64 , kind : WatchKind ) -> TargetResult < bool , Self > {
278281 match kind {
279282 WatchKind :: Read => add_breakpoint ! ( self , MEM_READ , addr, len, wp_r_hooks) ,
@@ -291,7 +294,7 @@ impl target::ext::breakpoints::HwWatchpoint for Emu {
291294 }
292295}
293296
294- impl target:: ext:: base:: single_register_access:: SingleRegisterAccess < ( ) > for Emu {
297+ impl < T : ' static > target:: ext:: base:: single_register_access:: SingleRegisterAccess < ( ) > for Emu < T > {
295298 fn read_register ( & mut self , _tid : ( ) , reg_id : arch:: GenericRegId , buf : & mut [ u8 ] ) -> TargetResult < usize , Self > {
296299 let reg = self . reg . get ( reg_id. 0 ) ?;
297300 if reg. 1 <= 8 {
@@ -323,7 +326,7 @@ impl target::ext::base::single_register_access::SingleRegisterAccess<()> for Emu
323326 }
324327}
325328
326- impl target:: ext:: target_description_xml_override:: TargetDescriptionXmlOverride for Emu {
329+ impl < T : ' static > target:: ext:: target_description_xml_override:: TargetDescriptionXmlOverride for Emu < T > {
327330 fn target_description_xml ( & self , _annex : & [ u8 ] , offset : u64 , length : usize , buf : & mut [ u8 ] ) -> TargetResult < usize , Self > {
328331 let xml = self . reg . description_xml ( ) . as_bytes ( ) ;
329332 Ok ( copy_range_to_buf ( xml, offset, length, buf) )
0 commit comments