Skip to content

Commit 095e7ae

Browse files
committed
Bump Rust version to nightly-2025-02-18(2024 Edition)
1 parent 793a628 commit 095e7ae

18 files changed

+64
-66
lines changed

.github/workflows/doc-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push]
44

55
env:
66
CARGO_TERM_COLOR: always
7-
rust_toolchain: nightly-2024-01-18
7+
rust_toolchain: nightly-2025-02-18
88

99
jobs:
1010
build-doc:

os/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "os"
33
version = "0.1.0"
44
authors = ["Yifan Wu <[email protected]>"]
5-
edition = "2021"
5+
edition = "2024"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

os/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fs::{read_dir, File};
1+
use std::fs::{File, read_dir};
22
use std::io::{Result, Write};
33

44
fn main() {

os/src/batch.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,30 @@ impl AppManager {
6767
}
6868
}
6969

70-
unsafe fn load_app(&self, app_id: usize) {
70+
fn load_app(&self, app_id: usize) {
7171
if app_id >= self.num_app {
7272
println!("All applications completed!");
7373
shutdown(false);
7474
}
7575
println!("[kernel] Loading app_{}", app_id);
76-
// clear app area
77-
core::slice::from_raw_parts_mut(APP_BASE_ADDRESS as *mut u8, APP_SIZE_LIMIT).fill(0);
78-
let app_src = core::slice::from_raw_parts(
79-
self.app_start[app_id] as *const u8,
80-
self.app_start[app_id + 1] - self.app_start[app_id],
81-
);
82-
let app_dst = core::slice::from_raw_parts_mut(APP_BASE_ADDRESS as *mut u8, app_src.len());
83-
app_dst.copy_from_slice(app_src);
84-
// Memory fence about fetching the instruction memory
85-
// It is guaranteed that a subsequent instruction fetch must
86-
// observes all previous writes to the instruction memory.
87-
// Therefore, fence.i must be executed after we have loaded
88-
// the code of the next app into the instruction memory.
89-
// See also: riscv non-priv spec chapter 3, 'Zifencei' extension.
90-
asm!("fence.i");
76+
unsafe {
77+
// clear app area
78+
core::slice::from_raw_parts_mut(APP_BASE_ADDRESS as *mut u8, APP_SIZE_LIMIT).fill(0);
79+
let app_src = core::slice::from_raw_parts(
80+
self.app_start[app_id] as *const u8,
81+
self.app_start[app_id + 1] - self.app_start[app_id],
82+
);
83+
let app_dst =
84+
core::slice::from_raw_parts_mut(APP_BASE_ADDRESS as *mut u8, app_src.len());
85+
app_dst.copy_from_slice(app_src);
86+
// Memory fence about fetching the instruction memory
87+
// It is guaranteed that a subsequent instruction fetch must
88+
// observes all previous writes to the instruction memory.
89+
// Therefore, fence.i must be executed after we have loaded
90+
// the code of the next app into the instruction memory.
91+
// See also: riscv non-priv spec chapter 3, 'Zifencei' extension.
92+
asm!("fence.i");
93+
}
9194
}
9295

9396
pub fn get_current_app(&self) -> usize {
@@ -102,8 +105,8 @@ impl AppManager {
102105
lazy_static! {
103106
static ref APP_MANAGER: UPSafeCell<AppManager> = unsafe {
104107
UPSafeCell::new({
105-
extern "C" {
106-
fn _num_app();
108+
unsafe extern "C" {
109+
safe fn _num_app();
107110
}
108111
let num_app_ptr = _num_app as usize as *const usize;
109112
let num_app = num_app_ptr.read_volatile();
@@ -134,15 +137,13 @@ pub fn print_app_info() {
134137
pub fn run_next_app() -> ! {
135138
let mut app_manager = APP_MANAGER.exclusive_access();
136139
let current_app = app_manager.get_current_app();
137-
unsafe {
138-
app_manager.load_app(current_app);
139-
}
140+
app_manager.load_app(current_app);
140141
app_manager.move_to_next_app();
141142
drop(app_manager);
142143
// before this we have to drop local variables related to resources manually
143144
// and release the resources
144-
extern "C" {
145-
fn __restore(cx_addr: usize);
145+
unsafe extern "C" {
146+
unsafe fn __restore(cx_addr: usize);
146147
}
147148
unsafe {
148149
__restore(KERNEL_STACK.push_context(TrapContext::app_init_context(

os/src/lang_items.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ fn panic(info: &PanicInfo) -> ! {
1111
"[kernel] Panicked at {}:{} {}",
1212
location.file(),
1313
location.line(),
14-
info.message().unwrap()
14+
info.message()
1515
);
1616
} else {
17-
error!("[kernel] Panicked: {}", info.message().unwrap());
17+
error!("[kernel] Panicked: {}", info.message());
1818
}
1919
shutdown(true)
2020
}

os/src/main.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#![deny(warnings)]
1919
#![no_std]
2020
#![no_main]
21-
#![feature(panic_info_message)]
2221

2322
use core::arch::global_asm;
2423

@@ -38,9 +37,9 @@ global_asm!(include_str!("link_app.S"));
3837

3938
/// clear BSS segment
4039
fn clear_bss() {
41-
extern "C" {
42-
fn sbss();
43-
fn ebss();
40+
unsafe extern "C" {
41+
safe fn sbss();
42+
safe fn ebss();
4443
}
4544
unsafe {
4645
core::slice::from_raw_parts_mut(sbss as usize as *mut u8, ebss as usize - sbss as usize)
@@ -49,27 +48,26 @@ fn clear_bss() {
4948
}
5049

5150
/// the rust entry-point of os
52-
#[no_mangle]
51+
#[unsafe(no_mangle)]
5352
pub fn rust_main() -> ! {
54-
extern "C" {
55-
fn stext(); // begin addr of text segment
56-
fn etext(); // end addr of text segment
57-
fn srodata(); // start addr of Read-Only data segment
58-
fn erodata(); // end addr of Read-Only data ssegment
59-
fn sdata(); // start addr of data segment
60-
fn edata(); // end addr of data segment
61-
fn sbss(); // start addr of BSS segment
62-
fn ebss(); // end addr of BSS segment
63-
fn boot_stack_lower_bound(); // stack lower bound
64-
fn boot_stack_top(); // stack top
53+
unsafe extern "C" {
54+
safe fn stext(); // begin addr of text segment
55+
safe fn etext(); // end addr of text segment
56+
safe fn srodata(); // start addr of Read-Only data segment
57+
safe fn erodata(); // end addr of Read-Only data ssegment
58+
safe fn sdata(); // start addr of data segment
59+
safe fn edata(); // end addr of data segment
60+
safe fn sbss(); // start addr of BSS segment
61+
safe fn ebss(); // end addr of BSS segment
62+
safe fn boot_stack_lower_bound(); // stack lower bound
63+
safe fn boot_stack_top(); // stack top
6564
}
6665
clear_bss();
6766
logging::init();
6867
println!("[kernel] Hello, world!");
6968
trace!(
7069
"[kernel] .text [{:#x}, {:#x})",
71-
stext as usize,
72-
etext as usize
70+
stext as usize, etext as usize
7371
);
7472
debug!(
7573
"[kernel] .rodata [{:#x}, {:#x})",

os/src/sbi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn console_getchar() -> usize {
1515

1616
/// use sbi call to shutdown the kernel
1717
pub fn shutdown(failure: bool) -> ! {
18-
use sbi_rt::{system_reset, NoReason, Shutdown, SystemFailure};
18+
use sbi_rt::{NoReason, Shutdown, SystemFailure, system_reset};
1919
if !failure {
2020
system_reset(Shutdown, NoReason);
2121
} else {

os/src/trap/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use riscv::register::sstatus::{self, Sstatus, SPP};
1+
use riscv::register::sstatus::{self, SPP, Sstatus};
22
/// Trap Context
33
#[repr(C)]
44
pub struct TrapContext {

os/src/trap/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ global_asm!(include_str!("trap.S"));
2727

2828
/// initialize CSR `stvec` as the entry of `__alltraps`
2929
pub fn init() {
30-
extern "C" {
31-
fn __alltraps();
30+
unsafe extern "C" {
31+
safe fn __alltraps();
3232
}
3333
unsafe {
3434
stvec::write(__alltraps as usize, TrapMode::Direct);
3535
}
3636
}
3737

38-
#[no_mangle]
38+
#[unsafe(no_mangle)]
3939
/// handle an interrupt, exception, or system call from user space
4040
pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext {
4141
let scause = scause::read(); // get trap cause

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[toolchain]
22
profile = "minimal"
33
# use the nightly version of the last stable toolchain, see <https://forge.rust-lang.org/>
4-
channel = "nightly-2024-05-01"
4+
channel = "nightly-2025-02-18"
55
components = ["rust-src", "llvm-tools", "rustfmt", "clippy"]
66
targets = ["riscv64gc-unknown-none-elf"]

user/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "user_lib"
33
version = "0.1.0"
44
authors = ["Yifan Wu <[email protected]>"]
5-
edition = "2018"
5+
edition = "2024"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

user/src/bin/00hello_world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[macro_use]
55
extern crate user_lib;
66

7-
#[no_mangle]
7+
#[unsafe(no_mangle)]
88
fn main() -> i32 {
99
println!("Hello, world!");
1010
0

user/src/bin/01store_fault.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[macro_use]
55
extern crate user_lib;
66

7-
#[no_mangle]
7+
#[unsafe(no_mangle)]
88
fn main() -> i32 {
99
println!("Into Test store_fault, we will insert an invalid store operation...");
1010
println!("Kernel should kill this application!");

user/src/bin/02power.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const P: u32 = 3;
99
const STEP: usize = 100000;
1010
const MOD: u32 = 10007;
1111

12-
#[no_mangle]
12+
#[unsafe(no_mangle)]
1313
fn main() -> i32 {
1414
let mut pow = [0u32; SIZE];
1515
let mut index: usize = 0;

user/src/bin/03priv_inst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern crate user_lib;
66

77
use core::arch::asm;
88

9-
#[no_mangle]
9+
#[unsafe(no_mangle)]
1010
fn main() -> i32 {
1111
println!("Try to execute privileged instruction in U Mode");
1212
println!("Kernel should kill this application!");

user/src/bin/04priv_csr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern crate user_lib;
66

77
use riscv::register::sstatus::{self, SPP};
88

9-
#[no_mangle]
9+
#[unsafe(no_mangle)]
1010
fn main() -> i32 {
1111
println!("Try to access privileged CSR in U Mode");
1212
println!("Kernel should kill this application!");

user/src/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[panic_handler]
22
fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! {
3-
let err = panic_info.message().unwrap();
3+
let err = panic_info.message();
44
if let Some(location) = panic_info.location() {
55
println!(
66
"Panicked at {}:{}, {}",

user/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
#![no_std]
22
#![feature(linkage)]
3-
#![feature(panic_info_message)]
43

54
#[macro_use]
65
pub mod console;
76
mod lang_items;
87
mod syscall;
98

10-
#[no_mangle]
11-
#[link_section = ".text.entry"]
9+
#[unsafe(no_mangle)]
10+
#[unsafe(link_section = ".text.entry")]
1211
pub extern "C" fn _start() -> ! {
1312
clear_bss();
1413
exit(main());
1514
panic!("unreachable after sys_exit!");
1615
}
1716

1817
#[linkage = "weak"]
19-
#[no_mangle]
18+
#[unsafe(no_mangle)]
2019
fn main() -> i32 {
2120
panic!("Cannot find main!");
2221
}
2322

2423
fn clear_bss() {
25-
extern "C" {
26-
fn start_bss();
27-
fn end_bss();
24+
unsafe extern "C" {
25+
safe fn start_bss();
26+
safe fn end_bss();
2827
}
2928
(start_bss as usize..end_bss as usize).for_each(|addr| unsafe {
3029
(addr as *mut u8).write_volatile(0);

0 commit comments

Comments
 (0)