Browse Source

fix(sbi-testing): replace `#[naked]` with `#[unsafe(naked)]` for stable Rust compatibility (#132)

* fix(sbi-testing): replace `#[naked]` with `#[unsafe(naked)]` for stable Rust compatibility

- Modified all naked function attributes in `sbi-testing` module.
- Verified compilation on both stable and nightly Rust versions.
- Updated related documentation comments if any.

Signed-off-by: Yuyang Cai <2074730050@qq.com>

* refactor(sbi-testing): restore `naked_functions` feature gate for backward compatibility

This reverts partial changes restoring the `#![feature(naked_functions)]` declaration despite Clippy errors(the feature `naked_functions` has been stable since 1.88.0-nightly and no longer requires an attribute to enable).

Signed-off-by: Yuyang Cai <2074730050@qq.com>

* fix(sbi-testing): remove stabilized `naked_functions` feature gate

This removes the redundant `#![feature(naked_functions)]` declaration
since the feature has been stabilized in Rust 1.88.0+.It resolves the Clippy warning

Signed-off-by: Yuyang Cai <2074730050@qq.com>

* docs(changelog): record naked functions stabilization changes

- Document #[naked] → #[unsafe(naked)] transition in CHANGELOG
- Adjust CI to enforce Rust 1.88.0 for stabilized features

Signed-off-by: Yuyang Cai <2074730050@qq.com>

* fix(ci): update MSRV test from invalid Rust 1.88.0 to 1.90.0

- Correct toolchain version in GitHub Actions workflow

Signed-off-by: Yuyang Cai <2074730050@qq.com>

* fix(ci): update MSRV test with Rust 1.88.0(nightly-2025-04-21)

- Correct toolchain version in GitHub Actions workflow

Signed-off-by: Yuyang Cai <2074730050@qq.com>

---------

Signed-off-by: Yuyang Cai <2074730050@qq.com>
LunaRain_079 5 days ago
parent
commit
f6dc6ab062

+ 2 - 2
.github/workflows/Library.yml

@@ -142,7 +142,7 @@ jobs:
           cargo build --target ${{ matrix.TARGET }} --verbose -p sbi-testing --features "log"
 
   msrv-test:
-    name: MSRV Test (Rust 1.83.0)
+    name: MSRV Test (Rust 1.88.0)
     runs-on: ubuntu-latest
     strategy:
       matrix:
@@ -157,7 +157,7 @@ jobs:
           - riscv64imac-unknown-none-elf
           - riscv32imac-unknown-none-elf
         TOOLCHAIN:
-          - nightly-2024-11-28
+          - nightly-2025-04-21
     steps:
       - name: Checkout repository
         uses: actions/checkout@v4

+ 6 - 0
library/sbi-testing/CHANGELOG.md

@@ -17,6 +17,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 - Update sbi-spec to version 0.0.7
 - Update sbi-rt to version 0.0.3
 - Rename `MArchId` and `MVendorId` into `MarchId` and `MvendorId` in `BaseCase`
+- Replace `#[naked]` with `#[unsafe(naked)]` attribute in sbi-testing module to support stable Rust
+    - Modified files:
+        - `library/sbi-testing/src/thread.rs`
+        - `library/sbi-testing/src/hsm.rs`
+    - MSRV bumped to 1.88.0 ([PR #134213](https://github.com/rust-lang/rust/pull/134213))
 
 ### Fixed
 - Fix typos.
@@ -38,3 +43,4 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 [Unreleased]: https://github.com/rustsbi/sbi-testing/compare/v0.0.2...HEAD
 [0.0.2]: https://github.com/rustsbi/sbi-testing/compare/v0.0.1...v0.0.2
 [0.0.1]: https://github.com/rustsbi/sbi-testing/compare/v0.0.0...v0.0.1
+

+ 10 - 14
library/sbi-testing/src/hsm.rs

@@ -233,24 +233,20 @@ fn test_batch(batch: &[usize], mut f: impl FnMut(Case)) -> bool {
 }
 
 /// 测试用启动入口
-#[naked]
+#[unsafe(naked)]
 unsafe extern "C" fn test_entry(hartid: usize, opaque: *mut ItemPerHart) -> ! {
-    unsafe {
-        core::arch::naked_asm!(
-            "csrw sie, zero",   // 关中断
-            "call {set_stack}", // 设置栈
-            "j    {rust_main}", // 进入 rust
-            set_stack = sym set_stack,
-            rust_main = sym rust_main,
-        )
-    }
+    core::arch::naked_asm!(
+        "csrw sie, zero",   // 关中断
+        "call {set_stack}", // 设置栈
+        "j    {rust_main}", // 进入 rust
+        set_stack = sym set_stack,
+        rust_main = sym rust_main,
+    )
 }
 
-#[naked]
+#[unsafe(naked)]
 unsafe extern "C" fn set_stack(hart_id: usize, ptr: *const ItemPerHart) {
-    unsafe {
-        core::arch::naked_asm!("addi sp, a1, 512", "ret");
-    }
+    core::arch::naked_asm!("addi sp, a1, 512", "ret");
 }
 
 #[inline(never)]

+ 0 - 1
library/sbi-testing/src/lib.rs

@@ -2,7 +2,6 @@
 
 #![no_std]
 #![deny(warnings, missing_docs)]
-#![feature(naked_functions)]
 
 mod thread;
 

+ 68 - 70
library/sbi-testing/src/thread.rs

@@ -109,76 +109,74 @@ impl Thread {
 /// # Safety
 ///
 /// 裸函数。
-#[naked]
+#[unsafe(naked)]
 unsafe extern "C" fn execute_naked() {
-    unsafe {
-        core::arch::naked_asm!(
-            r"  .altmacro
-            .macro SAVE n
-                sd x\n, \n*8(sp)
-            .endm
-            .macro SAVE_ALL
-                sd x1, 1*8(sp)
-                .set n, 3
-                .rept 29
-                    SAVE %n
-                    .set n, n+1
-                .endr
-            .endm
+    core::arch::naked_asm!(
+        r"  .altmacro
+        .macro SAVE n
+            sd x\n, \n*8(sp)
+        .endm
+        .macro SAVE_ALL
+            sd x1, 1*8(sp)
+            .set n, 3
+            .rept 29
+                SAVE %n
+                .set n, n+1
+            .endr
+        .endm
 
-            .macro LOAD n
-                ld x\n, \n*8(sp)
-            .endm
-            .macro LOAD_ALL
-                ld x1, 1*8(sp)
-                .set n, 3
-                .rept 29
-                    LOAD %n
-                    .set n, n+1
-                .endr
-            .endm
-        ",
-            // 位置无关加载
-            "   .option push
-            .option nopic
-        ",
-            // 保存调度上下文
-            "   addi sp, sp, -32*8
-            SAVE_ALL
-        ",
-            // 设置陷入入口
-            "   la   t0, 2f
-            csrw stvec, t0
-        ",
-            // 保存调度上下文地址并切换上下文
-            "   csrr t0, sscratch
-            sd   sp, (t0)
-            mv   sp, t0
-        ",
-            // 恢复线程上下文
-            "   LOAD_ALL
-            ld   sp, 2*8(sp)
-        ",
-            // 执行线程
-            "   sret",
-            // 陷入
-            "   .align 2",
-            // 切换上下文
-            "2: csrrw sp, sscratch, sp",
-            // 保存线程上下文
-            "   SAVE_ALL
-            csrrw t0, sscratch, sp
-            sd    t0, 2*8(sp)
-        ",
-            // 切换上下文
-            "   ld sp, (sp)",
-            // 恢复调度上下文
-            "   LOAD_ALL
-            addi sp, sp, 32*8
-        ",
-            // 返回调度
-            "   ret",
-            "   .option pop",
-        )
-    }
+        .macro LOAD n
+            ld x\n, \n*8(sp)
+        .endm
+        .macro LOAD_ALL
+            ld x1, 1*8(sp)
+            .set n, 3
+            .rept 29
+                LOAD %n
+                .set n, n+1
+            .endr
+        .endm
+    ",
+        // 位置无关加载
+        "   .option push
+        .option nopic
+    ",
+        // 保存调度上下文
+        "   addi sp, sp, -32*8
+        SAVE_ALL
+    ",
+        // 设置陷入入口
+        "   la   t0, 2f
+        csrw stvec, t0
+    ",
+        // 保存调度上下文地址并切换上下文
+        "   csrr t0, sscratch
+        sd   sp, (t0)
+        mv   sp, t0
+    ",
+        // 恢复线程上下文
+        "   LOAD_ALL
+        ld   sp, 2*8(sp)
+    ",
+        // 执行线程
+        "   sret",
+        // 陷入
+        "   .align 2",
+        // 切换上下文
+        "2: csrrw sp, sscratch, sp",
+        // 保存线程上下文
+        "   SAVE_ALL
+        csrrw t0, sscratch, sp
+        sd    t0, 2*8(sp)
+    ",
+        // 切换上下文
+        "   ld sp, (sp)",
+        // 恢复调度上下文
+        "   LOAD_ALL
+        addi sp, sp, 32*8
+    ",
+        // 返回调度
+        "   ret",
+        "   .option pop",
+    )
 }