File tree Expand file tree Collapse file tree 1 file changed +9
-18
lines changed
src/vm-vcpu-ref/src/x86_64 Expand file tree Collapse file tree 1 file changed +9
-18
lines changed Original file line number Diff line number Diff line change 55// Use of this source code is governed by a BSD-style license that can be
66// found in the THIRD-PARTY file.
77
8- use std:: io;
98use std:: mem;
109use std:: result;
1110use std:: slice;
@@ -190,7 +189,8 @@ impl MpTable {
190189 let mut checksum: u8 = 0 ;
191190 let max_ioapic_id = self . cpu_num + 1 ;
192191
193- mem. read_from ( base_mp, & mut io:: repeat ( 0 ) , mp_size)
192+ let zero_slice: Vec < u8 > = ( 0 ..mp_size) . map ( |_| 0u8 ) . collect ( ) ;
193+ mem. write_slice ( zero_slice. as_slice ( ) , base_mp)
194194 . map_err ( |_| Error :: Clear ) ?;
195195
196196 {
@@ -405,23 +405,14 @@ mod tests {
405405 let mpc_offset = GuestAddress ( u64:: from ( mpf_intel. 0 . physptr ) ) ;
406406 let mpc_table: MpcTable = mem. read_obj ( mpc_offset) . unwrap ( ) ;
407407
408- struct Sum ( u8 ) ;
409- impl io:: Write for Sum {
410- fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
411- for v in buf. iter ( ) {
412- self . 0 = self . 0 . wrapping_add ( * v) ;
413- }
414- Ok ( buf. len ( ) )
415- }
416- fn flush ( & mut self ) -> io:: Result < ( ) > {
417- Ok ( ( ) )
418- }
419- }
420-
421- let mut sum = Sum ( 0 ) ;
422- mem. write_to ( mpc_offset, & mut sum, mpc_table. 0 . length as usize )
408+ let mut mpc_table: Vec < u8 > = ( 0 ..mpc_table. 0 . length ) . map ( |_| 0u8 ) . collect ( ) ;
409+ mem. read_slice ( mpc_table. as_mut_slice ( ) , mpc_offset)
423410 . unwrap ( ) ;
424- assert_eq ! ( sum. 0 , 0 ) ;
411+ let mut csum: u8 = 0 ;
412+ mpc_table
413+ . iter ( )
414+ . for_each ( |byte| csum = csum. wrapping_add ( * byte) ) ;
415+ assert_eq ! ( csum, 0 ) ;
425416 }
426417
427418 #[ test]
You can’t perform that action at this time.
0 commit comments