@@ -147,7 +147,7 @@ pub enum VcpuExit<'a> {
147147 /// Corresponds to KVM_EXIT_EPR.
148148 Epr ,
149149 /// Corresponds to KVM_EXIT_SYSTEM_EVENT.
150- SystemEvent ( u32 /* type */ , u64 /* flags */ ) ,
150+ SystemEvent ( u32 /* type */ , & ' a [ u64 ] /* data */ ) ,
151151 /// Corresponds to KVM_EXIT_S390_STSI.
152152 S390Stsi ,
153153 /// Corresponds to KVM_EXIT_IOAPIC_EOI.
@@ -1533,10 +1533,10 @@ impl VcpuFd {
15331533 // SAFETY: Safe because the exit_reason (which comes from the kernel) told us
15341534 // which union field to use.
15351535 let system_event = unsafe { & mut run. __bindgen_anon_1 . system_event } ;
1536- Ok ( VcpuExit :: SystemEvent (
1537- system_event . type_ ,
1538- system_event. flags ,
1539- ) )
1536+ let ndata = system_event . ndata ;
1537+ // SAFETY: Safe because we only populate with valid data (based on ndata)
1538+ let data = unsafe { & system_event. __bindgen_anon_1 . data [ 0 ..ndata as usize ] } ;
1539+ Ok ( VcpuExit :: SystemEvent ( system_event . type_ , data ) )
15401540 }
15411541 KVM_EXIT_S390_STSI => Ok ( VcpuExit :: S390Stsi ) ,
15421542 KVM_EXIT_IOAPIC_EOI => {
@@ -2345,9 +2345,9 @@ mod tests {
23452345 . sum ( ) ;
23462346 assert_eq ! ( dirty_pages, 1 ) ;
23472347 }
2348- VcpuExit :: SystemEvent ( type_, flags ) => {
2348+ VcpuExit :: SystemEvent ( type_, data ) => {
23492349 assert_eq ! ( type_, KVM_SYSTEM_EVENT_SHUTDOWN ) ;
2350- assert_eq ! ( flags , 0 ) ;
2350+ assert_eq ! ( data [ 0 ] , 0 ) ;
23512351 break ;
23522352 }
23532353 r => panic ! ( "unexpected exit reason: {:?}" , r) ,
@@ -2723,11 +2723,14 @@ mod tests {
27232723 // not allocated memory, so the first time it fails.
27242724 let err = vcpu. get_reg_list ( & mut reg_list) . unwrap_err ( ) ;
27252725 assert ! ( err. errno( ) == libc:: E2BIG ) ;
2726- assert ! ( reg_list. as_mut_fam_struct( ) . n > 0 ) ;
2726+ // SAFETY: This structure is a result from a specific vCPU ioctl
2727+ assert ! ( unsafe { reg_list. as_mut_fam_struct( ) } . n > 0 ) ;
27272728
27282729 // We make use of the number of registers returned to allocate memory and
27292730 // try one more time.
2730- let mut reg_list = RegList :: new ( reg_list. as_mut_fam_struct ( ) . n as usize ) . unwrap ( ) ;
2731+ // SAFETY: This structure is a result from a specific vCPU ioctl
2732+ let mut reg_list =
2733+ RegList :: new ( unsafe { reg_list. as_mut_fam_struct ( ) } . n as usize ) . unwrap ( ) ;
27312734 assert ! ( vcpu. get_reg_list( & mut reg_list) . is_ok( ) ) ;
27322735 }
27332736
0 commit comments