Skip to content

Commit

Permalink
mshv-ioctls: update get_regs to use register page
Browse files Browse the repository at this point in the history
Signed-off-by: Muminul Islam <[email protected]>
  • Loading branch information
russell-islam committed Jan 12, 2025
1 parent 7191d33 commit e42898d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mshv-bindings/src/x86_64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,18 @@ macro_rules! set_gp_regs_field_ptr {
};
}

#[macro_export]
macro_rules! get_gp_regs_field_ptr {
($this: ident, $name: ident) => {
(*$this)
.__bindgen_anon_1
.__bindgen_anon_1
.__bindgen_anon_1
.__bindgen_anon_1
.$name
};
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
31 changes: 31 additions & 0 deletions mshv-ioctls/src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,36 @@ impl VcpuFd {
Ok(())
}

/// Returns the vCPU general purpose registers using VP register page
#[cfg(not(target_arch = "aarch64"))]
pub fn get_vp_page_standard_regs(&self) -> Result<StandardRegisters> {
let vp_reg_page = self.get_vp_reg_page();
let mut ret_regs = StandardRegisters::default();
// SAFETY: access union fields
unsafe {
ret_regs.rax = get_gp_regs_field_ptr!(vp_reg_page, rax);
ret_regs.rbx = get_gp_regs_field_ptr!(vp_reg_page, rbx);
ret_regs.rcx = get_gp_regs_field_ptr!(vp_reg_page, rcx);
ret_regs.rdx = get_gp_regs_field_ptr!(vp_reg_page, rdx);
ret_regs.rsi = get_gp_regs_field_ptr!(vp_reg_page, rsi);
ret_regs.rdi = get_gp_regs_field_ptr!(vp_reg_page, rdi);
ret_regs.rsp = get_gp_regs_field_ptr!(vp_reg_page, rsp);
ret_regs.rbp = get_gp_regs_field_ptr!(vp_reg_page, rbp);
ret_regs.r8 = get_gp_regs_field_ptr!(vp_reg_page, r8);
ret_regs.r9 = get_gp_regs_field_ptr!(vp_reg_page, r9);
ret_regs.r10 = get_gp_regs_field_ptr!(vp_reg_page, r10);
ret_regs.r11 = get_gp_regs_field_ptr!(vp_reg_page, r11);
ret_regs.r12 = get_gp_regs_field_ptr!(vp_reg_page, r12);
ret_regs.r13 = get_gp_regs_field_ptr!(vp_reg_page, r13);
ret_regs.r14 = get_gp_regs_field_ptr!(vp_reg_page, r14);
ret_regs.r15 = get_gp_regs_field_ptr!(vp_reg_page, r15);
ret_regs.rip = (*vp_reg_page).__bindgen_anon_1.__bindgen_anon_1.rip;
ret_regs.rflags = (*vp_reg_page).__bindgen_anon_1.__bindgen_anon_1.rflags;
}

Ok(ret_regs)
}

/// Returns the vCPU general purpose registers.
#[cfg(not(target_arch = "aarch64"))]
pub fn get_regs(&self) -> Result<StandardRegisters> {
Expand Down Expand Up @@ -353,6 +383,7 @@ impl VcpuFd {

Ok(ret_regs)
}

/// Returns the vCPU special registers.
#[cfg(not(target_arch = "aarch64"))]
pub fn get_sregs(&self) -> Result<SpecialRegisters> {
Expand Down

0 comments on commit e42898d

Please sign in to comment.