Bump Rust version to nightly-2025-02-18(2024 Edition)

This commit is contained in:
Yifan Wu 2025-02-19 21:27:17 +08:00
parent 123595601d
commit 5b846fce6a
44 changed files with 118 additions and 105 deletions

View file

@ -2,7 +2,7 @@
name = "os"
version = "0.1.0"
authors = ["Yifan Wu <shinbokuow@163.com>"]
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,7 +1,7 @@
use super::BlockDevice;
use crate::mm::{
frame_alloc, frame_dealloc, kernel_token, FrameTracker, PageTable, PhysAddr, PhysPageNum,
StepByOne, VirtAddr,
FrameTracker, PageTable, PhysAddr, PhysPageNum, StepByOne, VirtAddr, frame_alloc,
frame_dealloc, kernel_token,
};
use crate::sync::UPSafeCell;
use alloc::vec::Vec;

View file

@ -15,5 +15,5 @@ pub trait File: Send + Sync {
fn write(&self, buf: UserBuffer) -> usize;
}
pub use inode::{list_apps, open_file, OSInode, OpenFlags};
pub use inode::{OSInode, OpenFlags, list_apps, open_file};
pub use stdio::{Stdin, Stdout};

View file

@ -10,10 +10,10 @@ fn panic(info: &PanicInfo) -> ! {
"[kernel] Panicked at {}:{} {}",
location.file(),
location.line(),
info.message().unwrap()
info.message()
);
} else {
error!("[kernel] Panicked: {}", info.message().unwrap());
error!("[kernel] Panicked: {}", info.message());
}
shutdown(true)
}

View file

@ -23,7 +23,6 @@
#![allow(unused_imports)]
#![no_std]
#![no_main]
#![feature(panic_info_message)]
#![feature(alloc_error_handler)]
extern crate alloc;
@ -56,9 +55,9 @@ use core::arch::global_asm;
global_asm!(include_str!("entry.asm"));
/// clear BSS segment
fn clear_bss() {
extern "C" {
fn sbss();
fn ebss();
unsafe extern "C" {
safe fn sbss();
safe fn ebss();
}
unsafe {
core::slice::from_raw_parts_mut(sbss as usize as *mut u8, ebss as usize - sbss as usize)
@ -66,8 +65,8 @@ fn clear_bss() {
}
}
#[no_mangle]
/// the rust entry-point of os
#[unsafe(no_mangle)]
pub fn rust_main() -> ! {
clear_bss();
logging::init();

View file

@ -94,8 +94,8 @@ lazy_static! {
}
/// initiate the frame allocator using `ekernel` and `MEMORY_END`
pub fn init_frame_allocator() {
extern "C" {
fn ekernel();
unsafe extern "C" {
safe fn ekernel();
}
FRAME_ALLOCATOR.exclusive_access().init(
PhysAddr::from(ekernel as usize).ceil(),

View file

@ -1,6 +1,7 @@
//! The global allocator
use crate::config::KERNEL_HEAP_SIZE;
use buddy_system_allocator::LockedHeap;
use core::ptr::addr_of_mut;
#[global_allocator]
/// heap allocator instance
@ -18,7 +19,7 @@ pub fn init_heap() {
unsafe {
HEAP_ALLOCATOR
.lock()
.init(HEAP_SPACE.as_ptr() as usize, KERNEL_HEAP_SIZE);
.init(addr_of_mut!(HEAP_SPACE) as usize, KERNEL_HEAP_SIZE);
}
}
@ -26,9 +27,9 @@ pub fn init_heap() {
pub fn heap_test() {
use alloc::boxed::Box;
use alloc::vec::Vec;
extern "C" {
fn sbss();
fn ebss();
unsafe extern "C" {
safe fn sbss();
safe fn ebss();
}
let bss_range = sbss as usize..ebss as usize;
let a = Box::new(5);

View file

@ -1,5 +1,6 @@
//! Implementation of [`MapArea`] and [`MemorySet`].
use super::{frame_alloc, FrameTracker};
use super::{FrameTracker, frame_alloc};
use super::{PTEFlags, PageTable, PageTableEntry};
use super::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
use super::{StepByOne, VPNRange};
@ -12,17 +13,17 @@ use core::arch::asm;
use lazy_static::*;
use riscv::register::satp;
extern "C" {
fn stext();
fn etext();
fn srodata();
fn erodata();
fn sdata();
fn edata();
fn sbss_with_stack();
fn ebss();
fn ekernel();
fn strampoline();
unsafe extern "C" {
safe fn stext();
safe fn etext();
safe fn srodata();
safe fn erodata();
safe fn sdata();
safe fn edata();
safe fn sbss_with_stack();
safe fn ebss();
safe fn ekernel();
safe fn strampoline();
}
lazy_static! {
@ -389,20 +390,26 @@ pub fn remap_test() {
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
assert!(!kernel_space
.page_table
.translate(mid_text.floor())
.unwrap()
.writable(),);
assert!(!kernel_space
.page_table
.translate(mid_rodata.floor())
.unwrap()
.writable(),);
assert!(!kernel_space
.page_table
.translate(mid_data.floor())
.unwrap()
.executable(),);
assert!(
!kernel_space
.page_table
.translate(mid_text.floor())
.unwrap()
.writable(),
);
assert!(
!kernel_space
.page_table
.translate(mid_rodata.floor())
.unwrap()
.writable(),
);
assert!(
!kernel_space
.page_table
.translate(mid_data.floor())
.unwrap()
.executable(),
);
println!("remap_test passed!");
}

View file

@ -13,13 +13,13 @@ mod page_table;
use address::VPNRange;
pub use address::{PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum};
pub use frame_allocator::{frame_alloc, frame_dealloc, FrameTracker};
pub use frame_allocator::{FrameTracker, frame_alloc, frame_dealloc};
pub use memory_set::remap_test;
pub use memory_set::{kernel_token, MapPermission, MemorySet, KERNEL_SPACE};
pub use memory_set::{KERNEL_SPACE, MapPermission, MemorySet, kernel_token};
use page_table::PTEFlags;
pub use page_table::{
translated_byte_buffer, translated_ref, translated_refmut, translated_str, PageTable,
PageTableEntry, UserBuffer, UserBufferIterator,
PageTable, PageTableEntry, UserBuffer, UserBufferIterator, translated_byte_buffer,
translated_ref, translated_refmut, translated_str,
};
/// initiate heap allocator, frame allocator and kernel space
pub fn init() {

View file

@ -1,5 +1,6 @@
//! Implementation of [`PageTableEntry`] and [`PageTable`].
use super::{frame_alloc, FrameTracker, PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum};
use super::{FrameTracker, PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum, frame_alloc};
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;

View file

@ -20,7 +20,7 @@ pub fn set_timer(timer: usize) {
/// use sbi call to shutdown the kernel
pub fn shutdown(failure: bool) -> ! {
use sbi_rt::{system_reset, NoReason, Shutdown, SystemFailure};
use sbi_rt::{NoReason, Shutdown, SystemFailure, system_reset};
if !failure {
system_reset(Shutdown, NoReason);
} else {

View file

@ -1,6 +1,6 @@
//! File and filesystem-related syscalls
use crate::fs::{open_file, OpenFlags};
use crate::mm::{translated_byte_buffer, translated_str, UserBuffer};
use crate::fs::{OpenFlags, open_file};
use crate::mm::{UserBuffer, translated_byte_buffer, translated_str};
use crate::task::{current_task, current_user_token};
pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize {

View file

@ -1,4 +1,4 @@
use crate::fs::{open_file, OpenFlags};
use crate::fs::{OpenFlags, open_file};
use crate::mm::{translated_refmut, translated_str};
use crate::task::{
add_task, current_task, current_user_token, exit_current_and_run_next,

View file

@ -23,20 +23,20 @@ mod switch;
#[allow(rustdoc::private_intra_doc_links)]
mod task;
use crate::fs::{open_file, OpenFlags};
use crate::fs::{OpenFlags, open_file};
use crate::sbi::shutdown;
use alloc::sync::Arc;
pub use context::TaskContext;
use lazy_static::*;
pub use manager::{fetch_task, TaskManager};
pub use manager::{TaskManager, fetch_task};
use switch::__switch;
use task::{TaskControlBlock, TaskStatus};
pub use manager::add_task;
pub use pid::{pid_alloc, KernelStack, PidAllocator, PidHandle};
pub use pid::{KernelStack, PidAllocator, PidHandle, pid_alloc};
pub use processor::{
current_task, current_trap_cx, current_user_token, run_tasks, schedule, take_current_task,
Processor,
Processor, current_task, current_trap_cx, current_user_token, run_tasks, schedule,
take_current_task,
};
/// Suspend the current 'Running' task and run the next task in task list.
pub fn suspend_current_and_run_next() {

View file

@ -1,6 +1,6 @@
//!Implementation of [`PidAllocator`]
use crate::config::{KERNEL_STACK_SIZE, PAGE_SIZE, TRAMPOLINE};
use crate::mm::{MapPermission, VirtAddr, KERNEL_SPACE};
use crate::mm::{KERNEL_SPACE, MapPermission, VirtAddr};
use crate::sync::UPSafeCell;
use alloc::vec::Vec;
use lazy_static::*;

View file

@ -1,7 +1,7 @@
//!Implementation of [`Processor`] and Intersection of control flow
use super::__switch;
use super::{fetch_task, TaskStatus};
use super::{TaskContext, TaskControlBlock};
use super::{TaskStatus, fetch_task};
use crate::sync::UPSafeCell;
use crate::trap::TrapContext;
use alloc::sync::Arc;

View file

@ -4,6 +4,11 @@ use core::arch::global_asm;
global_asm!(include_str!("switch.S"));
extern "C" {
pub fn __switch(current_task_cx_ptr: *mut TaskContext, next_task_cx_ptr: *const TaskContext);
unsafe extern "C" {
/// Switch to the context of `next_task_cx_ptr`, saving the current context
/// in `current_task_cx_ptr`.
pub unsafe fn __switch(
current_task_cx_ptr: *mut TaskContext,
next_task_cx_ptr: *const TaskContext,
);
}

View file

@ -1,11 +1,11 @@
//!Implementation of [`TaskControlBlock`]
use super::TaskContext;
use super::{pid_alloc, KernelStack, PidHandle};
use super::{KernelStack, PidHandle, pid_alloc};
use crate::config::TRAP_CONTEXT;
use crate::fs::{File, Stdin, Stdout};
use crate::mm::{MemorySet, PhysPageNum, VirtAddr, KERNEL_SPACE};
use crate::mm::{KERNEL_SPACE, MemorySet, PhysPageNum, VirtAddr};
use crate::sync::UPSafeCell;
use crate::trap::{trap_handler, TrapContext};
use crate::trap::{TrapContext, trap_handler};
use alloc::sync::{Arc, Weak};
use alloc::vec;
use alloc::vec::Vec;

View file

@ -1,5 +1,5 @@
//! Implementation of [`TrapContext`]
use riscv::register::sstatus::{self, Sstatus, SPP};
use riscv::register::sstatus::{self, SPP, Sstatus};
#[repr(C)]
#[derive(Debug)]

View file

@ -50,7 +50,7 @@ pub fn enable_timer_interrupt() {
}
}
#[no_mangle]
#[unsafe(no_mangle)]
/// handle an interrupt, exception, or system call from user space
pub fn trap_handler() -> ! {
set_kernel_trap_entry();
@ -103,7 +103,7 @@ pub fn trap_handler() -> ! {
trap_return();
}
#[no_mangle]
#[unsafe(no_mangle)]
/// set the new addr of __restore asm function in TRAMPOLINE page,
/// set the reg a0 = trap_cx_ptr, reg a1 = phy addr of usr page table,
/// finally, jump to new addr of __restore asm function
@ -111,9 +111,9 @@ pub fn trap_return() -> ! {
set_user_trap_entry();
let trap_cx_ptr = TRAP_CONTEXT;
let user_satp = current_user_token();
extern "C" {
fn __alltraps();
fn __restore();
unsafe extern "C" {
unsafe fn __alltraps();
unsafe fn __restore();
}
let restore_va = __restore as usize - __alltraps as usize + TRAMPOLINE;
unsafe {
@ -128,7 +128,7 @@ pub fn trap_return() -> ! {
}
}
#[no_mangle]
#[unsafe(no_mangle)]
/// Unimplement: traps/interrupts/exceptions from kernel mode
/// Todo: Chapter 9: I/O device
pub fn trap_from_kernel() -> ! {