Skip to content

Commit de9b3ec

Browse files
committed
Bump Rust version to nightly-2025-02-18(2024 Edition)
1 parent 37b2d53 commit de9b3ec

File tree

18 files changed

+41
-37
lines changed

18 files changed

+41
-37
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/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/loader.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ fn get_base_i(app_id: usize) -> usize {
5555

5656
/// Get the total number of applications.
5757
pub fn get_num_app() -> usize {
58-
extern "C" {
59-
fn _num_app();
58+
unsafe extern "C" {
59+
safe fn _num_app();
6060
}
6161
unsafe { (_num_app as usize as *const usize).read_volatile() }
6262
}
6363

6464
/// Load nth user app at
6565
/// [APP_BASE_ADDRESS + n * APP_SIZE_LIMIT, APP_BASE_ADDRESS + (n+1) * APP_SIZE_LIMIT).
6666
pub fn load_apps() {
67-
extern "C" {
68-
fn _num_app();
67+
unsafe extern "C" {
68+
safe fn _num_app();
6969
}
7070
let num_app_ptr = _num_app as usize as *const usize;
7171
let num_app = get_num_app();

os/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#![deny(warnings)]
2020
#![no_std]
2121
#![no_main]
22-
#![feature(panic_info_message)]
2322

2423
use core::arch::global_asm;
2524
use log::*;
@@ -40,9 +39,9 @@ global_asm!(include_str!("link_app.S"));
4039

4140
/// clear BSS segment
4241
fn clear_bss() {
43-
extern "C" {
44-
fn sbss();
45-
fn ebss();
42+
unsafe extern "C" {
43+
safe fn sbss();
44+
safe fn ebss();
4645
}
4746
unsafe {
4847
core::slice::from_raw_parts_mut(sbss as usize as *mut u8, ebss as usize - sbss as usize)
@@ -51,7 +50,7 @@ fn clear_bss() {
5150
}
5251

5352
/// the rust entry-point of os
54-
#[no_mangle]
53+
#[unsafe(no_mangle)]
5554
pub fn rust_main() -> ! {
5655
clear_bss();
5756
logging::init();

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/task/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ impl TaskContext {
2424

2525
/// set task context {__restore ASM funciton, kernel stack, s_0..12 }
2626
pub fn goto_restore(kstack_ptr: usize) -> Self {
27-
extern "C" {
28-
fn __restore();
27+
unsafe extern "C" {
28+
unsafe fn __restore();
2929
}
3030
Self {
3131
ra: __restore as usize,

os/src/task/switch.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ use core::arch::global_asm;
1010

1111
global_asm!(include_str!("switch.S"));
1212

13-
extern "C" {
13+
unsafe extern "C" {
1414
/// Switch to the context of `next_task_cx_ptr`, saving the current context
1515
/// in `current_task_cx_ptr`.
16-
pub fn __switch(current_task_cx_ptr: *mut TaskContext, next_task_cx_ptr: *const TaskContext);
16+
pub unsafe fn __switch(
17+
current_task_cx_ptr: *mut TaskContext,
18+
next_task_cx_ptr: *const TaskContext,
19+
);
1720
}

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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ global_asm!(include_str!("trap.S"));
2626

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

37-
#[no_mangle]
37+
#[unsafe(no_mangle)]
3838
/// handle an interrupt, exception, or system call from user space
3939
pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext {
4040
let scause = scause::read(); // get trap cause
@@ -45,7 +45,10 @@ pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext {
4545
cx.x[10] = syscall(cx.x[17], [cx.x[10], cx.x[11], cx.x[12]]) as usize;
4646
}
4747
Trap::Exception(Exception::StoreFault) | Trap::Exception(Exception::StorePageFault) => {
48-
println!("[kernel] PageFault in application, bad addr = {:#x}, bad instruction = {:#x}, kernel killed it.", stval, cx.sepc);
48+
println!(
49+
"[kernel] PageFault in application, bad addr = {:#x}, bad instruction = {:#x}, kernel killed it.",
50+
stval, cx.sepc
51+
);
4952
panic!("[kernel] Cannot continue!");
5053
//run_next_app();
5154
}

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/00write_a.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use user_lib::yield_;
99
const WIDTH: usize = 10;
1010
const HEIGHT: usize = 5;
1111

12-
#[no_mangle]
12+
#[unsafe(no_mangle)]
1313
fn main() -> i32 {
1414
for i in 0..HEIGHT {
1515
for _ in 0..WIDTH {

user/src/bin/01write_b.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use user_lib::yield_;
99
const WIDTH: usize = 10;
1010
const HEIGHT: usize = 2;
1111

12-
#[no_mangle]
12+
#[unsafe(no_mangle)]
1313
fn main() -> i32 {
1414
for i in 0..HEIGHT {
1515
for _ in 0..WIDTH {

user/src/bin/02write_c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use user_lib::yield_;
99
const WIDTH: usize = 10;
1010
const HEIGHT: usize = 3;
1111

12-
#[no_mangle]
12+
#[unsafe(no_mangle)]
1313
fn main() -> i32 {
1414
for i in 0..HEIGHT {
1515
for _ in 0..WIDTH {

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)