@@ -100,13 +100,10 @@ impl Instruction {
100100
101101#[ cfg( any( test, fuzzing) ) ]
102102pub mod test_utils {
103- extern crate alloc;
104-
105103 use crate :: cpu:: control_regs:: { CR0Flags , CR4Flags } ;
106104 use crate :: cpu:: efer:: EFERFlags ;
107105 use crate :: insn_decode:: * ;
108106 use crate :: types:: Bytes ;
109- use alloc:: boxed:: Box ;
110107 use zerocopy:: { FromBytes , IntoBytes } ;
111108
112109 pub const TEST_PORT : u16 = 0xE0 ;
@@ -174,12 +171,15 @@ pub mod test_utils {
174171 }
175172 }
176173
174+ #[ derive( Debug , Clone , Copy ) ]
177175 #[ cfg_attr( not( test) , expect( dead_code) ) ]
178- struct TestMem < T > {
176+ pub struct TestMem < T > {
179177 ptr : * mut T ,
180178 }
181179
182180 impl InsnMachineCtx for TestCtx {
181+ type Ptr < T : FromBytes + IntoBytes > = TestMem < T > ;
182+
183183 fn read_efer ( & self ) -> u64 {
184184 self . efer
185185 }
@@ -251,13 +251,13 @@ pub mod test_utils {
251251 self . flags
252252 }
253253
254- fn map_linear_addr < T : FromBytes + IntoBytes + ' static > (
254+ fn map_linear_addr < T : FromBytes + IntoBytes > (
255255 & self ,
256256 la : usize ,
257257 _write : bool ,
258258 _fetch : bool ,
259- ) -> Result < Box < dyn InsnMachineMem < Item = T > > , InsnError > {
260- Ok ( Box :: new ( TestMem { ptr : la as * mut T } ) )
259+ ) -> Result < Self :: Ptr < T > , InsnError > {
260+ Ok ( TestMem { ptr : la as * mut T } )
261261 }
262262
263263 fn ioio_in ( & self , _port : u16 , size : Bytes ) -> Result < u64 , InsnError > {
@@ -345,13 +345,11 @@ pub mod test_utils {
345345 }
346346
347347 #[ cfg( test) ]
348- impl < T : FromBytes + IntoBytes > InsnMachineMem for TestMem < T > {
349- type Item = T ;
350-
348+ impl < T : FromBytes + IntoBytes > InsnMachineMem < T > for TestMem < T > {
351349 /// # Safety
352350 /// The caller is required to ensure the validity of the address
353351 /// this object was initialized with.
354- unsafe fn mem_read ( & self ) -> Result < Self :: Item , InsnError > {
352+ unsafe fn mem_read ( & self ) -> Result < T , InsnError > {
355353 // SAFETY: caller must ensure `ptr` was initialized with a valid
356354 // address.
357355 Ok ( unsafe { self . ptr . read ( ) } )
@@ -360,7 +358,7 @@ pub mod test_utils {
360358 /// # Safety
361359 /// The caller is required to ensure the validity of the address
362360 /// this object was initialized with.
363- unsafe fn mem_write ( & mut self , data : Self :: Item ) -> Result < ( ) , InsnError > {
361+ unsafe fn mem_write ( & mut self , data : T ) -> Result < ( ) , InsnError > {
364362 // SAFETY: caller must ensure `ptr` was initialized with a valid
365363 // address.
366364 unsafe {
@@ -371,12 +369,10 @@ pub mod test_utils {
371369 }
372370
373371 #[ cfg( fuzzing) ]
374- impl < T : FromBytes + IntoBytes > InsnMachineMem for TestMem < T > {
375- type Item = T ;
376-
372+ impl < T : FromBytes + IntoBytes > InsnMachineMem < T > for TestMem < T > {
377373 /// # Safety
378374 /// No safety concerns under fuzzing.
379- unsafe fn mem_write ( & mut self , _data : Self :: Item ) -> Result < ( ) , InsnError > {
375+ unsafe fn mem_write ( & mut self , _data : T ) -> Result < ( ) , InsnError > {
380376 Ok ( ( ) )
381377 }
382378 }
0 commit comments