Skip to content

Commit 3817ec5

Browse files
committed
Bump Rust version to nightly-2025-02-18(2024 Edition)
1 parent 4677d2a commit 3817ec5

27 files changed

+105
-97
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
@@ -12,10 +12,10 @@ fn panic(info: &PanicInfo) -> ! {
1212
"[kernel] Panicked at {}:{} {}",
1313
location.file(),
1414
location.line(),
15-
info.message().unwrap()
15+
info.message()
1616
);
1717
} else {
18-
error!("[kernel] Panicked: {}", info.message().unwrap());
18+
error!("[kernel] Panicked: {}", info.message());
1919
}
2020
shutdown(true)
2121
}

os/src/loader.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
33
/// Get the total number of applications.
44
pub fn get_num_app() -> usize {
5-
extern "C" {
6-
fn _num_app();
5+
unsafe extern "C" {
6+
safe fn _num_app();
77
}
88
unsafe { (_num_app as usize as *const usize).read_volatile() }
99
}
1010

1111
/// get applications data
1212
pub fn get_app_data(app_id: usize) -> &'static [u8] {
13-
extern "C" {
14-
fn _num_app();
13+
unsafe extern "C" {
14+
safe fn _num_app();
1515
}
1616
let num_app_ptr = _num_app as usize as *const usize;
1717
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
#![feature(alloc_error_handler)]
2423

2524
extern crate alloc;
@@ -51,18 +50,18 @@ core::arch::global_asm!(include_str!("link_app.S"));
5150

5251
/// clear BSS segment
5352
fn clear_bss() {
54-
extern "C" {
55-
fn sbss();
56-
fn ebss();
53+
unsafe extern "C" {
54+
safe fn sbss();
55+
safe fn ebss();
5756
}
5857
unsafe {
5958
core::slice::from_raw_parts_mut(sbss as usize as *mut u8, ebss as usize - sbss as usize)
6059
.fill(0);
6160
}
6261
}
6362

64-
#[no_mangle]
6563
/// the rust entry-point of os
64+
#[unsafe(no_mangle)]
6665
pub fn rust_main() -> ! {
6766
clear_bss();
6867
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
@@ -2,6 +2,7 @@
22
33
use crate::config::KERNEL_HEAP_SIZE;
44
use buddy_system_allocator::LockedHeap;
5+
use core::ptr::addr_of_mut;
56

67
#[global_allocator]
78
/// heap allocator instance
@@ -21,17 +22,17 @@ pub fn init_heap() {
2122
unsafe {
2223
HEAP_ALLOCATOR
2324
.lock()
24-
.init(HEAP_SPACE.as_ptr() as usize, KERNEL_HEAP_SIZE);
25+
.init(addr_of_mut!(HEAP_SPACE) as usize, KERNEL_HEAP_SIZE);
2526
}
2627
}
2728

2829
#[allow(unused)]
2930
pub fn heap_test() {
3031
use alloc::boxed::Box;
3132
use alloc::vec::Vec;
32-
extern "C" {
33-
fn sbss();
34-
fn ebss();
33+
unsafe extern "C" {
34+
safe fn sbss();
35+
safe fn ebss();
3536
}
3637
let bss_range = sbss as usize..ebss as usize;
3738
let a = Box::new(5);

os/src/mm/memory_set.rs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Implementation of [`MapArea`] and [`MemorySet`].
22
3-
use super::{frame_alloc, FrameTracker};
3+
use super::{FrameTracker, frame_alloc};
44
use super::{PTEFlags, PageTable, PageTableEntry};
55
use super::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
66
use super::{StepByOne, VPNRange};
@@ -13,17 +13,17 @@ use core::arch::asm;
1313
use lazy_static::*;
1414
use riscv::register::satp;
1515

16-
extern "C" {
17-
fn stext();
18-
fn etext();
19-
fn srodata();
20-
fn erodata();
21-
fn sdata();
22-
fn edata();
23-
fn sbss_with_stack();
24-
fn ebss();
25-
fn ekernel();
26-
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();
2727
}
2828

2929
lazy_static! {
@@ -386,20 +386,26 @@ pub fn remap_test() {
386386
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
387387
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
388388
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
389-
assert!(!kernel_space
390-
.page_table
391-
.translate(mid_text.floor())
392-
.unwrap()
393-
.writable(),);
394-
assert!(!kernel_space
395-
.page_table
396-
.translate(mid_rodata.floor())
397-
.unwrap()
398-
.writable(),);
399-
assert!(!kernel_space
400-
.page_table
401-
.translate(mid_data.floor())
402-
.unwrap()
403-
.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+
);
404410
println!("remap_test passed!");
405411
}

os/src/mm/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ mod page_table;
1414

1515
pub use address::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
1616
use address::{StepByOne, VPNRange};
17-
pub use frame_allocator::{frame_alloc, FrameTracker};
17+
pub use frame_allocator::{FrameTracker, frame_alloc};
1818
pub use memory_set::remap_test;
19-
pub use memory_set::{MapPermission, MemorySet, KERNEL_SPACE};
20-
pub use page_table::{translated_byte_buffer, PageTableEntry};
19+
pub use memory_set::{KERNEL_SPACE, MapPermission, MemorySet};
2120
use page_table::{PTEFlags, PageTable};
21+
pub use page_table::{PageTableEntry, translated_byte_buffer};
2222

2323
/// initiate heap allocator, frame allocator and kernel space
2424
pub fn init() {

0 commit comments

Comments
 (0)