From 5b846fce6a826da3eb19417adf73df9d315088b2 Mon Sep 17 00:00:00 2001 From: Yifan Wu Date: Wed, 19 Feb 2025 21:27:17 +0800 Subject: [PATCH] Bump Rust version to nightly-2025-02-18(2024 Edition) --- .github/workflows/doc-and-test.yml | 2 +- os/Cargo.toml | 2 +- os/src/drivers/block/virtio_blk.rs | 4 +- os/src/fs/mod.rs | 2 +- os/src/lang_items.rs | 4 +- os/src/main.rs | 9 ++--- os/src/mm/frame_allocator.rs | 4 +- os/src/mm/heap_allocator.rs | 9 +++-- os/src/mm/memory_set.rs | 61 +++++++++++++++++------------- os/src/mm/mod.rs | 8 ++-- os/src/mm/page_table.rs | 3 +- os/src/sbi.rs | 2 +- os/src/syscall/fs.rs | 4 +- os/src/syscall/process.rs | 2 +- os/src/task/mod.rs | 10 ++--- os/src/task/pid.rs | 2 +- os/src/task/processor.rs | 2 +- os/src/task/switch.rs | 9 ++++- os/src/task/task.rs | 6 +-- os/src/trap/context.rs | 2 +- os/src/trap/mod.rs | 12 +++--- rust-toolchain.toml | 2 +- user/Cargo.toml | 2 +- user/src/bin/cat_filea.rs | 4 +- user/src/bin/exit.rs | 2 +- user/src/bin/fantastic_text.rs | 6 +-- user/src/bin/filetest_simple.rs | 4 +- user/src/bin/forktest.rs | 2 +- user/src/bin/forktest2.rs | 2 +- user/src/bin/forktest_simple.rs | 2 +- user/src/bin/forktree.rs | 2 +- user/src/bin/hello_world.rs | 2 +- user/src/bin/huge_write.rs | 4 +- user/src/bin/initproc.rs | 2 +- user/src/bin/matrix.rs | 2 +- user/src/bin/sleep.rs | 2 +- user/src/bin/sleep_simple.rs | 2 +- user/src/bin/stack_overflow.rs | 2 +- user/src/bin/user_shell.rs | 2 +- user/src/bin/usertests.rs | 2 +- user/src/bin/usertests_simple.rs | 2 +- user/src/bin/yield.rs | 2 +- user/src/lang_items.rs | 2 +- user/src/lib.rs | 10 ++--- 44 files changed, 118 insertions(+), 105 deletions(-) diff --git a/.github/workflows/doc-and-test.yml b/.github/workflows/doc-and-test.yml index 72f124b..9fee30e 100644 --- a/.github/workflows/doc-and-test.yml +++ b/.github/workflows/doc-and-test.yml @@ -4,7 +4,7 @@ on: [push] env: CARGO_TERM_COLOR: always - rust_toolchain: nightly-2024-01-18 + rust_toolchain: nightly-2025-02-18 jobs: build-doc: diff --git a/os/Cargo.toml b/os/Cargo.toml index b65ed6e..d621557 100644 --- a/os/Cargo.toml +++ b/os/Cargo.toml @@ -2,7 +2,7 @@ name = "os" version = "0.1.0" authors = ["Yifan Wu "] -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/os/src/drivers/block/virtio_blk.rs b/os/src/drivers/block/virtio_blk.rs index 9755250..5097831 100644 --- a/os/src/drivers/block/virtio_blk.rs +++ b/os/src/drivers/block/virtio_blk.rs @@ -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; diff --git a/os/src/fs/mod.rs b/os/src/fs/mod.rs index 6c790fe..c3cc1e7 100644 --- a/os/src/fs/mod.rs +++ b/os/src/fs/mod.rs @@ -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}; diff --git a/os/src/lang_items.rs b/os/src/lang_items.rs index 26951f8..79cd51e 100644 --- a/os/src/lang_items.rs +++ b/os/src/lang_items.rs @@ -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) } diff --git a/os/src/main.rs b/os/src/main.rs index ad60a70..46161de 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -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(); diff --git a/os/src/mm/frame_allocator.rs b/os/src/mm/frame_allocator.rs index f3d18ea..28b519c 100644 --- a/os/src/mm/frame_allocator.rs +++ b/os/src/mm/frame_allocator.rs @@ -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(), diff --git a/os/src/mm/heap_allocator.rs b/os/src/mm/heap_allocator.rs index e5f8b30..a6b413b 100644 --- a/os/src/mm/heap_allocator.rs +++ b/os/src/mm/heap_allocator.rs @@ -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); diff --git a/os/src/mm/memory_set.rs b/os/src/mm/memory_set.rs index a2c31cd..b1e5072 100644 --- a/os/src/mm/memory_set.rs +++ b/os/src/mm/memory_set.rs @@ -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!"); } diff --git a/os/src/mm/mod.rs b/os/src/mm/mod.rs index 65f1e9a..3255725 100644 --- a/os/src/mm/mod.rs +++ b/os/src/mm/mod.rs @@ -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() { diff --git a/os/src/mm/page_table.rs b/os/src/mm/page_table.rs index 9fbd21b..f5fdf2b 100644 --- a/os/src/mm/page_table.rs +++ b/os/src/mm/page_table.rs @@ -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; diff --git a/os/src/sbi.rs b/os/src/sbi.rs index eb79f67..a73476f 100644 --- a/os/src/sbi.rs +++ b/os/src/sbi.rs @@ -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 { diff --git a/os/src/syscall/fs.rs b/os/src/syscall/fs.rs index aecc790..ff68ee9 100644 --- a/os/src/syscall/fs.rs +++ b/os/src/syscall/fs.rs @@ -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 { diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index 3d62cbb..61e78d6 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -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, diff --git a/os/src/task/mod.rs b/os/src/task/mod.rs index e4837cb..47c13cd 100644 --- a/os/src/task/mod.rs +++ b/os/src/task/mod.rs @@ -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() { diff --git a/os/src/task/pid.rs b/os/src/task/pid.rs index a7bdea9..f0a5e2a 100644 --- a/os/src/task/pid.rs +++ b/os/src/task/pid.rs @@ -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::*; diff --git a/os/src/task/processor.rs b/os/src/task/processor.rs index 1d9c0f2..7c05a21 100644 --- a/os/src/task/processor.rs +++ b/os/src/task/processor.rs @@ -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; diff --git a/os/src/task/switch.rs b/os/src/task/switch.rs index 7d194f5..8f69fdf 100644 --- a/os/src/task/switch.rs +++ b/os/src/task/switch.rs @@ -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, + ); } diff --git a/os/src/task/task.rs b/os/src/task/task.rs index 6e38b92..7b02cd6 100644 --- a/os/src/task/task.rs +++ b/os/src/task/task.rs @@ -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; diff --git a/os/src/trap/context.rs b/os/src/trap/context.rs index 0cae492..5f968e5 100644 --- a/os/src/trap/context.rs +++ b/os/src/trap/context.rs @@ -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)] diff --git a/os/src/trap/mod.rs b/os/src/trap/mod.rs index 49b85ec..26e7895 100644 --- a/os/src/trap/mod.rs +++ b/os/src/trap/mod.rs @@ -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() -> ! { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c65d258..e6f10a1 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,6 +1,6 @@ [toolchain] profile = "minimal" # use the nightly version of the last stable toolchain, see -channel = "nightly-2024-05-01" +channel = "nightly-2025-02-18" components = ["rust-src", "llvm-tools", "rustfmt", "clippy"] targets = ["riscv64gc-unknown-none-elf"] diff --git a/user/Cargo.toml b/user/Cargo.toml index 3bc82dc..92f3f7e 100644 --- a/user/Cargo.toml +++ b/user/Cargo.toml @@ -2,7 +2,7 @@ name = "user_lib" version = "0.1.0" authors = ["Yifan Wu "] -edition = "2018" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/user/src/bin/cat_filea.rs b/user/src/bin/cat_filea.rs index 6307ecd..20daf77 100644 --- a/user/src/bin/cat_filea.rs +++ b/user/src/bin/cat_filea.rs @@ -5,9 +5,9 @@ extern crate user_lib; extern crate alloc; -use user_lib::{close, open, read, OpenFlags}; +use user_lib::{OpenFlags, close, open, read}; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { let fd = open("filea\0", OpenFlags::RDONLY); if fd == -1 { diff --git a/user/src/bin/exit.rs b/user/src/bin/exit.rs index 60510c9..8e19542 100644 --- a/user/src/bin/exit.rs +++ b/user/src/bin/exit.rs @@ -7,7 +7,7 @@ use user_lib::{exit, fork, wait, waitpid, yield_}; const MAGIC: i32 = -0x10384; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { println!("I am the parent. Forking the child..."); let pid = fork(); diff --git a/user/src/bin/fantastic_text.rs b/user/src/bin/fantastic_text.rs index a3402ff..0850162 100644 --- a/user/src/bin/fantastic_text.rs +++ b/user/src/bin/fantastic_text.rs @@ -5,12 +5,12 @@ extern crate user_lib; macro_rules! color_text { - ($text:expr, $color:expr) => {{ + ($text:expr, $color:expr) => { format_args!("\x1b[{}m{}\x1b[0m", $color, $text) - }}; + }; } -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { println!( "{}{}{}{}{} {}{}{}{} {}{}{}{}{}{}", diff --git a/user/src/bin/filetest_simple.rs b/user/src/bin/filetest_simple.rs index 3406d55..b192156 100644 --- a/user/src/bin/filetest_simple.rs +++ b/user/src/bin/filetest_simple.rs @@ -4,9 +4,9 @@ #[macro_use] extern crate user_lib; -use user_lib::{close, open, read, write, OpenFlags}; +use user_lib::{OpenFlags, close, open, read, write}; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { let test_str = "Hello, world!"; let filea = "filea\0"; diff --git a/user/src/bin/forktest.rs b/user/src/bin/forktest.rs index 5374a56..f6003c5 100644 --- a/user/src/bin/forktest.rs +++ b/user/src/bin/forktest.rs @@ -8,7 +8,7 @@ use user_lib::{exit, fork, wait}; const MAX_CHILD: usize = 30; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { for i in 0..MAX_CHILD { let pid = fork(); diff --git a/user/src/bin/forktest2.rs b/user/src/bin/forktest2.rs index c91ce15..ee452cc 100644 --- a/user/src/bin/forktest2.rs +++ b/user/src/bin/forktest2.rs @@ -8,7 +8,7 @@ use user_lib::{exit, fork, get_time, getpid, sleep, wait}; static NUM: usize = 30; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { for _ in 0..NUM { let pid = fork(); diff --git a/user/src/bin/forktest_simple.rs b/user/src/bin/forktest_simple.rs index 29a624b..b9cf587 100644 --- a/user/src/bin/forktest_simple.rs +++ b/user/src/bin/forktest_simple.rs @@ -6,7 +6,7 @@ extern crate user_lib; use user_lib::{fork, getpid, wait}; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { assert_eq!(wait(&mut 0i32), -1); println!("sys_wait without child process test passed!"); diff --git a/user/src/bin/forktree.rs b/user/src/bin/forktree.rs index bfcfc4c..bcca4e6 100644 --- a/user/src/bin/forktree.rs +++ b/user/src/bin/forktree.rs @@ -29,7 +29,7 @@ fn fork_tree(cur: &str) { fork_child(cur, '1'); } -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { fork_tree(""); sleep(3000); diff --git a/user/src/bin/hello_world.rs b/user/src/bin/hello_world.rs index 10d3f26..cc651e7 100644 --- a/user/src/bin/hello_world.rs +++ b/user/src/bin/hello_world.rs @@ -4,7 +4,7 @@ #[macro_use] extern crate user_lib; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { println!("Hello world from user mode program!"); 0 diff --git a/user/src/bin/huge_write.rs b/user/src/bin/huge_write.rs index e93f8b8..9327261 100644 --- a/user/src/bin/huge_write.rs +++ b/user/src/bin/huge_write.rs @@ -4,9 +4,9 @@ #[macro_use] extern crate user_lib; -use user_lib::{close, get_time, open, write, OpenFlags}; +use user_lib::{OpenFlags, close, get_time, open, write}; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { let mut buffer = [0u8; 1024]; // 1KiB for (i, ch) in buffer.iter_mut().enumerate() { diff --git a/user/src/bin/initproc.rs b/user/src/bin/initproc.rs index 71bed27..d522b77 100644 --- a/user/src/bin/initproc.rs +++ b/user/src/bin/initproc.rs @@ -6,7 +6,7 @@ extern crate user_lib; use user_lib::{exec, fork, wait, yield_}; -#[no_mangle] +#[unsafe(no_mangle)] fn main() -> i32 { if fork() == 0 { exec("user_shell\0"); diff --git a/user/src/bin/matrix.rs b/user/src/bin/matrix.rs index 9ebf48f..846f4c6 100644 --- a/user/src/bin/matrix.rs +++ b/user/src/bin/matrix.rs @@ -44,7 +44,7 @@ fn work(times: isize) { exit(0); } -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { for _ in 0..NUM { let pid = fork(); diff --git a/user/src/bin/sleep.rs b/user/src/bin/sleep.rs index 641a4f9..e02b3ed 100644 --- a/user/src/bin/sleep.rs +++ b/user/src/bin/sleep.rs @@ -15,7 +15,7 @@ fn sleepy() { exit(0); } -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { let current_time = get_time(); let pid = fork(); diff --git a/user/src/bin/sleep_simple.rs b/user/src/bin/sleep_simple.rs index 7015a3d..9f6e2e4 100644 --- a/user/src/bin/sleep_simple.rs +++ b/user/src/bin/sleep_simple.rs @@ -6,7 +6,7 @@ extern crate user_lib; use user_lib::{get_time, sleep}; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { println!("into sleep test!"); let start = get_time(); diff --git a/user/src/bin/stack_overflow.rs b/user/src/bin/stack_overflow.rs index 3bec557..731982a 100644 --- a/user/src/bin/stack_overflow.rs +++ b/user/src/bin/stack_overflow.rs @@ -12,7 +12,7 @@ fn f(depth: usize) { f(depth + 1); } -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { println!("It should trigger segmentation fault!"); f(0); diff --git a/user/src/bin/user_shell.rs b/user/src/bin/user_shell.rs index cdcb972..1ca120b 100644 --- a/user/src/bin/user_shell.rs +++ b/user/src/bin/user_shell.rs @@ -16,7 +16,7 @@ use alloc::string::String; use user_lib::console::getchar; use user_lib::{exec, fork, waitpid}; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { println!("Rust user shell"); let mut line: String = String::new(); diff --git a/user/src/bin/usertests.rs b/user/src/bin/usertests.rs index 20cbbe9..d47dc20 100644 --- a/user/src/bin/usertests.rs +++ b/user/src/bin/usertests.rs @@ -84,7 +84,7 @@ fn run_tests(tests: &[(&str, &str, &str, &str, i32)]) -> i32 { pass_num } -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { let succ_num = run_tests(SUCC_TESTS); let err_num = run_tests(FAIL_TESTS); diff --git a/user/src/bin/usertests_simple.rs b/user/src/bin/usertests_simple.rs index 62bc838..0a73edd 100644 --- a/user/src/bin/usertests_simple.rs +++ b/user/src/bin/usertests_simple.rs @@ -20,7 +20,7 @@ static TESTS: &[&str] = &[ use user_lib::{exec, fork, waitpid}; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { for test in TESTS { println!("Usertests: Running {}", test); diff --git a/user/src/bin/yield.rs b/user/src/bin/yield.rs index 78b1468..b9558ef 100644 --- a/user/src/bin/yield.rs +++ b/user/src/bin/yield.rs @@ -5,7 +5,7 @@ extern crate user_lib; use user_lib::{getpid, yield_}; -#[no_mangle] +#[unsafe(no_mangle)] pub fn main() -> i32 { println!("Hello, I am process {}.", getpid()); for i in 0..5 { diff --git a/user/src/lang_items.rs b/user/src/lang_items.rs index c65aa42..b03e8eb 100644 --- a/user/src/lang_items.rs +++ b/user/src/lang_items.rs @@ -2,7 +2,7 @@ use super::exit; #[panic_handler] fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! { - let err = panic_info.message().unwrap(); + let err = panic_info.message(); if let Some(location) = panic_info.location() { println!( "Panicked at {}:{}, {}", diff --git a/user/src/lib.rs b/user/src/lib.rs index c3b2cb9..a5584c2 100644 --- a/user/src/lib.rs +++ b/user/src/lib.rs @@ -1,6 +1,5 @@ #![no_std] #![feature(linkage)] -#![feature(panic_info_message)] #![feature(alloc_error_handler)] #[macro_use] @@ -13,6 +12,7 @@ extern crate alloc; extern crate bitflags; use buddy_system_allocator::LockedHeap; +use core::ptr::addr_of_mut; use syscall::*; const USER_HEAP_SIZE: usize = 32768; @@ -27,18 +27,18 @@ pub fn handle_alloc_error(layout: core::alloc::Layout) -> ! { panic!("Heap allocation error, layout = {:?}", layout); } -#[no_mangle] -#[link_section = ".text.entry"] +#[unsafe(no_mangle)] +#[unsafe(link_section = ".text.entry")] pub extern "C" fn _start() -> ! { unsafe { HEAP.lock() - .init(HEAP_SPACE.as_ptr() as usize, USER_HEAP_SIZE); + .init(addr_of_mut!(HEAP_SPACE) as usize, USER_HEAP_SIZE); } exit(main()); } #[linkage = "weak"] -#[no_mangle] +#[unsafe(no_mangle)] fn main() -> i32 { panic!("Cannot find main!"); }