Skip to content

Commit d0cb6fd

Browse files
authored
Last minute fixes for version 0.1.0 (#24)
* refactor: simplify unsafe blocks in VMX entry and exit functions * feat: add rust-toolchain configuration file
1 parent f9e91e4 commit d0cb6fd

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

rust-toolchain.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[toolchain]
2+
profile = "minimal"
3+
channel = "nightly-2025-05-20"
4+
components = ["rust-src", "llvm-tools", "rustfmt", "clippy"]
5+
targets = [
6+
"x86_64-unknown-none",
7+
]

src/vmx/vcpu.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -876,19 +876,17 @@ impl<H: AxVCpuHal> VmxVcpu<H> {
876876
/// Get ready then vmlaunch or vmresume.
877877
macro_rules! vmx_entry_with {
878878
($instr:literal) => {
879-
unsafe {
880-
naked_asm!(
881-
save_regs_to_stack!(), // save host status
882-
"mov [rdi + {host_stack_size}], rsp", // save current RSP to Vcpu::host_stack_top
883-
"mov rsp, rdi", // set RSP to guest regs area
884-
restore_regs_from_stack!(), // restore guest status
885-
$instr, // let's go!
886-
"jmp {failed}",
887-
host_stack_size = const size_of::<GeneralRegisters>(),
888-
failed = sym Self::vmx_entry_failed,
889-
// options(noreturn),
890-
)
891-
}
879+
naked_asm!(
880+
save_regs_to_stack!(), // save host status
881+
"mov [rdi + {host_stack_size}], rsp", // save current RSP to Vcpu::host_stack_top
882+
"mov rsp, rdi", // set RSP to guest regs area
883+
restore_regs_from_stack!(), // restore guest status
884+
$instr, // let's go!
885+
"jmp {failed}",
886+
host_stack_size = const size_of::<GeneralRegisters>(),
887+
failed = sym Self::vmx_entry_failed,
888+
// options(noreturn),
889+
)
892890
}
893891
}
894892

@@ -920,15 +918,14 @@ impl<H: AxVCpuHal> VmxVcpu<H> {
920918
///
921919
/// The return value is a dummy value.
922920
unsafe extern "C" fn vmx_exit(&mut self) -> usize {
923-
unsafe {
924-
naked_asm!(
925-
save_regs_to_stack!(), // save guest status, after this, rsp points to the `VmxVcpu`
926-
"mov rsp, [rsp + {host_stack_top}]", // set RSP to Vcpu::host_stack_top
927-
restore_regs_from_stack!(), // restore host status
928-
"ret",
929-
host_stack_top = const size_of::<GeneralRegisters>(),
930-
);
931-
}
921+
// it's not necessary to use another `unsafe` here, as Rust now do not require it in naked functions.
922+
naked_asm!(
923+
save_regs_to_stack!(), // save guest status, after this, rsp points to the `VmxVcpu`
924+
"mov rsp, [rsp + {host_stack_top}]", // set RSP to Vcpu::host_stack_top
925+
restore_regs_from_stack!(), // restore host status
926+
"ret",
927+
host_stack_top = const size_of::<GeneralRegisters>(),
928+
);
932929
}
933930

934931
fn vmx_entry_failed() -> ! {
@@ -1055,10 +1052,13 @@ impl<H: AxVCpuHal> VmxVcpu<H> {
10551052
}
10561053
};
10571054

1055+
// TODO: handle APIC access.
1056+
let _ = write;
1057+
1058+
self.advance_rip(exit_info.exit_instruction_length as _)?;
1059+
10581060
unimplemented!("apic access");
10591061
// TODO
1060-
1061-
self.advance_rip(exit_info.exit_instruction_length as _)
10621062
}
10631063

10641064
fn handle_vmx_preemption_timer(&mut self) -> AxResult {

0 commit comments

Comments
 (0)