Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Build syscall
uses: actions-rs/cargo@v1
with:
command: build
args: --package syscall

- name: Check format
run: cargo fmt --all --check
Expand Down
13 changes: 10 additions & 3 deletions ch1-lab/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ fn main() {
use std::{env, fs, path::PathBuf};

let ld = &PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("linker.ld");
fs::write(ld, if env::var("CARGO_FEATURE_NOBIOS").is_ok() { NOBIOS_LINKER } else { LINKER }).unwrap();
fs::write(
ld,
if env::var("CARGO_FEATURE_NOBIOS").is_ok() {
NOBIOS_LINKER
} else {
LINKER
},
)
.unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_NOBIOS");
println!("cargo:rustc-link-arg=-T{}", ld.display());
Expand Down Expand Up @@ -30,7 +38,6 @@ SECTIONS {
}
}";


const NOBIOS_LINKER: &[u8] = b"
OUTPUT_ARCH(riscv)
ENTRY(_m_start)
Expand Down Expand Up @@ -69,4 +76,4 @@ SECTIONS {
*(.bss .bss.*)
*(.sbss .sbss.*)
}
}";
}";
13 changes: 10 additions & 3 deletions ch1/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ fn main() {
use std::{env, fs, path::PathBuf};

let ld = &PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("linker.ld");
fs::write(ld, if env::var("CARGO_FEATURE_NOBIOS").is_ok() { NOBIOS_LINKER } else { LINKER }).unwrap();
fs::write(
ld,
if env::var("CARGO_FEATURE_NOBIOS").is_ok() {
NOBIOS_LINKER
} else {
LINKER
},
)
.unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_NOBIOS");
println!("cargo:rustc-link-arg=-T{}", ld.display());
Expand Down Expand Up @@ -30,7 +38,6 @@ SECTIONS {
}
}";


const NOBIOS_LINKER: &[u8] = b"
OUTPUT_ARCH(riscv)
ENTRY(_m_start)
Expand Down Expand Up @@ -69,4 +76,4 @@ SECTIONS {
*(.bss .bss.*)
*(.sbss .sbss.*)
}
}";
}";
8 changes: 7 additions & 1 deletion ch3/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ mod impls {
impl Trace for SyscallContext {
// TODO: 实现 trace 系统调用
#[inline]
fn trace(&self, _caller: syscall::Caller, _trace_request: usize, _id: usize, _data: usize) -> isize {
fn trace(
&self,
_caller: syscall::Caller,
_trace_request: usize,
_id: usize,
_data: usize,
) -> isize {
rcore_console::log::info!("trace: not implemented");
-1
}
Expand Down
23 changes: 20 additions & 3 deletions ch4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,33 @@ mod impls {
impl Trace for SyscallContext {
// TODO: 实现 trace 系统调用
#[inline]
fn trace(&self, _caller: syscall::Caller, _trace_request: usize, _id: usize, _data: usize) -> isize {
fn trace(
&self,
_caller: syscall::Caller,
_trace_request: usize,
_id: usize,
_data: usize,
) -> isize {
rcore_console::log::info!("trace: not implemented");
-1
}
}

impl Memory for SyscallContext {
// TODO: 实现 mmap 系统调用
fn mmap(&self, _caller: Caller, addr: usize, len: usize, prot: i32, _flags: i32, _fd: i32, _offset: usize) -> isize {
rcore_console::log::info!("mmap: addr = {addr:#x}, len = {len}, prot = {prot}, not implemented");
fn mmap(
&self,
_caller: Caller,
addr: usize,
len: usize,
prot: i32,
_flags: i32,
_fd: i32,
_offset: usize,
) -> isize {
rcore_console::log::info!(
"mmap: addr = {addr:#x}, len = {len}, prot = {prot}, not implemented"
);
-1
}

Expand Down
40 changes: 33 additions & 7 deletions ch5/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ mod impls {
match fd {
STDOUT | STDDEBUG => {
const READABLE: VmFlags<Sv39> = VmFlags::build_from_str("RV");
if let Some(ptr) = PROCESSOR.get_mut().current()
if let Some(ptr) = PROCESSOR
.get_mut()
.current()
.unwrap()
.address_space
.translate(VAddr::new(buf), READABLE)
Expand Down Expand Up @@ -325,7 +327,10 @@ mod impls {
fn read(&self, _caller: Caller, fd: usize, buf: usize, count: usize) -> isize {
if fd == STDIN {
const WRITEABLE: VmFlags<Sv39> = VmFlags::build_from_str("W_V");
if let Some(mut ptr) = PROCESSOR.get_mut().current().unwrap()
if let Some(mut ptr) = PROCESSOR
.get_mut()
.current()
.unwrap()
.address_space
.translate(VAddr::new(buf), WRITEABLE)
{
Expand Down Expand Up @@ -419,7 +424,10 @@ mod impls {
// TODO: 实现 spawn 系统调用
fn spawn(&self, _caller: Caller, _path: usize, _count: usize) -> isize {
let current = PROCESSOR.get_mut().current().unwrap();
rcore_console::log::info!("spawn: parent pid = {}, not implemented", current.pid.get_usize());
rcore_console::log::info!(
"spawn: parent pid = {}, not implemented",
current.pid.get_usize()
);
-1
}
}
Expand All @@ -433,7 +441,11 @@ mod impls {
// TODO: 实现 set_priority 系统调用
fn set_priority(&self, _caller: Caller, prio: isize) -> isize {
let current = PROCESSOR.get_mut().current().unwrap();
rcore_console::log::info!("set_priority: pid = {}, prio = {}, not implemented", current.pid.get_usize(), prio);
rcore_console::log::info!(
"set_priority: pid = {}, prio = {}, not implemented",
current.pid.get_usize(),
prio
);
-1
}
}
Expand All @@ -444,7 +456,10 @@ mod impls {
const WRITABLE: VmFlags<Sv39> = VmFlags::build_from_str("W_V");
match clock_id {
ClockId::CLOCK_MONOTONIC => {
if let Some(mut ptr) = PROCESSOR.get_mut().current().unwrap()
if let Some(mut ptr) = PROCESSOR
.get_mut()
.current()
.unwrap()
.address_space
.translate(VAddr::new(tp), WRITABLE)
{
Expand All @@ -466,8 +481,19 @@ mod impls {

impl Memory for SyscallContext {
// TODO: 实现 mmap 系统调用
fn mmap(&self, _caller: Caller, addr: usize, len: usize, prot: i32, _flags: i32, _fd: i32, _offset: usize) -> isize {
rcore_console::log::info!("mmap: addr = {addr:#x}, len = {len}, prot = {prot}, not implemented");
fn mmap(
&self,
_caller: Caller,
addr: usize,
len: usize,
prot: i32,
_flags: i32,
_fd: i32,
_offset: usize,
) -> isize {
rcore_console::log::info!(
"mmap: addr = {addr:#x}, len = {len}, prot = {prot}, not implemented"
);
-1
}

Expand Down
41 changes: 35 additions & 6 deletions ch6/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,15 @@ mod impls {
}

// TODO: 实现 linkat 系统调用
fn linkat(&self, _caller: Caller, _olddirfd: i32, _oldpath: usize, _newdirfd: i32, _newpath: usize, _flags: u32) -> isize {
fn linkat(
&self,
_caller: Caller,
_olddirfd: i32,
_oldpath: usize,
_newdirfd: i32,
_newpath: usize,
_flags: u32,
) -> isize {
rcore_console::log::info!("linkat: not implemented");
-1
}
Expand Down Expand Up @@ -510,7 +518,10 @@ mod impls {
// TODO: 实现 spawn 系统调用
fn spawn(&self, _caller: Caller, _path: usize, _count: usize) -> isize {
let current = PROCESSOR.get_mut().current().unwrap();
rcore_console::log::info!("spawn: parent pid = {}, not implemented", current.pid.get_usize());
rcore_console::log::info!(
"spawn: parent pid = {}, not implemented",
current.pid.get_usize()
);
-1
}
}
Expand All @@ -524,7 +535,11 @@ mod impls {
// TODO: 实现 set_priority 系统调用
fn set_priority(&self, _caller: Caller, prio: isize) -> isize {
let current = PROCESSOR.get_mut().current().unwrap();
rcore_console::log::info!("set_priority: pid = {}, prio = {}, not implemented", current.pid.get_usize(), prio);
rcore_console::log::info!(
"set_priority: pid = {}, prio = {}, not implemented",
current.pid.get_usize(),
prio
);
-1
}
}
Expand All @@ -535,7 +550,10 @@ mod impls {
const WRITABLE: VmFlags<Sv39> = VmFlags::build_from_str("W_V");
match clock_id {
ClockId::CLOCK_MONOTONIC => {
if let Some(mut ptr) = PROCESSOR.get_mut().current().unwrap()
if let Some(mut ptr) = PROCESSOR
.get_mut()
.current()
.unwrap()
.address_space
.translate(VAddr::new(tp), WRITABLE)
{
Expand All @@ -557,8 +575,19 @@ mod impls {

impl Memory for SyscallContext {
// TODO: 实现 mmap 系统调用
fn mmap(&self, _caller: Caller, addr: usize, len: usize, prot: i32, _flags: i32, _fd: i32, _offset: usize) -> isize {
rcore_console::log::info!("mmap: addr = {addr:#x}, len = {len}, prot = {prot}, not implemented");
fn mmap(
&self,
_caller: Caller,
addr: usize,
len: usize,
prot: i32,
_flags: i32,
_fd: i32,
_offset: usize,
) -> isize {
rcore_console::log::info!(
"mmap: addr = {addr:#x}, len = {len}, prot = {prot}, not implemented"
);
-1
}

Expand Down
10 changes: 7 additions & 3 deletions ch7/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,10 @@ mod impls {
const WRITABLE: VmFlags<Sv39> = VmFlags::build_from_str("W_V");
match clock_id {
ClockId::CLOCK_MONOTONIC => {
if let Some(mut ptr) = PROCESSOR.get_mut().current().unwrap()
if let Some(mut ptr) = PROCESSOR
.get_mut()
.current()
.unwrap()
.address_space
.translate(VAddr::new(tp), WRITABLE)
{
Expand All @@ -539,8 +542,9 @@ mod impls {

impl Signal for SyscallContext {
fn kill(&self, _caller: Caller, pid: isize, signum: u8) -> isize {
if let Some(target_task) =
PROCESSOR.get_mut().get_task(ProcId::from_usize(pid as usize))
if let Some(target_task) = PROCESSOR
.get_mut()
.get_task(ProcId::from_usize(pid as usize))
{
if let Ok(signal_no) = SignalNo::try_from(signum) {
if signal_no != SignalNo::ERR {
Expand Down
15 changes: 9 additions & 6 deletions ch8/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ extern "C" fn rust_main() -> ! {
let current_proc = unsafe { (*processor).get_current_proc().unwrap() };
match current_proc.signal.handle_signals(ctx) {
// 进程应该结束执行
SignalResult::ProcessKilled(exit_code) => {
unsafe { (*processor).make_current_exited(exit_code as _) }
}
SignalResult::ProcessKilled(exit_code) => unsafe {
(*processor).make_current_exited(exit_code as _)
},
_ => match syscall_ret {
Ret::Done(ret) => match id {
Id::EXIT => unsafe { (*processor).make_current_exited(ret) },
Expand Down Expand Up @@ -558,8 +558,9 @@ mod impls {

impl Signal for SyscallContext {
fn kill(&self, _caller: Caller, pid: isize, signum: u8) -> isize {
if let Some(target_task) =
PROCESSOR.get_mut().get_proc(ProcId::from_usize(pid as usize))
if let Some(target_task) = PROCESSOR
.get_mut()
.get_proc(ProcId::from_usize(pid as usize))
{
if let Ok(signal_no) = SignalNo::try_from(signum) {
if signal_no != SignalNo::ERR {
Expand Down Expand Up @@ -855,7 +856,9 @@ mod impls {

// TODO: 实现 enable_deadlock_detect 系统调用
fn enable_deadlock_detect(&self, _caller: Caller, is_enable: i32) -> isize {
rcore_console::log::info!("enable_deadlock_detect: is_enable = {is_enable}, not implemented");
rcore_console::log::info!(
"enable_deadlock_detect: is_enable = {is_enable}, not implemented"
);
-1
}
}
Expand Down
2 changes: 1 addition & 1 deletion sbi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ pub fn shutdown(failure: bool) -> ! {
sbi_call(SBI_EXT_SRST, 0, 0, 0, 0);
}
panic!("It should shutdown!");
}
}
Loading
Loading