Skip to content

Commit 76e745d

Browse files
committed
修复:将 naked 属性更改为 unsafe(naked)
1 parent f6008e3 commit 76e745d

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

src/exception.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,18 @@ fn current_el_sync_handler(tf: &mut TrapFrame) {
325325
///
326326
/// - This function is not typically called directly from Rust code. Instead, it is
327327
/// invoked as part of the low-level hypervisor or VM exit handling routines.
328-
#[naked]
328+
#[unsafe(naked)]
329329
#[unsafe(no_mangle)]
330330
unsafe extern "C" fn vmexit_trampoline() -> ! {
331-
unsafe {
332-
core::arch::naked_asm!(
333-
// Curretly `sp` points to the base address of `Aarch64VCpu.ctx`, which stores guest's `TrapFrame`.
334-
"add x9, sp, 34 * 8", // Skip the exception frame.
335-
// Currently `x9` points to `&Aarch64VCpu.host_stack_top`, see `run_guest()` in vcpu.rs.
336-
"ldr x10, [x9]", // Get `host_stack_top` value from `&Aarch64VCpu.host_stack_top`.
337-
"mov sp, x10", // Set `sp` as the host stack top.
338-
restore_regs_from_stack!(), // Restore host function context frame.
339-
"ret", // Control flow is handed back to Aarch64VCpu.run(), simulating the normal return of the `run_guest` function.
340-
)
341-
}
331+
core::arch::naked_asm!(
332+
// Curretly `sp` points to the base address of `Aarch64VCpu.ctx`, which stores guest's `TrapFrame`.
333+
"add x9, sp, 34 * 8", // Skip the exception frame.
334+
// Currently `x9` points to `&Aarch64VCpu.host_stack_top`, see `run_guest()` in vcpu.rs.
335+
"ldr x10, [x9]", // Get `host_stack_top` value from `&Aarch64VCpu.host_stack_top`.
336+
"mov sp, x10", // Set `sp` as the host stack top.
337+
restore_regs_from_stack!(), // Restore host function context frame.
338+
"ret", // Control flow is handed back to Aarch64VCpu.run(), simulating the normal return of the `run_guest` function.
339+
)
342340
}
343341

344342
/// Deal with invalid aarch64 exception.

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![feature(naked_functions)]
32
#![feature(doc_cfg)]
43
#![doc = include_str!("../README.md")]
54

src/vcpu.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
182182
///
183183
/// When a VM-Exit happens when guest's vCpu is running,
184184
/// the control flow will be redirected to this function through `return_run_guest`.
185-
#[naked]
185+
#[unsafe(naked)]
186186
unsafe extern "C" fn run_guest(&mut self) -> usize {
187187
// Fixes: https://github.com/arceos-hypervisor/arm_vcpu/issues/22
188188
//
@@ -191,25 +191,23 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
191191
// original `run_guest` with the current naked one, we eliminate the dummy code path of the
192192
// original version, and ensure that the compiler does not perform any unexpected return
193193
// value optimization.
194-
unsafe {
195-
core::arch::naked_asm!(
196-
// Save host context.
197-
save_regs_to_stack!(),
198-
// Save current host stack top to `self.host_stack_top`.
199-
//
200-
// 'extern "C"' here specifies the aapcs64 calling convention, according to which
201-
// the first and only parameter, the pointer of self, should be in x0:
202-
"mov x9, sp",
203-
"add x0, x0, {host_stack_top_offset}",
204-
"str x9, [x0]",
205-
// Go to `context_vm_entry`.
206-
"b context_vm_entry",
207-
// Panic if the control flow comes back here, which should never happen.
208-
"b {run_guest_panic}",
209-
host_stack_top_offset = const core::mem::size_of::<TrapFrame>(),
210-
run_guest_panic = sym Self::run_guest_panic,
211-
);
212-
}
194+
core::arch::naked_asm!(
195+
// Save host context.
196+
save_regs_to_stack!(),
197+
// Save current host stack top to `self.host_stack_top`.
198+
//
199+
// 'extern "C"' here specifies the aapcs64 calling convention, according to which
200+
// the first and only parameter, the pointer of self, should be in x0:
201+
"mov x9, sp",
202+
"add x0, x0, {host_stack_top_offset}",
203+
"str x9, [x0]",
204+
// Go to `context_vm_entry`.
205+
"b context_vm_entry",
206+
// Panic if the control flow comes back here, which should never happen.
207+
"b {run_guest_panic}",
208+
host_stack_top_offset = const core::mem::size_of::<TrapFrame>(),
209+
run_guest_panic = sym Self::run_guest_panic,
210+
);
213211
}
214212

215213
/// This function is called when the control flow comes back to `run_guest`. To provide a error

0 commit comments

Comments
 (0)