Skip to content

Commit 80fb106

Browse files
committed
fam_wrappers: Rework doc for len field of XSAVE2
Previous doc of len field of kvm_xsave2 is outdate. Rework it to get it back to work. Signed-off-by: Ruoqing He <[email protected]>
1 parent 407b44e commit 80fb106

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

kvm-bindings/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ zerocopy = { version = "0.8.23", optional = true, features = ["derive"] }
2828

2929
[dev-dependencies]
3030
bincode = {version = "2.0.1", features = ["serde"] }
31+
libc = "0.2.39"
3132
serde_json = "1.0.125"

kvm-bindings/src/x86_64/fam_wrappers.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,26 @@ pub struct kvm_xsave2 {
136136
/// `kvm_xsave` structure, e.g. the sum of header and FAM. Thus, this `len` field
137137
/// is equal to
138138
/// ```no_run
139-
/// (KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) - sizeof::<kvm_xsave>()).div_ceil(sizeof::<__u32>())
139+
/// # use kvm_bindings::{__u32, kvm_xsave, KVM_CAP_XSAVE2};
140+
/// # use libc::{c_char, open, O_RDWR};
141+
/// # use std::fs::File;
142+
/// # use std::os::unix::io::FromRawFd;
143+
/// # use vmm_sys_util::{ioctl::ioctl_with_val, ioctl_io_nr};
144+
/// # const KVM_PATH: &str = "/dev/kvm\0";
145+
/// # const KVMIO: u32 = 0x03;
146+
/// # let kvm_fd = unsafe { open(KVM_PATH.as_ptr() as *const c_char, O_RDWR) };
147+
/// # assert!(kvm_fd >= 0);
148+
/// # ioctl_io_nr!(KVM_CHECK_EXTENSION, KVMIO, 0x03);
149+
///
150+
/// ((unsafe {
151+
/// ioctl_with_val(
152+
/// &File::from_raw_fd(kvm_fd),
153+
/// KVM_CHECK_EXTENSION(),
154+
/// KVM_CAP_XSAVE2.into(),
155+
/// )
156+
/// }) as usize
157+
/// - size_of::<kvm_xsave>())
158+
/// .div_ceil(size_of::<__u32>());
140159
/// ```
141160
pub len: usize,
142161
pub xsave: kvm_xsave,

0 commit comments

Comments
 (0)