diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 000332a..8caee93 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,8 @@ jobs: run: | cd code cargo fmt --all -- --check + cd ch02-03 + cargo fmt --all -- --check # uses: actions-rs/cargo@v1 # with: # command: fmt @@ -29,6 +31,8 @@ jobs: run: | cd code cargo clippy + cd ch02-03 + cargo clippy # uses: actions-rs/cargo@v1 # with: # command: clippy @@ -36,7 +40,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, macos-latest] + os: [ubuntu-20.04] +# os: [ubuntu-20.04, macos-latest] steps: - uses: actions/checkout@v2 with: @@ -50,15 +55,17 @@ jobs: run: | cd code cargo build + cd ch02-03 + cargo build # uses: actions-rs/cargo@v1 # with: # command: build - test: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, macos-latest] + os: [ubuntu-20.04] +# os: [ubuntu-20.04, macos-latest] steps: - uses: actions/checkout@v2 with: @@ -72,3 +79,27 @@ jobs: run: | cd code cargo test + cd ch02-03 + cargo test + + doc: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04] +# os: [ubuntu-20.04, macos-latest] + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly-2021-07-27 + components: rust-src + - name: Build docs + run: | + cd code + cargo doc --no-deps --all-features + cd ch02-03 + cargo doc --no-deps --all-features diff --git a/README.md b/README.md index 8fdc113..4a15be7 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,16 @@ # zCore Tutorial +[![CI](https://github.com/rcore-os/zCore-Tutorial/workflows/CI/badge.svg?branch=master)](https://github.com/rcore-os/zCore-Tutorial/actions) +[![Docs](https://img.shields.io/badge/docs-alpha-blue)](https://rcore-os.github.io/zCore-Tutorial/) + +zCore Toturial 的目标是通过`step by step`地建立一个简化的zCore kernel的过程来学习和掌握zCore Kernel的核心概念和对应实现,从而为进一步分析掌握zCore的完整内核打下基础。 + +zCore Toturial 的特点是所有的code都在用户态运行,便于调试和分析。 + ## 仓库目录 * `docs/`: 教学实验指导 -* `zcore`: 操作系统代码 +* `code`: 操作系统代码 ## 实验指导 @@ -23,3 +30,20 @@ mdbook serve docs ``` rustc 1.56.0-nightly (08095fc1f 2021-07-26) ``` + +## 参考 +- https://fuchsia.dev/ + - https://fuchsia.dev/fuchsia-src/concepts/kernel + - https://fuchsia.dev/fuchsia-src/reference/kernel_objects/objects + - https://fuchsia.dev/fuchsia-src/reference/syscalls + - https://github.com/zhangpf/fuchsia-docs-zh-CN/tree/master/zircon + - [许中兴博士演讲:Fuchsia OS 简介](https://xuzhongxing.github.io/201806fuchsia.pdf) + +- 毕设论文 + - [Rust语言操作系统的设计与实现,王润基本科毕设论文,2019](https://github.com/rcore-os/zCore/wiki/files/wrj-thesis.pdf) + - [zCore操作系统内核的设计与实现,潘庆霖本科毕设论文,2020](https://github.com/rcore-os/zCore/wiki/files/pql-thesis.pdf) + +- 开发文档 + - https://github.com/rcore-os/zCore/wiki/documents-of-zcore + +- 更简单和基础的[rCore-Tutorial v3](https://rcore-os.github.io/rCore-Tutorial-Book-v3/):如果看不懂上面的内容,可以先看看这个教程。 diff --git a/code/Cargo.toml b/code/Cargo.toml index 20ef163..3818402 100644 --- a/code/Cargo.toml +++ b/code/Cargo.toml @@ -4,4 +4,6 @@ members = [ "ch01-02", "ch01-03", "ch02-02", +# "ch02-03", +# "ch03-02", ] diff --git a/code/ch01-01/src/object/mod.rs b/code/ch01-01/src/object/mod.rs index 1c114c2..e6361f4 100644 --- a/code/ch01-01/src/object/mod.rs +++ b/code/ch01-01/src/object/mod.rs @@ -127,6 +127,7 @@ impl_kobject!(DummyObject); impl DummyObject { /// 创建一个新 `DummyObject` + #[allow(dead_code)] pub fn new() -> Arc { Arc::new(DummyObject { base: KObjectBase::default(), diff --git a/code/ch01-02/src/object/handle.rs b/code/ch01-02/src/object/handle.rs index 592282d..455a462 100644 --- a/code/ch01-02/src/object/handle.rs +++ b/code/ch01-02/src/object/handle.rs @@ -1,5 +1,5 @@ // ANCHOR: handle -use super::{DummyObject, KernelObject, Rights}; +use super::{KernelObject, Rights}; use alloc::sync::Arc; /// 内核对象句柄 @@ -20,7 +20,7 @@ impl Handle { #[cfg(test)] mod tests { use super::*; - + use crate::object::DummyObject; #[test] fn new_obj_handle() { let obj = DummyObject::new(); diff --git a/code/ch01-03/src/ipc/channel.rs b/code/ch01-03/src/ipc/channel.rs index 1b6d0e5..f93146d 100644 --- a/code/ch01-03/src/ipc/channel.rs +++ b/code/ch01-03/src/ipc/channel.rs @@ -60,7 +60,7 @@ impl Channel { /// Read a packet from the channel if check is ok, otherwise the msg will keep. pub fn read(&self) -> ZxResult { let mut recv_queue = self.recv_queue.lock(); - if let Some(msg) = recv_queue.front() { + if let Some(_msg) = recv_queue.front() { let msg = recv_queue.pop_front().unwrap(); return Ok(msg); } diff --git a/code/ch01-03/src/object/handle.rs b/code/ch01-03/src/object/handle.rs index 592282d..455a462 100644 --- a/code/ch01-03/src/object/handle.rs +++ b/code/ch01-03/src/object/handle.rs @@ -1,5 +1,5 @@ // ANCHOR: handle -use super::{DummyObject, KernelObject, Rights}; +use super::{KernelObject, Rights}; use alloc::sync::Arc; /// 内核对象句柄 @@ -20,7 +20,7 @@ impl Handle { #[cfg(test)] mod tests { use super::*; - + use crate::object::DummyObject; #[test] fn new_obj_handle() { let obj = DummyObject::new(); diff --git a/code/ch02-02/src/ipc/channel.rs b/code/ch02-02/src/ipc/channel.rs index f8f7d59..5639a8d 100644 --- a/code/ch02-02/src/ipc/channel.rs +++ b/code/ch02-02/src/ipc/channel.rs @@ -55,7 +55,7 @@ impl Channel { /// Read a packet from the channel if check is ok, otherwise the msg will keep. pub fn read(&self) -> ZxResult { let mut recv_queue = self.recv_queue.lock(); - if let Some(_) = recv_queue.front() { + if recv_queue.front().is_some() { let msg = recv_queue.pop_front().unwrap(); return Ok(msg); } diff --git a/code/ch02-02/src/task/process.rs b/code/ch02-02/src/task/process.rs index cf63855..7dbc9a6 100644 --- a/code/ch02-02/src/task/process.rs +++ b/code/ch02-02/src/task/process.rs @@ -145,7 +145,7 @@ impl Process { Ok(object) } - pub fn start(&self) -> () { + pub fn start(&self) { // unimplemented!() } @@ -164,7 +164,7 @@ impl Process { /// The process finally terminates. fn terminate(&self) { let mut inner = self.inner.lock(); - let retcode = match inner.status { + let _retcode = match inner.status { Status::Exited(retcode) => retcode, _ => { inner.status = Status::Exited(0); diff --git a/code/ch02-03/object/src/task/thread.rs b/code/ch02-03/object/src/task/thread.rs index 6917f10..e57fb6d 100644 --- a/code/ch02-03/object/src/task/thread.rs +++ b/code/ch02-03/object/src/task/thread.rs @@ -10,8 +10,8 @@ use { pin::Pin, task::{Context, Poll, Waker}, }, - trapframe::{UserContext}, spin::Mutex, + trapframe::UserContext, }; pub use self::thread_state::*; @@ -258,7 +258,6 @@ impl Task for Thread { } } - /// A handle to current thread. /// /// This is a wrapper of [`Thread`] that provides additional methods for the thread runner. @@ -397,9 +396,9 @@ pub struct ThreadInfo { mod tests { use super::job::Job; use super::*; + use core::time::Duration; use kernel_hal::timer_now; use kernel_hal::GeneralRegs; - use core::time::Duration; #[test] fn create() { @@ -469,7 +468,6 @@ mod tests { assert_eq!(thread.state(), ThreadState::Dead); } - #[test] fn info() { let root_job = Job::root(); diff --git a/code/ch03-02/object/src/lib.rs b/code/ch03-02/object/src/lib.rs index 0153a78..c434f09 100644 --- a/code/ch03-02/object/src/lib.rs +++ b/code/ch03-02/object/src/lib.rs @@ -17,7 +17,7 @@ mod error; mod ipc; mod object; mod task; -mod vm; mod util; +mod vm; pub use self::error::*; diff --git a/code/ch03-02/object/src/task/thread.rs b/code/ch03-02/object/src/task/thread.rs index 6917f10..e57fb6d 100644 --- a/code/ch03-02/object/src/task/thread.rs +++ b/code/ch03-02/object/src/task/thread.rs @@ -10,8 +10,8 @@ use { pin::Pin, task::{Context, Poll, Waker}, }, - trapframe::{UserContext}, spin::Mutex, + trapframe::UserContext, }; pub use self::thread_state::*; @@ -258,7 +258,6 @@ impl Task for Thread { } } - /// A handle to current thread. /// /// This is a wrapper of [`Thread`] that provides additional methods for the thread runner. @@ -397,9 +396,9 @@ pub struct ThreadInfo { mod tests { use super::job::Job; use super::*; + use core::time::Duration; use kernel_hal::timer_now; use kernel_hal::GeneralRegs; - use core::time::Duration; #[test] fn create() { @@ -469,7 +468,6 @@ mod tests { assert_eq!(thread.state(), ThreadState::Dead); } - #[test] fn info() { let root_job = Job::root();