Skip to content

Commit d2a33f8

Browse files
committed
Bump Rust version to nightly-2025-02-18(2024 Edition)
1 parent f04d0fe commit d2a33f8

40 files changed

+113
-99
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
@@ -10,10 +10,10 @@ fn panic(info: &PanicInfo) -> ! {
1010
"[kernel] Panicked at {}:{} {}",
1111
location.file(),
1212
location.line(),
13-
info.message().unwrap()
13+
info.message()
1414
);
1515
} else {
16-
error!("[kernel] Panicked: {}", info.message().unwrap());
16+
error!("[kernel] Panicked: {}", info.message());
1717
}
1818
shutdown(true)
1919
}

os/src/loader.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use alloc::vec::Vec;
55
use lazy_static::*;
66
///get app number
77
pub fn get_num_app() -> usize {
8-
extern "C" {
9-
fn _num_app();
8+
unsafe extern "C" {
9+
safe fn _num_app();
1010
}
1111
unsafe { (_num_app as usize as *const usize).read_volatile() }
1212
}
1313
/// get applications data
1414
pub fn get_app_data(app_id: usize) -> &'static [u8] {
15-
extern "C" {
16-
fn _num_app();
15+
unsafe extern "C" {
16+
safe fn _num_app();
1717
}
1818
let num_app_ptr = _num_app as usize as *const usize;
1919
let num_app = get_num_app();
@@ -31,8 +31,8 @@ lazy_static! {
3131
///All of app's name
3232
static ref APP_NAMES: Vec<&'static str> = {
3333
let num_app = get_num_app();
34-
extern "C" {
35-
fn _app_names();
34+
unsafe extern "C" {
35+
safe fn _app_names();
3636
}
3737
let mut start = _app_names as usize as *const u8;
3838
let mut v = Vec::new();

os/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#![deny(warnings)]
2222
#![no_std]
2323
#![no_main]
24-
#![feature(panic_info_message)]
2524
#![feature(alloc_error_handler)]
2625

2726
extern crate alloc;
@@ -54,18 +53,18 @@ global_asm!(include_str!("entry.asm"));
5453
global_asm!(include_str!("link_app.S"));
5554
/// clear BSS segment
5655
fn clear_bss() {
57-
extern "C" {
58-
fn sbss();
59-
fn ebss();
56+
unsafe extern "C" {
57+
safe fn sbss();
58+
safe fn ebss();
6059
}
6160
unsafe {
6261
core::slice::from_raw_parts_mut(sbss as usize as *mut u8, ebss as usize - sbss as usize)
6362
.fill(0);
6463
}
6564
}
6665

67-
#[no_mangle]
6866
/// the rust entry-point of os
67+
#[unsafe(no_mangle)]
6968
pub fn rust_main() -> ! {
7069
clear_bss();
7170
logging::init();

os/src/mm/frame_allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ lazy_static! {
9494
}
9595
/// initiate the frame allocator using `ekernel` and `MEMORY_END`
9696
pub fn init_frame_allocator() {
97-
extern "C" {
98-
fn ekernel();
97+
unsafe extern "C" {
98+
safe fn ekernel();
9999
}
100100
FRAME_ALLOCATOR.exclusive_access().init(
101101
PhysAddr::from(ekernel as usize).ceil(),

os/src/mm/heap_allocator.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! The global allocator
22
use crate::config::KERNEL_HEAP_SIZE;
33
use buddy_system_allocator::LockedHeap;
4+
use core::ptr::addr_of_mut;
45

56
#[global_allocator]
67
/// heap allocator instance
@@ -18,17 +19,17 @@ pub fn init_heap() {
1819
unsafe {
1920
HEAP_ALLOCATOR
2021
.lock()
21-
.init(HEAP_SPACE.as_ptr() as usize, KERNEL_HEAP_SIZE);
22+
.init(addr_of_mut!(HEAP_SPACE) as usize, KERNEL_HEAP_SIZE);
2223
}
2324
}
2425

2526
#[allow(unused)]
2627
pub fn heap_test() {
2728
use alloc::boxed::Box;
2829
use alloc::vec::Vec;
29-
extern "C" {
30-
fn sbss();
31-
fn ebss();
30+
unsafe extern "C" {
31+
safe fn sbss();
32+
safe fn ebss();
3233
}
3334
let bss_range = sbss as usize..ebss as usize;
3435
let a = Box::new(5);

os/src/mm/memory_set.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Implementation of [`MapArea`] and [`MemorySet`].
2-
use super::{frame_alloc, FrameTracker};
2+
3+
use super::{FrameTracker, frame_alloc};
34
use super::{PTEFlags, PageTable, PageTableEntry};
45
use super::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
56
use super::{StepByOne, VPNRange};
@@ -12,17 +13,17 @@ use core::arch::asm;
1213
use lazy_static::*;
1314
use riscv::register::satp;
1415

15-
extern "C" {
16-
fn stext();
17-
fn etext();
18-
fn srodata();
19-
fn erodata();
20-
fn sdata();
21-
fn edata();
22-
fn sbss_with_stack();
23-
fn ebss();
24-
fn ekernel();
25-
fn strampoline();
16+
unsafe extern "C" {
17+
safe fn stext();
18+
safe fn etext();
19+
safe fn srodata();
20+
safe fn erodata();
21+
safe fn sdata();
22+
safe fn edata();
23+
safe fn sbss_with_stack();
24+
safe fn ebss();
25+
safe fn ekernel();
26+
safe fn strampoline();
2627
}
2728

2829
lazy_static! {
@@ -385,20 +386,26 @@ pub fn remap_test() {
385386
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
386387
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
387388
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
388-
assert!(!kernel_space
389-
.page_table
390-
.translate(mid_text.floor())
391-
.unwrap()
392-
.writable(),);
393-
assert!(!kernel_space
394-
.page_table
395-
.translate(mid_rodata.floor())
396-
.unwrap()
397-
.writable(),);
398-
assert!(!kernel_space
399-
.page_table
400-
.translate(mid_data.floor())
401-
.unwrap()
402-
.executable(),);
389+
assert!(
390+
!kernel_space
391+
.page_table
392+
.translate(mid_text.floor())
393+
.unwrap()
394+
.writable(),
395+
);
396+
assert!(
397+
!kernel_space
398+
.page_table
399+
.translate(mid_rodata.floor())
400+
.unwrap()
401+
.writable(),
402+
);
403+
assert!(
404+
!kernel_space
405+
.page_table
406+
.translate(mid_data.floor())
407+
.unwrap()
408+
.executable(),
409+
);
403410
println!("remap_test passed!");
404411
}

os/src/mm/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ mod page_table;
1313

1414
pub use address::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
1515
use address::{StepByOne, VPNRange};
16-
pub use frame_allocator::{frame_alloc, FrameTracker};
16+
pub use frame_allocator::{FrameTracker, frame_alloc};
1717
pub use memory_set::remap_test;
18-
pub use memory_set::{MapPermission, MemorySet, KERNEL_SPACE};
19-
pub use page_table::{translated_byte_buffer, translated_refmut, translated_str, PageTableEntry};
18+
pub use memory_set::{KERNEL_SPACE, MapPermission, MemorySet};
2019
use page_table::{PTEFlags, PageTable};
20+
pub use page_table::{PageTableEntry, translated_byte_buffer, translated_refmut, translated_str};
21+
2122
/// initiate heap allocator, frame allocator and kernel space
2223
pub fn init() {
2324
heap_allocator::init_heap();

os/src/mm/page_table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Implementation of [`PageTableEntry`] and [`PageTable`].
2-
use super::{frame_alloc, FrameTracker, PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum};
2+
3+
use super::{FrameTracker, PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum, frame_alloc};
34
use alloc::string::String;
45
use alloc::vec;
56
use alloc::vec::Vec;

os/src/sbi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn set_timer(timer: usize) {
2020

2121
/// use sbi call to shutdown the kernel
2222
pub fn shutdown(failure: bool) -> ! {
23-
use sbi_rt::{system_reset, NoReason, Shutdown, SystemFailure};
23+
use sbi_rt::{NoReason, Shutdown, SystemFailure, system_reset};
2424
if !failure {
2525
system_reset(Shutdown, NoReason);
2626
} else {

os/src/task/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ use crate::loader::get_app_data_by_name;
2626
use crate::sbi::shutdown;
2727
use alloc::sync::Arc;
2828
use lazy_static::*;
29-
pub use manager::{fetch_task, TaskManager};
29+
pub use manager::{TaskManager, fetch_task};
3030
use switch::__switch;
3131
use task::{TaskControlBlock, TaskStatus};
3232

3333
pub use context::TaskContext;
3434
pub use manager::add_task;
35-
pub use pid::{pid_alloc, KernelStack, PidAllocator, PidHandle};
35+
pub use pid::{KernelStack, PidAllocator, PidHandle, pid_alloc};
3636
pub use processor::{
37-
current_task, current_trap_cx, current_user_token, run_tasks, schedule, take_current_task,
38-
Processor,
37+
Processor, current_task, current_trap_cx, current_user_token, run_tasks, schedule,
38+
take_current_task,
3939
};
4040
/// Suspend the current 'Running' task and run the next task in task list.
4141
pub fn suspend_current_and_run_next() {

os/src/task/pid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//!Implementation of [`PidAllocator`]
22
use crate::config::{KERNEL_STACK_SIZE, PAGE_SIZE, TRAMPOLINE};
3-
use crate::mm::{MapPermission, VirtAddr, KERNEL_SPACE};
3+
use crate::mm::{KERNEL_SPACE, MapPermission, VirtAddr};
44
use crate::sync::UPSafeCell;
55
use alloc::vec::Vec;
66
use lazy_static::*;

os/src/task/processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//!Implementation of [`Processor`] and Intersection of control flow
22
use super::__switch;
3-
use super::{fetch_task, TaskStatus};
43
use super::{TaskContext, TaskControlBlock};
4+
use super::{TaskStatus, fetch_task};
55
use crate::sync::UPSafeCell;
66
use crate::trap::TrapContext;
77
use alloc::sync::Arc;

os/src/task/switch.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ use core::arch::global_asm;
44

55
global_asm!(include_str!("switch.S"));
66

7-
extern "C" {
8-
pub fn __switch(current_task_cx_ptr: *mut TaskContext, next_task_cx_ptr: *const TaskContext);
7+
unsafe extern "C" {
8+
/// Switch to the context of `next_task_cx_ptr`, saving the current context
9+
/// in `current_task_cx_ptr`.
10+
pub unsafe fn __switch(
11+
current_task_cx_ptr: *mut TaskContext,
12+
next_task_cx_ptr: *const TaskContext,
13+
);
914
}

os/src/task/task.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//!Implementation of [`TaskControlBlock`]
22
use super::TaskContext;
3-
use super::{pid_alloc, KernelStack, PidHandle};
3+
use super::{KernelStack, PidHandle, pid_alloc};
44
use crate::config::TRAP_CONTEXT;
5-
use crate::mm::{MemorySet, PhysPageNum, VirtAddr, KERNEL_SPACE};
5+
use crate::mm::{KERNEL_SPACE, MemorySet, PhysPageNum, VirtAddr};
66
use crate::sync::UPSafeCell;
7-
use crate::trap::{trap_handler, TrapContext};
7+
use crate::trap::{TrapContext, trap_handler};
88
use alloc::sync::{Arc, Weak};
99
use alloc::vec::Vec;
1010
use core::cell::RefMut;

os/src/trap/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Implementation of [`TrapContext`]
2-
use riscv::register::sstatus::{self, Sstatus, SPP};
2+
use riscv::register::sstatus::{self, SPP, Sstatus};
33

44
#[repr(C)]
55
///trap context structure containing sstatus, sepc and registers

os/src/trap/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn enable_timer_interrupt() {
5050
}
5151
}
5252

53-
#[no_mangle]
53+
#[unsafe(no_mangle)]
5454
/// handle an interrupt, exception, or system call from user space
5555
pub fn trap_handler() -> ! {
5656
set_kernel_trap_entry();
@@ -102,17 +102,17 @@ pub fn trap_handler() -> ! {
102102
trap_return();
103103
}
104104

105-
#[no_mangle]
105+
#[unsafe(no_mangle)]
106106
/// set the new addr of __restore asm function in TRAMPOLINE page,
107107
/// set the reg a0 = trap_cx_ptr, reg a1 = phy addr of usr page table,
108108
/// finally, jump to new addr of __restore asm function
109109
pub fn trap_return() -> ! {
110110
set_user_trap_entry();
111111
let trap_cx_ptr = TRAP_CONTEXT;
112112
let user_satp = current_user_token();
113-
extern "C" {
114-
fn __alltraps();
115-
fn __restore();
113+
unsafe extern "C" {
114+
unsafe fn __alltraps();
115+
unsafe fn __restore();
116116
}
117117
let restore_va = __restore as usize - __alltraps as usize + TRAMPOLINE;
118118
unsafe {
@@ -127,7 +127,7 @@ pub fn trap_return() -> ! {
127127
}
128128
}
129129

130-
#[no_mangle]
130+
#[unsafe(no_mangle)]
131131
/// Unimplement: traps/interrupts/exceptions from kernel mode
132132
/// Todo: Chapter 9: I/O device
133133
pub fn trap_from_kernel() -> ! {

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/exit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use user_lib::{exit, fork, wait, waitpid, yield_};
77

88
const MAGIC: i32 = -0x10384;
99

10-
#[no_mangle]
10+
#[unsafe(no_mangle)]
1111
pub fn main() -> i32 {
1212
println!("I am the parent. Forking the child...");
1313
let pid = fork();

0 commit comments

Comments
 (0)