@@ -147,7 +147,7 @@ pub enum VcpuExit<'a> {
147
147
/// Corresponds to KVM_EXIT_EPR.
148
148
Epr ,
149
149
/// Corresponds to KVM_EXIT_SYSTEM_EVENT.
150
- SystemEvent ( u32 /* type */ , u64 /* flags */ ) ,
150
+ SystemEvent ( u32 /* type */ , & ' a [ u64 ] /* data */ ) ,
151
151
/// Corresponds to KVM_EXIT_S390_STSI.
152
152
S390Stsi ,
153
153
/// Corresponds to KVM_EXIT_IOAPIC_EOI.
@@ -1533,10 +1533,10 @@ impl VcpuFd {
1533
1533
// SAFETY: Safe because the exit_reason (which comes from the kernel) told us
1534
1534
// which union field to use.
1535
1535
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 ) )
1540
1540
}
1541
1541
KVM_EXIT_S390_STSI => Ok ( VcpuExit :: S390Stsi ) ,
1542
1542
KVM_EXIT_IOAPIC_EOI => {
@@ -2345,9 +2345,9 @@ mod tests {
2345
2345
. sum ( ) ;
2346
2346
assert_eq ! ( dirty_pages, 1 ) ;
2347
2347
}
2348
- VcpuExit :: SystemEvent ( type_, flags ) => {
2348
+ VcpuExit :: SystemEvent ( type_, data ) => {
2349
2349
assert_eq ! ( type_, KVM_SYSTEM_EVENT_SHUTDOWN ) ;
2350
- assert_eq ! ( flags , 0 ) ;
2350
+ assert_eq ! ( data [ 0 ] , 0 ) ;
2351
2351
break ;
2352
2352
}
2353
2353
r => panic ! ( "unexpected exit reason: {:?}" , r) ,
@@ -2723,11 +2723,14 @@ mod tests {
2723
2723
// not allocated memory, so the first time it fails.
2724
2724
let err = vcpu. get_reg_list ( & mut reg_list) . unwrap_err ( ) ;
2725
2725
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 ) ;
2727
2728
2728
2729
// We make use of the number of registers returned to allocate memory and
2729
2730
// 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 ( ) ;
2731
2734
assert ! ( vcpu. get_reg_list( & mut reg_list) . is_ok( ) ) ;
2732
2735
}
2733
2736
0 commit comments