rust-vmm / kvm-ioctls

Apache License 2.0
255 stars 103 forks source link

Export reg_size function #234

Closed xuejun-xj closed 10 months ago

xuejun-xj commented 10 months ago

As get_one_reg/set_one_reg uses slice to save the value of register, exporting reg_size function maybe a better way for use of these two ioctls? Users can easily calculate the size of registers and create the specific vector.

/// Helper method to obtain the size of the register through its id
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
fn reg_size(reg_id: u64) -> usize {
    2_usize.pow(((reg_id & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT) as u32)
}

pub fn set_one_reg(&self, reg_id: u64, data: &[u8]) -> Result<usize>;
pub fn get_one_reg(&self, reg_id: u64, data: &mut [u8]) -> Result<usize>
xuejun-xj commented 10 months ago

Hi @roypat , do you think this is a good idea? When I am calling set_one_reg/get_one_reg, I want to known how long the vector should be initialized. Use this helper function can easily do what I want.

andreeaflorescu commented 10 months ago

@xuejun-xj I don't see any problem in making reg_size a public function so that it can be used outside of the crate. Feel free to open a PR with this change.

xuejun-xj commented 10 months ago

@xuejun-xj I don't see any problem in making reg_size a public function so that it can be used outside of the crate. Feel free to open a PR with this change.

Thanks :), @andreeaflorescu . I will open a PR later for it.