@@ -328,34 +328,6 @@ impl GuestMemory {
328328 } )
329329 }
330330
331- /// Convert a GuestAddress into a pointer in the address space of this
332- /// process. This should only be necessary for giving addresses to the
333- /// kernel, as with vhost ioctls. Normal reads/writes to guest memory should
334- /// be done through `write_from_memory`, `read_obj_from_addr`, etc.
335- ///
336- /// # Arguments
337- /// * `guest_addr` - Guest address to convert.
338- ///
339- /// # Examples
340- ///
341- /// ```
342- /// # use sys_util::{GuestAddress, GuestMemory};
343- /// # fn test_host_addr() -> Result<(), ()> {
344- /// let start_addr = GuestAddress(0x1000);
345- /// let mut gm = GuestMemory::new(&vec![(start_addr, 0x500)]).map_err(|_| ())?;
346- /// let addr = gm.get_host_address(GuestAddress(0x1200)).unwrap();
347- /// println!("Host address is {:p}", addr);
348- /// Ok(())
349- /// # }
350- /// ```
351- pub fn get_host_address ( & self , guest_addr : GuestAddress ) -> Result < * const u8 > {
352- self . do_in_region ( guest_addr, |mapping, offset| {
353- // This is safe; `do_in_region` already checks that offset is in
354- // bounds.
355- Ok ( unsafe { mapping. as_ptr ( ) . offset ( offset as isize ) } as * const u8 )
356- } )
357- }
358-
359331 pub fn do_in_region < F , T > ( & self , guest_addr : GuestAddress , cb : F ) -> Result < T >
360332 where
361333 F : FnOnce ( & MemoryMapping , usize ) -> Result < T > ,
@@ -462,31 +434,6 @@ mod tests {
462434 assert_eq ! ( val2, num2) ;
463435 }
464436
465- // Get the base address of the mapping for a GuestAddress.
466- fn get_mapping ( mem : & GuestMemory , addr : GuestAddress ) -> Result < * const u8 > {
467- mem. do_in_region ( addr, |mapping, _| Ok ( mapping. as_ptr ( ) as * const u8 ) )
468- }
469-
470- #[ test]
471- fn guest_to_host ( ) {
472- let start_addr1 = GuestAddress ( 0x0 ) ;
473- let start_addr2 = GuestAddress ( 0x100 ) ;
474- let mem = GuestMemory :: new ( & vec ! [ ( start_addr1, 0x100 ) , ( start_addr2, 0x400 ) ] ) . unwrap ( ) ;
475-
476- // Verify the host addresses match what we expect from the mappings.
477- let addr1_base = get_mapping ( & mem, start_addr1) . unwrap ( ) ;
478- let addr2_base = get_mapping ( & mem, start_addr2) . unwrap ( ) ;
479- let host_addr1 = mem. get_host_address ( start_addr1) . unwrap ( ) ;
480- let host_addr2 = mem. get_host_address ( start_addr2) . unwrap ( ) ;
481- assert_eq ! ( host_addr1, addr1_base) ;
482- assert_eq ! ( host_addr2, addr2_base) ;
483-
484- // Check that a bad address returns an error.
485- let bad_addr = GuestAddress ( 0x123456 ) ;
486- assert ! ( mem. get_host_address( bad_addr) . is_err( ) ) ;
487- format ! ( "{:?}" , mem. get_host_address( bad_addr) ) ;
488- }
489-
490437 #[ test]
491438 fn write_and_read_slice ( ) {
492439 let start_addr = GuestAddress ( 0x1000 ) ;
0 commit comments