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();

0 commit comments

Comments
 (0)