Skip to content

Commit c025be0

Browse files
bench-kernel: replace #[naked] with #[unsafe(naked)] for stable Rust
Replace the #[naked] attribute with #[unsafe(naked)] in the bench-kernel module to ensure compatibility with the latest stable Rust compiler. This follows the stabilization in rust-lang/rust#134213 and avoids build failures when using the stable Rust toolchain. Specific changes include: - Replace `#[naked]` with `#[unsafe(naked)]` across all relevant functions. - Remove `#![feature(naked_functions, asm_const)]` as they are no longer needed on stable with `#[unsafe(naked)]`. - Switch to the `naked_asm!` macro to comply with new naked function requirements introduced alongside `#[unsafe(naked)]`. - Remove `options(noreturn)`, which is disallowed within `naked_asm!`. - Update `put_char` and `put_str` implementations in `impl rcore_console::Console for Console` to avoid errors from creating shared references to mutable statics. - Update GitHub Actions workflow files to use `ubuntu-22.04` instead of `ubuntu-20.04` for CI compatibility. The changes build and pass tests successfully on both stable and nightly Rust. Fix: rustsbi/rustsbi#63 Refs: - Issue: rustsbi/rustsbi#63 - Upstream PR: rust-lang/rust#134213 Signed-off-by: manchangfengxu <[email protected]>
1 parent 557dd8b commit c025be0

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
build:
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- uses: actions/checkout@v3
1313

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5555
- Fixes on usage of CLINT peripheral, thanks to @duskmoon314
5656
- Numerous fixes to HSM module implementation, more documents
5757

58+
## [0.1.1] - 2025-04-22
59+
60+
### Modified
61+
- Replaced #[naked] with #[unsafe(naked)] across all relevant functions.
62+
- Removed `#![feature(naked_functions, asm_const)]` as they are no longer needed.
63+
- Switched to the `naked_asm!` macro to comply with new naked function requirements.
64+
- Removed `options(noreturn)`, which is not allowed in `naked_asm!`.
65+
- Updated implementations of `put_char` and `put_str` in
66+
`impl rcore_console::Console for Console` to avoid errors caused by
67+
creating shared references to mutable statics.
68+
- Updated GitHub Actions YAML workflow files to replace `ubuntu-20.04` with
69+
`ubuntu-22.04` for CI compatibility.
70+
5871
[Unreleased]: https://github.com/rustsbi/rustsbi-qemu/compare/v0.1.1...HEAD
5972
[0.1.1]: https://github.com/rustsbi/rustsbi-qemu/compare/v0.1.0...v0.1.1
6073
[0.1.0]: https://github.com/rustsbi/rustsbi-qemu/releases/tag/v0.1.0

bench-kernel/src/main.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#![no_std]
22
#![no_main]
3-
#![feature(naked_functions, asm_const)]
43
#![deny(warnings)]
54

65
use rcore_console::log;
76
use riscv::register::*;
87
use sbi_rt::*;
98
use uart16550::Uart16550;
109

11-
#[naked]
10+
#[unsafe(naked)]
1211
#[no_mangle]
1312
#[link_section = ".text.entry"]
1413
unsafe extern "C" fn _start(hartid: usize, device_tree_paddr: usize) -> ! {
@@ -17,13 +16,12 @@ unsafe extern "C" fn _start(hartid: usize, device_tree_paddr: usize) -> ! {
1716
#[link_section = ".bss.uninit"]
1817
static mut STACK: [u8; STACK_SIZE] = [0u8; STACK_SIZE];
1918

20-
core::arch::asm!(
19+
core::arch::naked_asm!(
2120
"la sp, {stack} + {stack_size}",
2221
"j {main}",
2322
stack_size = const STACK_SIZE,
2423
stack = sym STACK,
2524
main = sym rust_main,
26-
options(noreturn),
2725
)
2826
}
2927

@@ -127,11 +125,17 @@ impl Uart16550Map {
127125
impl rcore_console::Console for Console {
128126
#[inline]
129127
fn put_char(&self, c: u8) {
130-
unsafe { UART.get().write(core::slice::from_ref(&c)) };
128+
unsafe {
129+
let mut_ref_uart = (*(&raw mut UART)).get();
130+
mut_ref_uart.write(core::slice::from_ref(&c))
131+
};
131132
}
132133

133134
#[inline]
134135
fn put_str(&self, s: &str) {
135-
unsafe { UART.get().write(s.as_bytes()) };
136+
unsafe {
137+
let mut_ref_uart = (*(&raw mut UART)).get();
138+
mut_ref_uart.write(s.as_bytes())
139+
};
136140
}
137141
}

0 commit comments

Comments
 (0)