From f86583dbce100aca1146dddf106f55969a4d180f Mon Sep 17 00:00:00 2001 From: Jianfeng Jiang Date: Mon, 1 Jul 2024 08:00:09 +0000 Subject: [PATCH] Make essential changes for publishing OSTD --- .github/workflows/publish_osdk.yml | 36 ------ .github/workflows/publish_osdk_and_ostd.yml | 69 +++++++++++ Cargo.lock | 117 ++++++++++-------- Cargo.toml | 2 +- Makefile | 2 +- kernel/aster-nix/Cargo.toml | 3 +- kernel/aster-nix/src/arch/x86/cpu.rs | 66 +++++++++- kernel/aster-nix/src/fs/exfat/super_block.rs | 2 +- kernel/aster-nix/src/prelude.rs | 2 +- .../aster-nix/src/process/signal/c_types.rs | 4 +- kernel/aster-nix/src/process/signal/mod.rs | 6 +- kernel/aster-nix/src/syscall/rt_sigreturn.rs | 6 +- kernel/aster-nix/src/vdso.rs | 2 +- kernel/comps/block/Cargo.toml | 1 - kernel/comps/block/src/id.rs | 2 +- kernel/comps/network/Cargo.toml | 1 - kernel/comps/network/src/buffer.rs | 2 +- kernel/comps/network/src/lib.rs | 3 +- kernel/comps/virtio/Cargo.toml | 1 - .../comps/virtio/src/device/block/device.rs | 2 +- kernel/comps/virtio/src/device/block/mod.rs | 3 +- .../comps/virtio/src/device/console/config.rs | 3 +- kernel/comps/virtio/src/device/input/mod.rs | 3 +- .../comps/virtio/src/device/network/config.rs | 3 +- .../comps/virtio/src/device/network/header.rs | 2 +- .../comps/virtio/src/device/socket/config.rs | 3 +- .../comps/virtio/src/device/socket/device.rs | 3 +- .../comps/virtio/src/device/socket/header.rs | 2 +- kernel/comps/virtio/src/queue.rs | 3 +- .../comps/virtio/src/transport/mmio/layout.rs | 2 +- .../virtio/src/transport/pci/common_cfg.rs | 3 +- kernel/libs/aster-util/Cargo.toml | 1 - kernel/libs/aster-util/src/safe_ptr.rs | 2 +- kernel/libs/aster-util/src/union_read_ptr.rs | 2 +- kernel/libs/int-to-c-enum/Cargo.toml | 6 +- kernel/libs/int-to-c-enum/derive/Cargo.toml | 3 + osdk/src/commands/build/bin.rs | 7 +- osdk/src/commands/new/mod.rs | 4 +- osdk/src/util.rs | 18 +-- osdk/tests/util/mod.rs | 2 +- ostd/Cargo.toml | 39 +++--- ostd/README.md | 10 +- ostd/libs/id-alloc/Cargo.toml | 3 + .../libs/linux-bzimage/boot-params/Cargo.toml | 3 + ostd/libs/linux-bzimage/setup/Cargo.toml | 5 +- ostd/libs/ostd-macros/Cargo.toml | 5 +- ostd/libs/ostd-macros/src/lib.rs | 12 +- ostd/libs/{ktest => ostd-test}/Cargo.toml | 5 +- ostd/libs/{ktest => ostd-test}/src/lib.rs | 14 +-- ostd/libs/{ktest => ostd-test}/src/path.rs | 0 ostd/libs/{ktest => ostd-test}/src/runner.rs | 0 ostd/libs/{ktest => ostd-test}/src/tree.rs | 0 ostd/src/arch/x86/cpu.rs | 9 +- ostd/src/arch/x86/iommu/context_table.rs | 2 +- ostd/src/arch/x86/iommu/second_stage.rs | 13 +- ostd/src/arch/x86/mm/mod.rs | 12 +- ostd/src/boot/mod.rs | 2 +- ostd/src/cpu/mod.rs | 1 - ostd/src/io_mem.rs | 4 +- ostd/src/lib.rs | 3 +- ostd/src/mm/io.rs | 3 +- ostd/src/mm/page_table/mod.rs | 7 +- ostd/src/panicking.rs | 2 +- ostd/src/sync/atomic_bits.rs | 1 - 64 files changed, 341 insertions(+), 218 deletions(-) delete mode 100644 .github/workflows/publish_osdk.yml create mode 100644 .github/workflows/publish_osdk_and_ostd.yml rename ostd/libs/{ktest => ostd-test}/Cargo.toml (54%) rename ostd/libs/{ktest => ostd-test}/src/lib.rs (92%) rename ostd/libs/{ktest => ostd-test}/src/path.rs (100%) rename ostd/libs/{ktest => ostd-test}/src/runner.rs (100%) rename ostd/libs/{ktest => ostd-test}/src/tree.rs (100%) diff --git a/.github/workflows/publish_osdk.yml b/.github/workflows/publish_osdk.yml deleted file mode 100644 index 62a5580b..00000000 --- a/.github/workflows/publish_osdk.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Publish OSDK - -on: - pull_request: - paths: - - VERSION - - osdk/Cargo.toml - push: - branches: - - main - paths: - - VERSION - -jobs: - osdk-publish: - runs-on: ubuntu-latest - timeout-minutes: 10 - container: asterinas/asterinas:0.6.2 - steps: - - uses: actions/checkout@v4 - - - name: Check Publish - # On pull request, set `--dry-run` to check whether OSDK can publish - if: github.event_name == 'pull_request' - run: | - cd osdk - cargo publish --dry-run - - - name: Publish - # On push, OSDK will be published - if: github.event_name == 'push' - env: - REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - run: | - cd osdk - cargo publish --token ${REGISTRY_TOKEN} diff --git a/.github/workflows/publish_osdk_and_ostd.yml b/.github/workflows/publish_osdk_and_ostd.yml new file mode 100644 index 00000000..c9e4d2e5 --- /dev/null +++ b/.github/workflows/publish_osdk_and_ostd.yml @@ -0,0 +1,69 @@ +name: Publish OSDK and OSTD + +on: + pull_request: + paths: + - VERSION + - ostd/** + - osdk/** + push: + branches: + - main + paths: + - VERSION + +jobs: + osdk-publish: + runs-on: ubuntu-latest + timeout-minutes: 10 + container: asterinas/asterinas:0.6.2 + steps: + - uses: actions/checkout@v4 + + - name: Check Publish OSDK + # On pull request, set `--dry-run` to check whether OSDK can publish + if: github.event_name == 'pull_request' + run: | + cd osdk + cargo publish --dry-run + + - name: Publish OSDK + # On push, OSDK will be published + if: github.event_name == 'push' + env: + REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: | + cd osdk + cargo publish --token ${REGISTRY_TOKEN} + + ostd-publish: + runs-on: ubuntu-latest + timeout-minutes: 10 + container: asterinas/asterinas:0.6.2 + strategy: + matrix: + # All supported targets, this array should keep consistent with + # `package.metadata.docs.rs.targets` in `ostd/Cargo.toml` + target: ['x86_64-unknown-none'] + steps: + - uses: actions/checkout@v4 + + - name: Check Publish OSTD + # On pull request, set `--dry-run` to check whether OSDK can publish + if: github.event_name == 'pull_request' + run: | + cd ostd + cargo publish --target ${{ matrix.target }} --dry-run + cargo doc --target ${{ matrix.target }} + + - name: Publish OSTD + if: github.event_name == 'push' + env: + REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + # Using any target that OSTD supports for publishing is ok. + # Here we use the same target as + # `package.metadata.docs.rs.default-target` in `ostd/Cargo.toml`. + run: | + cd ostd + cargo publish --target x86_64-unknown-none --token ${REGISTRY_TOKEN} + diff --git a/Cargo.lock b/Cargo.lock index c70d7b0c..79dc2328 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,7 +84,6 @@ dependencies = [ "lazy_static", "log", "ostd", - "pod", "spin 0.9.8", "static_assertions", ] @@ -141,7 +140,6 @@ dependencies = [ "int-to-c-enum", "log", "ostd", - "pod", "ringbuf", "smoltcp", "spin 0.9.8", @@ -185,7 +183,6 @@ dependencies = [ "lru", "ostd", "paste", - "pod", "rand", "ringbuf", "smoltcp", @@ -238,7 +235,6 @@ dependencies = [ "aster-rights-proc", "inherit-methods-macro", "ostd", - "pod", "typeflags-util", ] @@ -261,7 +257,6 @@ dependencies = [ "int-to-c-enum", "log", "ostd", - "pod", "smoltcp", "spin 0.9.8", "typeflags-util", @@ -277,7 +272,7 @@ dependencies = [ "component", "id-alloc", "ostd", - "x86_64", + "x86_64 0.14.11", ] [[package]] @@ -760,9 +755,9 @@ dependencies = [ [[package]] name = "intrusive-collections" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f4f90afb01281fdeffb0f8e082d230cbe4f888f837cc90759696b858db1a700" +checksum = "b694dc9f70c3bda874626d2aed13b780f137aab435f4e9814121955cf706122e" dependencies = [ "memoffset", ] @@ -795,13 +790,6 @@ checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" name = "keyable-arc" version = "0.1.0" -[[package]] -name = "ktest" -version = "0.1.0" -dependencies = [ - "owo-colors", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -891,7 +879,7 @@ dependencies = [ "uart_16550", "uefi", "uefi-services", - "x86_64", + "x86_64 0.14.11", "xmas-elf 0.8.0", ] @@ -950,9 +938,9 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memoffset" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" dependencies = [ "autocfg", ] @@ -1094,7 +1082,6 @@ dependencies = [ "inherit-methods-macro", "int-to-c-enum", "intrusive-collections", - "ktest", "lazy_static", "linux-boot-params", "log", @@ -1103,8 +1090,9 @@ dependencies = [ "num-derive", "num-traits", "ostd-macros", + "ostd-pod", + "ostd-test", "owo-colors", - "pod", "rsdp", "spin 0.9.8", "static_assertions", @@ -1113,13 +1101,13 @@ dependencies = [ "unwinding", "volatile", "x86", - "x86_64", + "x86_64 0.14.11", "xarray", ] [[package]] name = "ostd-macros" -version = "0.1.0" +version = "0.1.4" dependencies = [ "proc-macro2", "quote", @@ -1127,6 +1115,31 @@ dependencies = [ "syn 2.0.49", ] +[[package]] +name = "ostd-pod" +version = "0.1.1" +source = "git+https://github.com/asterinas/ostd-pod?rev=c4644be#c4644be401cae1e046a810574078b64e35924f5f" +dependencies = [ + "ostd-pod-derive", +] + +[[package]] +name = "ostd-pod-derive" +version = "0.1.1" +source = "git+https://github.com/asterinas/ostd-pod?rev=c4644be#c4644be401cae1e046a810574078b64e35924f5f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ostd-test" +version = "0.1.0" +dependencies = [ + "owo-colors", +] + [[package]] name = "owo-colors" version = "3.5.0" @@ -1139,24 +1152,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "pod" -version = "0.1.0" -source = "git+https://github.com/asterinas/pod?rev=d7dba56#d7dba56cc202a10d483b60aba4f734b1f49cb37b" -dependencies = [ - "pod-derive", -] - -[[package]] -name = "pod-derive" -version = "0.1.0" -source = "git+https://github.com/asterinas/pod?rev=d7dba56#d7dba56cc202a10d483b60aba4f734b1f49cb37b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "polonius-the-crab" version = "0.2.1" @@ -1276,6 +1271,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "raw-cpuid" +version = "11.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e29830cbb1290e404f24c73af91c5d8d631ce7e128691e9477556b540cd01ecd" +dependencies = [ + "bitflags 2.4.1", +] + [[package]] name = "ringbuf" version = "0.3.3" @@ -1358,9 +1362,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smoltcp" @@ -1462,8 +1466,8 @@ dependencies = [ "bitflags 1.3.2", "iced-x86", "lazy_static", - "raw-cpuid", - "x86_64", + "raw-cpuid 10.7.0", + "x86_64 0.14.11", ] [[package]] @@ -1539,13 +1543,12 @@ dependencies = [ [[package]] name = "trapframe" -version = "0.9.0" -source = "git+https://github.com/asterinas/trapframe-rs?rev=4739428#4739428fd51685c74e6e88e73e5f04cb89f465ee" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "105000258ba41c463b63403c9341c55a298f35f6137b1cca08c10f0409ef8d3a" dependencies = [ - "log", - "pod", - "raw-cpuid", - "x86_64", + "raw-cpuid 11.0.2", + "x86_64 0.15.1", ] [[package]] @@ -1723,7 +1726,7 @@ checksum = "2781db97787217ad2a2845c396a5efe286f87467a5810836db6d74926e94a385" dependencies = [ "bit_field", "bitflags 1.3.2", - "raw-cpuid", + "raw-cpuid 10.7.0", ] [[package]] @@ -1738,6 +1741,18 @@ dependencies = [ "volatile", ] +[[package]] +name = "x86_64" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bc79523af8abf92fb1a970c3e086c5a343f6bcc1a0eb890f575cbb3b45743df" +dependencies = [ + "bit_field", + "bitflags 2.4.1", + "rustversion", + "volatile", +] + [[package]] name = "xarray" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 9e47daa4..26ab93e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ "ostd/libs/linux-bzimage/builder", "ostd/libs/linux-bzimage/boot-params", "ostd/libs/linux-bzimage/setup", - "ostd/libs/ktest", + "ostd/libs/ostd-test", "kernel", "kernel/aster-nix", "kernel/comps/block", diff --git a/Makefile b/Makefile index 0a02b804..56134ff5 100644 --- a/Makefile +++ b/Makefile @@ -91,8 +91,8 @@ NON_OSDK_CRATES := \ ostd/libs/id-alloc \ ostd/libs/linux-bzimage/builder \ ostd/libs/linux-bzimage/boot-params \ - ostd/libs/ktest \ ostd/libs/ostd-macros \ + ostd/libs/ostd-test \ kernel/libs/cpio-decoder \ kernel/libs/int-to-c-enum \ kernel/libs/int-to-c-enum/derive \ diff --git a/kernel/aster-nix/Cargo.toml b/kernel/aster-nix/Cargo.toml index b2651c6b..f5b52453 100644 --- a/kernel/aster-nix/Cargo.toml +++ b/kernel/aster-nix/Cargo.toml @@ -6,9 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ostd = { path = "../../ostd" } align_ext = { path = "../../ostd/libs/align_ext" } -pod = { git = "https://github.com/asterinas/pod", rev = "d7dba56" } aster-input = { path = "../comps/input" } aster-block = { path = "../comps/block" } aster-network = { path = "../comps/network" } @@ -17,6 +15,7 @@ aster-time = { path = "../comps/time" } aster-virtio = { path = "../comps/virtio" } aster-rights = { path = "../libs/aster-rights" } controlled = { path = "../libs/comp-sys/controlled" } +ostd = { path = "../../ostd" } typeflags = { path = "../libs/typeflags" } typeflags-util = { path = "../libs/typeflags-util" } aster-rights-proc = { path = "../libs/aster-rights-proc" } diff --git a/kernel/aster-nix/src/arch/x86/cpu.rs b/kernel/aster-nix/src/arch/x86/cpu.rs index b6b25721..3bb49ce1 100644 --- a/kernel/aster-nix/src/arch/x86/cpu.rs +++ b/kernel/aster-nix/src/arch/x86/cpu.rs @@ -1,6 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 -use ostd::cpu::UserContext; +use ostd::{ + cpu::{RawGeneralRegs, UserContext}, + Pod, +}; use crate::cpu::LinuxAbi; @@ -36,3 +39,64 @@ impl LinuxAbi for UserContext { self.fsbase() } } + +/// General-purpose registers. +#[derive(Debug, Clone, Copy, Pod, Default)] +#[repr(C)] +pub struct GpRegs { + pub rax: usize, + pub rbx: usize, + pub rcx: usize, + pub rdx: usize, + pub rsi: usize, + pub rdi: usize, + pub rbp: usize, + pub rsp: usize, + pub r8: usize, + pub r9: usize, + pub r10: usize, + pub r11: usize, + pub r12: usize, + pub r13: usize, + pub r14: usize, + pub r15: usize, + pub rip: usize, + pub rflags: usize, + pub fsbase: usize, + pub gsbase: usize, +} + +macro_rules! copy_gp_regs { + ($src: ident, $dst: ident) => { + $dst.rax = $src.rax; + $dst.rbx = $src.rax; + $dst.rcx = $src.rcx; + $dst.rdx = $src.rdx; + $dst.rsi = $src.rsi; + $dst.rdi = $src.rdi; + $dst.rbp = $src.rbp; + $dst.rsp = $src.rsp; + $dst.r8 = $src.r8; + $dst.r9 = $src.r9; + $dst.r10 = $src.r10; + $dst.r11 = $src.r11; + $dst.r12 = $src.r12; + $dst.r13 = $src.r13; + $dst.r14 = $src.r14; + $dst.r15 = $src.r15; + $dst.rip = $src.rip; + $dst.rflags = $src.rflags; + $dst.fsbase = $src.fsbase; + $dst.gsbase = $src.gsbase; + }; +} + +impl GpRegs { + pub fn copy_to_raw(&self, dst: &mut RawGeneralRegs) { + copy_gp_regs!(self, dst); + } + + pub fn copy_from_raw(&mut self, src: &RawGeneralRegs) { + copy_gp_regs!(src, self); + } +} diff --git a/kernel/aster-nix/src/fs/exfat/super_block.rs b/kernel/aster-nix/src/fs/exfat/super_block.rs index eb422c46..78225709 100644 --- a/kernel/aster-nix/src/fs/exfat/super_block.rs +++ b/kernel/aster-nix/src/fs/exfat/super_block.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use pod::Pod; +use ostd::Pod; use super::constants::{EXFAT_FIRST_CLUSTER, EXFAT_RESERVED_CLUSTERS, MEDIA_FAILURE, VOLUME_DIRTY}; use crate::prelude::*; diff --git a/kernel/aster-nix/src/prelude.rs b/kernel/aster-nix/src/prelude.rs index 701b8ed9..dfff7626 100644 --- a/kernel/aster-nix/src/prelude.rs +++ b/kernel/aster-nix/src/prelude.rs @@ -19,8 +19,8 @@ pub(crate) use log::{debug, error, info, log_enabled, trace, warn}; pub(crate) use ostd::{ mm::{Vaddr, VmReader, VmWriter, PAGE_SIZE}, sync::{Mutex, MutexGuard, RwLock, RwMutex, SpinLock, SpinLockGuard}, + Pod, }; -pub(crate) use pod::Pod; /// return current process #[macro_export] diff --git a/kernel/aster-nix/src/process/signal/c_types.rs b/kernel/aster-nix/src/process/signal/c_types.rs index b2f39c9c..5981cd16 100644 --- a/kernel/aster-nix/src/process/signal/c_types.rs +++ b/kernel/aster-nix/src/process/signal/c_types.rs @@ -6,10 +6,10 @@ use core::mem::{self, size_of}; use aster_util::{read_union_fields, union_read_ptr::UnionReadPtr}; -use ostd::cpu::GeneralRegs; use super::sig_num::SigNum; use crate::{ + arch::cpu::GpRegs, prelude::*, process::{Pid, Uid}, }; @@ -206,7 +206,7 @@ pub struct mcontext_t { #[derive(Debug, Clone, Copy, Pod, Default)] #[repr(C)] pub struct SignalCpuContext { - pub gp_regs: GeneralRegs, + pub gp_regs: GpRegs, pub fpregs_on_heap: u64, pub fpregs: Vaddr, // *mut FpRegs, } diff --git a/kernel/aster-nix/src/process/signal/mod.rs b/kernel/aster-nix/src/process/signal/mod.rs index aba58e03..38a727a3 100644 --- a/kernel/aster-nix/src/process/signal/mod.rs +++ b/kernel/aster-nix/src/process/signal/mod.rs @@ -166,7 +166,11 @@ pub fn handle_user_signal( uc_sigmask: mask.as_u64(), ..Default::default() }; - ucontext.uc_mcontext.inner.gp_regs = *context.general_regs(); + ucontext + .uc_mcontext + .inner + .gp_regs + .copy_from_raw(context.general_regs()); let mut sig_context = posix_thread.sig_context().lock(); if let Some(sig_context_addr) = *sig_context { ucontext.uc_link = sig_context_addr; diff --git a/kernel/aster-nix/src/syscall/rt_sigreturn.rs b/kernel/aster-nix/src/syscall/rt_sigreturn.rs index a25258bb..bd45365f 100644 --- a/kernel/aster-nix/src/syscall/rt_sigreturn.rs +++ b/kernel/aster-nix/src/syscall/rt_sigreturn.rs @@ -38,7 +38,11 @@ pub fn sys_rt_sigreturn(context: &mut UserContext) -> Result { } else { *sig_context = Some(ucontext.uc_link); }; - *context.general_regs_mut() = ucontext.uc_mcontext.inner.gp_regs; + ucontext + .uc_mcontext + .inner + .gp_regs + .copy_to_raw(context.general_regs_mut()); // unblock sig mask let sig_mask = ucontext.uc_sigmask; posix_thread.sig_mask().lock().unblock(sig_mask); diff --git a/kernel/aster-nix/src/vdso.rs b/kernel/aster-nix/src/vdso.rs index 1db2adbc..c1f9b701 100644 --- a/kernel/aster-nix/src/vdso.rs +++ b/kernel/aster-nix/src/vdso.rs @@ -23,8 +23,8 @@ use aster_util::coeff::Coeff; use ostd::{ mm::{Frame, VmIo, PAGE_SIZE}, sync::SpinLock, + Pod, }; -use pod::Pod; use spin::Once; use crate::{ diff --git a/kernel/comps/block/Cargo.toml b/kernel/comps/block/Cargo.toml index 95af96b1..e0c8770f 100644 --- a/kernel/comps/block/Cargo.toml +++ b/kernel/comps/block/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] bitflags = "1.3" spin = "0.9.4" -pod = { git = "https://github.com/asterinas/pod", rev = "d7dba56" } ostd = { path = "../../../ostd" } align_ext = { path = "../../../ostd/libs/align_ext" } aster-util = { path = "../../libs/aster-util" } diff --git a/kernel/comps/block/src/id.rs b/kernel/comps/block/src/id.rs index 30081737..6065f239 100644 --- a/kernel/comps/block/src/id.rs +++ b/kernel/comps/block/src/id.rs @@ -5,7 +5,7 @@ use core::{ ops::{Add, Sub}, }; -use pod::Pod; +use ostd::Pod; use static_assertions::const_assert; /// The block index used in the filesystem. diff --git a/kernel/comps/network/Cargo.toml b/kernel/comps/network/Cargo.toml index 1da353f3..f57c9d20 100644 --- a/kernel/comps/network/Cargo.toml +++ b/kernel/comps/network/Cargo.toml @@ -15,7 +15,6 @@ component = { path = "../../libs/comp-sys/component" } int-to-c-enum = { path = "../../libs/int-to-c-enum" } log = "0.4" ostd = { path = "../../../ostd" } -pod = { git = "https://github.com/asterinas/pod", rev = "d7dba56" } ringbuf = { version = "0.3.2", default-features = false, features = ["alloc"] } smoltcp = { version = "0.9.1", default-features = false, features = ["alloc", "log", "medium-ethernet", "medium-ip", "proto-dhcpv4", "proto-ipv4", "proto-igmp", "socket-icmp", "socket-udp", "socket-tcp", "socket-raw", "socket-dhcpv4"] } spin = "0.9.4" diff --git a/kernel/comps/network/src/buffer.rs b/kernel/comps/network/src/buffer.rs index c4fd2204..845fc26b 100644 --- a/kernel/comps/network/src/buffer.rs +++ b/kernel/comps/network/src/buffer.rs @@ -8,8 +8,8 @@ use ostd::{ Daddr, DmaDirection, DmaStream, FrameAllocOptions, HasDaddr, VmReader, VmWriter, PAGE_SIZE, }, sync::SpinLock, + Pod, }; -use pod::Pod; use spin::Once; use crate::dma_pool::{DmaPool, DmaSegment}; diff --git a/kernel/comps/network/src/lib.rs b/kernel/comps/network/src/lib.rs index 5c19dfa8..e5378f12 100644 --- a/kernel/comps/network/src/lib.rs +++ b/kernel/comps/network/src/lib.rs @@ -15,11 +15,10 @@ extern crate alloc; use alloc::{collections::BTreeMap, string::String, sync::Arc, vec::Vec}; use core::{any::Any, fmt::Debug}; -use aster_util::safe_ptr::Pod; pub use buffer::{RxBuffer, TxBuffer, RX_BUFFER_POOL, TX_BUFFER_POOL}; use component::{init_component, ComponentInitError}; pub use dma_pool::DmaSegment; -use ostd::sync::SpinLock; +use ostd::{sync::SpinLock, Pod}; use smoltcp::phy; use spin::Once; diff --git a/kernel/comps/virtio/Cargo.toml b/kernel/comps/virtio/Cargo.toml index 9763a773..3347c8c8 100644 --- a/kernel/comps/virtio/Cargo.toml +++ b/kernel/comps/virtio/Cargo.toml @@ -19,7 +19,6 @@ aster-rights = { path = "../../libs/aster-rights" } id-alloc = { path = "../../../ostd/libs/id-alloc" } typeflags-util = { path = "../../libs/typeflags-util" } ostd = { path = "../../../ostd" } -pod = { git = "https://github.com/asterinas/pod", rev = "d7dba56" } component = { path = "../../libs/comp-sys/component" } log = "0.4" bit_field = "0.10.1" diff --git a/kernel/comps/virtio/src/device/block/device.rs b/kernel/comps/virtio/src/device/block/device.rs index fce5c64e..8c28d231 100644 --- a/kernel/comps/virtio/src/device/block/device.rs +++ b/kernel/comps/virtio/src/device/block/device.rs @@ -15,8 +15,8 @@ use ostd::{ mm::{DmaDirection, DmaStream, DmaStreamSlice, FrameAllocOptions, VmIo}, sync::SpinLock, trap::TrapFrame, + Pod, }; -use pod::Pod; use super::{BlockFeatures, VirtioBlockConfig}; use crate::{ diff --git a/kernel/comps/virtio/src/device/block/mod.rs b/kernel/comps/virtio/src/device/block/mod.rs index 18faf8a1..e0970a80 100644 --- a/kernel/comps/virtio/src/device/block/mod.rs +++ b/kernel/comps/virtio/src/device/block/mod.rs @@ -5,8 +5,7 @@ pub mod device; use aster_util::safe_ptr::SafePtr; use bitflags::bitflags; use int_to_c_enum::TryFromInt; -use ostd::io_mem::IoMem; -use pod::Pod; +use ostd::{io_mem::IoMem, Pod}; use crate::transport::VirtioTransport; diff --git a/kernel/comps/virtio/src/device/console/config.rs b/kernel/comps/virtio/src/device/console/config.rs index 05d24ef1..49079e27 100644 --- a/kernel/comps/virtio/src/device/console/config.rs +++ b/kernel/comps/virtio/src/device/console/config.rs @@ -1,8 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 use aster_util::safe_ptr::SafePtr; -use ostd::io_mem::IoMem; -use pod::Pod; +use ostd::{io_mem::IoMem, Pod}; use crate::transport::VirtioTransport; diff --git a/kernel/comps/virtio/src/device/input/mod.rs b/kernel/comps/virtio/src/device/input/mod.rs index e42a53e9..2823eaee 100644 --- a/kernel/comps/virtio/src/device/input/mod.rs +++ b/kernel/comps/virtio/src/device/input/mod.rs @@ -28,8 +28,7 @@ pub mod device; use aster_util::safe_ptr::SafePtr; -use ostd::io_mem::IoMem; -use pod::Pod; +use ostd::{io_mem::IoMem, Pod}; use crate::transport::VirtioTransport; diff --git a/kernel/comps/virtio/src/device/network/config.rs b/kernel/comps/virtio/src/device/network/config.rs index aa2fe387..278d8926 100644 --- a/kernel/comps/virtio/src/device/network/config.rs +++ b/kernel/comps/virtio/src/device/network/config.rs @@ -3,8 +3,7 @@ use aster_network::EthernetAddr; use aster_util::safe_ptr::SafePtr; use bitflags::bitflags; -use ostd::io_mem::IoMem; -use pod::Pod; +use ostd::{io_mem::IoMem, Pod}; use crate::transport::VirtioTransport; diff --git a/kernel/comps/virtio/src/device/network/header.rs b/kernel/comps/virtio/src/device/network/header.rs index 2294fbb0..ca888a8c 100644 --- a/kernel/comps/virtio/src/device/network/header.rs +++ b/kernel/comps/virtio/src/device/network/header.rs @@ -2,7 +2,7 @@ use bitflags::bitflags; use int_to_c_enum::TryFromInt; -use pod::Pod; +use ostd::Pod; pub const VIRTIO_NET_HDR_LEN: usize = core::mem::size_of::(); diff --git a/kernel/comps/virtio/src/device/socket/config.rs b/kernel/comps/virtio/src/device/socket/config.rs index 8c1331f7..f2ce56f1 100644 --- a/kernel/comps/virtio/src/device/socket/config.rs +++ b/kernel/comps/virtio/src/device/socket/config.rs @@ -2,8 +2,7 @@ use aster_util::safe_ptr::SafePtr; use bitflags::bitflags; -use ostd::io_mem::IoMem; -use pod::Pod; +use ostd::{io_mem::IoMem, Pod}; use crate::transport::VirtioTransport; diff --git a/kernel/comps/virtio/src/device/socket/device.rs b/kernel/comps/virtio/src/device/socket/device.rs index 3536c20c..44fbc9a7 100644 --- a/kernel/comps/virtio/src/device/socket/device.rs +++ b/kernel/comps/virtio/src/device/socket/device.rs @@ -6,8 +6,7 @@ use core::{fmt::Debug, hint::spin_loop, mem::size_of}; use aster_network::{RxBuffer, TxBuffer}; use aster_util::{field_ptr, slot_vec::SlotVec}; use log::debug; -use ostd::{mm::VmWriter, offset_of, sync::SpinLock, trap::TrapFrame}; -use pod::Pod; +use ostd::{mm::VmWriter, offset_of, sync::SpinLock, trap::TrapFrame, Pod}; use super::{ config::{VirtioVsockConfig, VsockFeatures}, diff --git a/kernel/comps/virtio/src/device/socket/header.rs b/kernel/comps/virtio/src/device/socket/header.rs index d66f37a6..339e60c6 100644 --- a/kernel/comps/virtio/src/device/socket/header.rs +++ b/kernel/comps/virtio/src/device/socket/header.rs @@ -27,7 +27,7 @@ // use bitflags::bitflags; use int_to_c_enum::TryFromInt; -use pod::Pod; +use ostd::Pod; use super::error::{self, SocketError}; diff --git a/kernel/comps/virtio/src/queue.rs b/kernel/comps/virtio/src/queue.rs index c8a16766..4a45f4a2 100644 --- a/kernel/comps/virtio/src/queue.rs +++ b/kernel/comps/virtio/src/queue.rs @@ -15,9 +15,8 @@ use log::debug; use ostd::{ io_mem::IoMem, mm::{DmaCoherent, FrameAllocOptions}, - offset_of, + offset_of, Pod, }; -use pod::Pod; use crate::{dma_buf::DmaBuf, transport::VirtioTransport}; diff --git a/kernel/comps/virtio/src/transport/mmio/layout.rs b/kernel/comps/virtio/src/transport/mmio/layout.rs index 71bf7a23..a6b601ee 100644 --- a/kernel/comps/virtio/src/transport/mmio/layout.rs +++ b/kernel/comps/virtio/src/transport/mmio/layout.rs @@ -2,7 +2,7 @@ use core::fmt::Debug; -use pod::Pod; +use ostd::Pod; #[derive(Clone, Copy, Pod)] #[repr(C)] diff --git a/kernel/comps/virtio/src/transport/pci/common_cfg.rs b/kernel/comps/virtio/src/transport/pci/common_cfg.rs index a6e8b2e2..a3b022ba 100644 --- a/kernel/comps/virtio/src/transport/pci/common_cfg.rs +++ b/kernel/comps/virtio/src/transport/pci/common_cfg.rs @@ -1,8 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 use aster_util::safe_ptr::SafePtr; -use ostd::io_mem::IoMem; -use pod::Pod; +use ostd::{io_mem::IoMem, Pod}; use super::capability::VirtioPciCapabilityData; use crate::transport::pci::capability::VirtioPciCpabilityType; diff --git a/kernel/libs/aster-util/Cargo.toml b/kernel/libs/aster-util/Cargo.toml index 321d5a74..7b6454e0 100644 --- a/kernel/libs/aster-util/Cargo.toml +++ b/kernel/libs/aster-util/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [dependencies] ostd = { path = "../../../ostd" } -pod = { git = "https://github.com/asterinas/pod", rev = "d7dba56" } typeflags-util = { path = "../typeflags-util" } aster-rights-proc = { path = "../aster-rights-proc" } aster-rights = { path = "../aster-rights" } diff --git a/kernel/libs/aster-util/src/safe_ptr.rs b/kernel/libs/aster-util/src/safe_ptr.rs index dd9bde81..0444a9f5 100644 --- a/kernel/libs/aster-util/src/safe_ptr.rs +++ b/kernel/libs/aster-util/src/safe_ptr.rs @@ -5,11 +5,11 @@ use core::{fmt::Debug, marker::PhantomData}; use aster_rights::{Dup, Exec, Full, Read, Signal, TRightSet, TRights, Write}; use aster_rights_proc::require; use inherit_methods_macro::inherit_methods; +pub use ostd::Pod; use ostd::{ mm::{Daddr, DmaStream, HasDaddr, HasPaddr, Paddr, VmIo}, Result, }; -pub use pod::Pod; pub use typeflags_util::SetContain; /// Safe pointers. diff --git a/kernel/libs/aster-util/src/union_read_ptr.rs b/kernel/libs/aster-util/src/union_read_ptr.rs index 3e811630..30d3b2e5 100644 --- a/kernel/libs/aster-util/src/union_read_ptr.rs +++ b/kernel/libs/aster-util/src/union_read_ptr.rs @@ -2,7 +2,7 @@ use core::marker::PhantomData; -use pod::Pod; +use ostd::Pod; /// This ptr is designed to read union field safely. /// Write to union field is safe operation. While reading union field is UB. diff --git a/kernel/libs/int-to-c-enum/Cargo.toml b/kernel/libs/int-to-c-enum/Cargo.toml index 09656d0c..98443d32 100644 --- a/kernel/libs/int-to-c-enum/Cargo.toml +++ b/kernel/libs/int-to-c-enum/Cargo.toml @@ -2,11 +2,15 @@ name = "int-to-c-enum" version = "0.1.0" edition = "2021" +license = "MPL-2.0" +readme = "README.md" +description = "TryFromInt - A convenient derive macro for converting an integer to an enum" +repository = "https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -int-to-c-enum-derive = { path = "derive", optional = true } +int-to-c-enum-derive = { path = "derive", optional = true, version = "0.1.0"} [features] default = ["derive"] diff --git a/kernel/libs/int-to-c-enum/derive/Cargo.toml b/kernel/libs/int-to-c-enum/derive/Cargo.toml index c235a57a..badab5b6 100644 --- a/kernel/libs/int-to-c-enum/derive/Cargo.toml +++ b/kernel/libs/int-to-c-enum/derive/Cargo.toml @@ -2,6 +2,9 @@ name = "int-to-c-enum-derive" version = "0.1.0" edition = "2021" +license = "MPL-2.0" +description = "int-to-c-enum's proc macros" +repository = "https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/osdk/src/commands/build/bin.rs b/osdk/src/commands/build/bin.rs index 977ade06..f0dda635 100644 --- a/osdk/src/commands/build/bin.rs +++ b/osdk/src/commands/build/bin.rs @@ -157,10 +157,9 @@ fn install_setup_with_arch( cmd.arg("install").arg("linux-bzimage-setup"); cmd.arg("--force"); cmd.arg("--root").arg(install_dir.as_ref()); - cmd.arg("--git").arg(crate::util::ASTER_GIT_LINK); - // FIXME: Uses a fixed tag instaed of relies on remote branch - cmd.arg("--tag").arg("v0.5.1"); - // cmd.arg("--tag").arg(crate::util::ASTER_GIT_TAG); + // Remember to upgrade this version if new version of linux-bzimage-setup is released. + const LINUX_BZIMAGE_SETUP_VERSION: &str = "0.1.0"; + cmd.arg("--version").arg(LINUX_BZIMAGE_SETUP_VERSION); cmd.arg("--target").arg(match arch { SetupInstallArch::X86_64 => "x86_64-unknown-none", SetupInstallArch::Other(path) => path.to_str().unwrap(), diff --git a/osdk/src/commands/new/mod.rs b/osdk/src/commands/new/mod.rs index bc321cd7..1c5c3860 100644 --- a/osdk/src/commands/new/mod.rs +++ b/osdk/src/commands/new/mod.rs @@ -7,7 +7,7 @@ use crate::{ config::manifest::ProjectType, error::Errno, error_msg, - util::{aster_crate_dep, cargo_new_lib, get_cargo_metadata}, + util::{cargo_new_lib, get_cargo_metadata, ostd_dep}, }; pub fn execute_new_command(args: &NewArgs) { @@ -40,7 +40,7 @@ fn add_manifest_dependencies(cargo_metadata: &serde_json::Value, crate_name: &st let dependencies = manifest.get_mut("dependencies").unwrap(); - let ostd_dep = toml::Table::from_str(&aster_crate_dep("ostd")).unwrap(); + let ostd_dep = toml::Table::from_str(&ostd_dep()).unwrap(); dependencies.as_table_mut().unwrap().extend(ostd_dep); let content = toml::to_string(&manifest).unwrap(); diff --git a/osdk/src/util.rs b/osdk/src/util.rs index 1f1e4b85..2d629aa6 100644 --- a/osdk/src/util.rs +++ b/osdk/src/util.rs @@ -12,18 +12,12 @@ use crate::{error::Errno, error_msg}; use quote::ToTokens; -/// FIXME: We should publish the asterinas crates to a public registry -/// and use the published version in the generated Cargo.toml. -pub const ASTER_GIT_LINK: &str = "https://github.com/asterinas/asterinas"; -/// Make sure it syncs with the builder dependency in Cargo.toml. -/// We cannot use `include_str!("../../VERSION")` here -/// because `cargo publish` does not allow using files outside of the crate directory. -pub const ASTER_GIT_TAG: &str = concat!("v", env!("CARGO_PKG_VERSION")); -pub fn aster_crate_dep(crate_name: &str) -> String { - format!( - "{} = {{ git = \"{}\", tag = \"{}\" }}", - crate_name, ASTER_GIT_LINK, ASTER_GIT_TAG - ) +/// The version of OSTD on crates.io. +/// +/// OSTD shares the same version with OSDK, so just use the version of OSDK here. +pub const OSTD_VERSION: &str = env!("CARGO_PKG_VERSION"); +pub fn ostd_dep() -> String { + format!("ostd = {{ version = \"{}\" }}", OSTD_VERSION) } fn cargo() -> Command { diff --git a/osdk/tests/util/mod.rs b/osdk/tests/util/mod.rs index 98ac7b61..4f947ba4 100644 --- a/osdk/tests/util/mod.rs +++ b/osdk/tests/util/mod.rs @@ -88,7 +88,7 @@ pub fn add_member_to_workspace(workspace: impl AsRef, new_member: &str) { } /// Makes crates created by `cargo ostd new` depends on ostd locally, -/// instead of ostd from local branch. +/// instead of ostd from remote source(git repo/crates.io). /// /// Each crate created by `cargo ostd new` should add this patch. pub fn depends_on_local_ostd(manifest_path: impl AsRef) { diff --git a/ostd/Cargo.toml b/ostd/Cargo.toml index bacfdf3d..b788274f 100644 --- a/ostd/Cargo.toml +++ b/ostd/Cargo.toml @@ -2,41 +2,48 @@ name = "ostd" version = "0.6.2" edition = "2021" +description = "Rust OS framework that facilitates the development of and innovation in OS kernels" +license = "MPL-2.0" +readme = "README.md" +repository = "https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +# Settings for publishing docs in docs.rs +[package.metadata.docs.rs] +default-target = "x86_64-unknown-none" +targets = ["x86_64-unknown-none"] + [dependencies] -align_ext = { path = "libs/align_ext" } -ostd-macros = { path = "libs/ostd-macros" } +align_ext = { path = "libs/align_ext", version = "0.1.0" } +array-init = "2.0" bit_field = "0.10.1" +buddy_system_allocator = "0.9.0" bitflags = "1.3" bitvec = { version = "1.0", default-features = false, features = ["alloc"] } -linux-boot-params = { path = "libs/linux-bzimage/boot-params" } -buddy_system_allocator = "0.9.0" cfg-if = "1.0" gimli = { version = "0.28", default-features = false, features = ["read-core"] } -inherit-methods-macro = { git = "https://github.com/asterinas/inherit-methods-macro", rev = "98f7e3e" } -xarray = { git = "https://github.com/asterinas/xarray", rev = "72a4067" } -int-to-c-enum = { path = "../kernel/libs/int-to-c-enum" } -# instrusive-collections of version 0.9.6 fails to compile with current rust toolchain, -# So we set a fixed version 0.9.5 for this crate -intrusive-collections = { version = "=0.9.5", features = ["nightly"] } -array-init = "2.0" -ktest = { path = "libs/ktest" } -id-alloc = { path = "libs/id-alloc" } +id-alloc = { path = "libs/id-alloc", version = "0.1.0" } +inherit-methods-macro = { git = "https://github.com/asterinas/inherit-methods-macro", rev = "98f7e3e", version = "0.1.0" } +int-to-c-enum = { path = "../kernel/libs/int-to-c-enum", version = "0.1.0" } +intrusive-collections = { version = "0.9.6", features = ["nightly"] } lazy_static = { version = "1.0", features = ["spin_no_std"] } +linux-boot-params = { path = "libs/linux-bzimage/boot-params", version = "0.1.0" } log = "0.4" num = { version = "0.4", default-features = false } num-derive = { version = "0.4", default-features = false } num-traits = { version = "0.2", default-features = false } -pod = { git = "https://github.com/asterinas/pod", rev = "d7dba56" } +ostd-macros = { path = "libs/ostd-macros", version = "0.1.4" } +ostd-test = { path = "libs/ostd-test", version = "0.1.0" } +owo-colors = { version = "3", optional = true } +ostd-pod = { git = "https://github.com/asterinas/ostd-pod", rev = "c4644be", version = "0.1.1" } spin = "0.9.4" static_assertions = "1.1.0" tdx-guest = { version = "0.1.5", optional = true } -trapframe = { git = "https://github.com/asterinas/trapframe-rs", rev = "4739428" } +trapframe = "0.10.0" unwinding = { version = "0.2.2", default-features = false, features = ["fde-gnu-eh-frame-hdr", "hide-trace", "panic", "personality", "unwinder"] } volatile = { version = "0.4.5", features = ["unstable"] } -owo-colors = { version = "3", optional = true } +xarray = { git = "https://github.com/asterinas/xarray", rev = "72a4067", version = "0.1.0" } [target.x86_64-unknown-none.dependencies] x86_64 = "0.14.2" diff --git a/ostd/README.md b/ostd/README.md index fb2d163e..bbb8c99c 100644 --- a/ostd/README.md +++ b/ostd/README.md @@ -18,12 +18,4 @@ Asterinas OSTD offers the following key values. ## OSTD APIs -TODO - -## Implementation status - -TODO - -## Roadmap and plan - -TODO \ No newline at end of file +See [API docs](https://docs.rs/ostd/latest/ostd). diff --git a/ostd/libs/id-alloc/Cargo.toml b/ostd/libs/id-alloc/Cargo.toml index 1ccca346..6a5bffc1 100644 --- a/ostd/libs/id-alloc/Cargo.toml +++ b/ostd/libs/id-alloc/Cargo.toml @@ -2,6 +2,9 @@ name = "id-alloc" version = "0.1.0" edition = "2021" +license = "MPL-2.0" +description = "An id allocator implemented by the bitmap" +repository = "https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/ostd/libs/linux-bzimage/boot-params/Cargo.toml b/ostd/libs/linux-bzimage/boot-params/Cargo.toml index 3b4b3459..a6942aca 100644 --- a/ostd/libs/linux-bzimage/boot-params/Cargo.toml +++ b/ostd/libs/linux-bzimage/boot-params/Cargo.toml @@ -2,6 +2,9 @@ name = "linux-boot-params" version = "0.1.0" edition = "2021" +description = "The Boot Parameters for Linux Boot Protocol" +license = "MPL-2.0" +repository = "https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/ostd/libs/linux-bzimage/setup/Cargo.toml b/ostd/libs/linux-bzimage/setup/Cargo.toml index 23b0f633..621829af 100644 --- a/ostd/libs/linux-bzimage/setup/Cargo.toml +++ b/ostd/libs/linux-bzimage/setup/Cargo.toml @@ -2,6 +2,9 @@ name = "linux-bzimage-setup" version = "0.1.0" edition = "2021" +description = "The linux bzImage setup binary" +license = "MPL-2.0" +repository = "https://github.com/asterinas/asterinas" [[bin]] name = "linux-bzimage-setup" @@ -11,7 +14,7 @@ path = "src/main.rs" [dependencies] cfg-if = "1.0.0" -linux-boot-params = { path = "../boot-params" } +linux-boot-params = { path = "../boot-params", version = "0.1.0" } uart_16550 = "0.3.0" xmas-elf = "0.8.0" diff --git a/ostd/libs/ostd-macros/Cargo.toml b/ostd/libs/ostd-macros/Cargo.toml index cc6d9946..816b8e05 100644 --- a/ostd/libs/ostd-macros/Cargo.toml +++ b/ostd/libs/ostd-macros/Cargo.toml @@ -1,7 +1,10 @@ [package] name = "ostd-macros" -version = "0.1.0" +version = "0.1.4" edition = "2021" +description = "OSTD's proc macros" +license = "MPL-2.0" +repository ="https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/ostd/libs/ostd-macros/src/lib.rs b/ostd/libs/ostd-macros/src/lib.rs index 3020e438..93466626 100644 --- a/ostd/libs/ostd-macros/src/lib.rs +++ b/ostd/libs/ostd-macros/src/lib.rs @@ -11,7 +11,9 @@ use syn::{parse_macro_input, Expr, Ident, ItemFn}; /// /// # Example /// -/// ```norun +/// ```ignore +/// #![no_std] +/// /// use ostd::prelude::*; /// /// #[ostd::main] @@ -44,7 +46,7 @@ pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream { /// For crates other than ostd, /// this macro can be used in the following form. /// -/// ```norun +/// ```ignore /// use ostd::prelude::*; /// /// #[ktest] @@ -56,7 +58,7 @@ pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream { /// For ostd crate itself, /// this macro can be used in the form /// -/// ```norun +/// ```ignore /// use crate::prelude::*; /// /// #[ktest] @@ -144,10 +146,10 @@ pub fn ktest(_attr: TokenStream, item: TokenStream) -> TokenStream { #[cfg(ktest)] #[used] #[link_section = ".ktest_array"] - static #fn_ktest_item_name: ktest::KtestItem = ktest::KtestItem::new( + static #fn_ktest_item_name: ostd_test::KtestItem = ostd_test::KtestItem::new( #fn_name, (#should_panic, #expectation_tokens), - ktest::KtestItemInfo { + ostd_test::KtestItemInfo { module_path: module_path!(), fn_name: stringify!(#fn_name), package: #package_name, diff --git a/ostd/libs/ktest/Cargo.toml b/ostd/libs/ostd-test/Cargo.toml similarity index 54% rename from ostd/libs/ktest/Cargo.toml rename to ostd/libs/ostd-test/Cargo.toml index db397f1a..82d4bcac 100644 --- a/ostd/libs/ktest/Cargo.toml +++ b/ostd/libs/ostd-test/Cargo.toml @@ -1,7 +1,10 @@ [package] -name = "ktest" +name = "ostd-test" version = "0.1.0" edition = "2021" +description = "The kernel mode testing framework of OSTD" +license = "MPL-2.0" +repository ="https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/ostd/libs/ktest/src/lib.rs b/ostd/libs/ostd-test/src/lib.rs similarity index 92% rename from ostd/libs/ktest/src/lib.rs rename to ostd/libs/ostd-test/src/lib.rs index f193a7ac..94e2207f 100644 --- a/ostd/libs/ktest/src/lib.rs +++ b/ostd/libs/ostd-test/src/lib.rs @@ -1,20 +1,20 @@ // SPDX-License-Identifier: MPL-2.0 -//! # The kernel mode testing framework of Asterinas. +//! # The kernel mode testing framework of OSTD. //! -//! `ktest` stands for kernel-mode testing framework. Its goal is to provide a +//! `ostd-test` stands for kernel-mode testing framework for OSTD. Its goal is to provide a //! `cargo test`-like experience for any `#![no_std]` bare metal crates. //! -//! In Asterinas, all the tests written in the source tree of the crates will be run +//! In OSTD, all the tests written in the source tree of the crates will be run //! immediately after the initialization of `ostd`. Thus you can use any //! feature provided by the frame including the heap allocator, etc. //! -//! By all means, ktest is an individule crate that only requires: +//! By all means, ostd-test is an individule crate that only requires: //! - a custom linker script section `.ktest_array`, //! - and an alloc implementation. //! -//! And the frame happens to provide both of them. Thus, any crates depending -//! on the frame can use ktest without any extra dependency. +//! And the OSTD happens to provide both of them. Thus, any crates depending +//! on the OSTD can use ostd-test without any extra dependency. //! //! ## Usage //! @@ -43,7 +43,7 @@ //! } //! ``` //! -//! Any crates using the ktest framework should be linked with ostd. +//! Any crates using the ostd-test framework should be linked with ostd. //! //! ```toml //! # Cargo.toml diff --git a/ostd/libs/ktest/src/path.rs b/ostd/libs/ostd-test/src/path.rs similarity index 100% rename from ostd/libs/ktest/src/path.rs rename to ostd/libs/ostd-test/src/path.rs diff --git a/ostd/libs/ktest/src/runner.rs b/ostd/libs/ostd-test/src/runner.rs similarity index 100% rename from ostd/libs/ktest/src/runner.rs rename to ostd/libs/ostd-test/src/runner.rs diff --git a/ostd/libs/ktest/src/tree.rs b/ostd/libs/ostd-test/src/tree.rs similarity index 100% rename from ostd/libs/ktest/src/tree.rs rename to ostd/libs/ostd-test/src/tree.rs diff --git a/ostd/src/arch/x86/cpu.rs b/ostd/src/arch/x86/cpu.rs index da7beea7..5fbd5674 100644 --- a/ostd/src/arch/x86/cpu.rs +++ b/ostd/src/arch/x86/cpu.rs @@ -16,7 +16,8 @@ use bitvec::{ use log::debug; #[cfg(feature = "intel_tdx")] use tdx_guest::tdcall; -use trapframe::{GeneralRegs, UserContext as RawUserContext}; +pub use trapframe::GeneralRegs as RawGeneralRegs; +use trapframe::UserContext as RawUserContext; use x86_64::registers::{ rflags::RFlags, segmentation::{Segment64, FS}, @@ -131,7 +132,7 @@ pub struct CpuExceptionInfo { } #[cfg(feature = "intel_tdx")] -impl TdxTrapFrame for GeneralRegs { +impl TdxTrapFrame for RawGeneralRegs { fn rax(&self) -> usize { self.rax } @@ -258,12 +259,12 @@ impl UserPreemption { impl UserContext { /// Returns a reference to the general registers. - pub fn general_regs(&self) -> &GeneralRegs { + pub fn general_regs(&self) -> &RawGeneralRegs { &self.user_context.general } /// Returns a mutable reference to the general registers - pub fn general_regs_mut(&mut self) -> &mut GeneralRegs { + pub fn general_regs_mut(&mut self) -> &mut RawGeneralRegs { &mut self.user_context.general } diff --git a/ostd/src/arch/x86/iommu/context_table.rs b/ostd/src/arch/x86/iommu/context_table.rs index 4da92c8d..ba2fbeb4 100644 --- a/ostd/src/arch/x86/iommu/context_table.rs +++ b/ostd/src/arch/x86/iommu/context_table.rs @@ -6,7 +6,6 @@ use alloc::collections::BTreeMap; use core::mem::size_of; use log::warn; -use pod::Pod; use super::second_stage::{DeviceMode, PageTableEntry, PagingConsts}; use crate::{ @@ -17,6 +16,7 @@ use crate::{ page_table::PageTableError, Frame, FrameAllocOptions, Paddr, PageFlags, PageTable, VmIo, PAGE_SIZE, }, + Pod, }; /// Bit 0 is `Present` bit, indicating whether this entry is present. diff --git a/ostd/src/arch/x86/iommu/second_stage.rs b/ostd/src/arch/x86/iommu/second_stage.rs index 521db1a0..907b770f 100644 --- a/ostd/src/arch/x86/iommu/second_stage.rs +++ b/ostd/src/arch/x86/iommu/second_stage.rs @@ -4,12 +4,13 @@ use core::ops::Range; -use pod::Pod; - -use crate::mm::{ - page_prop::{CachePolicy, PageFlags, PrivilegedPageFlags as PrivFlags}, - page_table::{PageTableEntryTrait, PageTableMode}, - Paddr, PageProperty, PagingConstsTrait, PagingLevel, Vaddr, +use crate::{ + mm::{ + page_prop::{CachePolicy, PageFlags, PrivilegedPageFlags as PrivFlags}, + page_table::{PageTableEntryTrait, PageTableMode}, + Paddr, PageProperty, PagingConstsTrait, PagingLevel, Vaddr, + }, + Pod, }; /// The page table used by iommu maps the device address diff --git a/ostd/src/arch/x86/mm/mod.rs b/ostd/src/arch/x86/mm/mod.rs index 93d38baf..774a61de 100644 --- a/ostd/src/arch/x86/mm/mod.rs +++ b/ostd/src/arch/x86/mm/mod.rs @@ -5,14 +5,16 @@ use alloc::fmt; use core::ops::Range; -use pod::Pod; pub(crate) use util::__memcpy_fallible; use x86_64::{instructions::tlb, structures::paging::PhysFrame, VirtAddr}; -use crate::mm::{ - page_prop::{CachePolicy, PageFlags, PageProperty, PrivilegedPageFlags as PrivFlags}, - page_table::PageTableEntryTrait, - Paddr, PagingConstsTrait, PagingLevel, Vaddr, PAGE_SIZE, +use crate::{ + mm::{ + page_prop::{CachePolicy, PageFlags, PageProperty, PrivilegedPageFlags as PrivFlags}, + page_table::PageTableEntryTrait, + Paddr, PagingConstsTrait, PagingLevel, Vaddr, PAGE_SIZE, + }, + Pod, }; mod util; diff --git a/ostd/src/boot/mod.rs b/ostd/src/boot/mod.rs index 669e5fda..7604f903 100644 --- a/ostd/src/boot/mod.rs +++ b/ostd/src/boot/mod.rs @@ -156,7 +156,7 @@ fn run_ktests(test_whitelist: Option<&[&str]>, crate_whitelist: Option<&[&str]>) let fn_catch_unwind = &(unwinding::panic::catch_unwind::<(), fn()> as fn(fn()) -> Result<(), Box<(dyn Any + Send + 'static)>>); - use ktest::runner::{run_ktests, KtestResult}; + use ostd_test::runner::{run_ktests, KtestResult}; match run_ktests( &crate::console::early_print, fn_catch_unwind, diff --git a/ostd/src/cpu/mod.rs b/ostd/src/cpu/mod.rs index 63f84e9f..76f7d303 100644 --- a/ostd/src/cpu/mod.rs +++ b/ostd/src/cpu/mod.rs @@ -6,7 +6,6 @@ pub mod cpu_local; cfg_if::cfg_if! { if #[cfg(target_arch = "x86_64")]{ - pub use trapframe::GeneralRegs; pub use crate::arch::x86::cpu::*; } } diff --git a/ostd/src/io_mem.rs b/ostd/src/io_mem.rs index 249204fe..9a17cd43 100644 --- a/ostd/src/io_mem.rs +++ b/ostd/src/io_mem.rs @@ -4,11 +4,9 @@ use core::{mem::size_of, ops::Range}; -use pod::Pod; - use crate::{ mm::{kspace::LINEAR_MAPPING_BASE_VADDR, paddr_to_vaddr, HasPaddr, Paddr, Vaddr, VmIo}, - Error, Result, + Error, Pod, Result, }; /// I/O memory. diff --git a/ostd/src/lib.rs b/ostd/src/lib.rs index e4db96a2..abc7e577 100644 --- a/ostd/src/lib.rs +++ b/ostd/src/lib.rs @@ -44,6 +44,7 @@ pub mod trap; pub mod user; pub use ostd_macros::main; +pub use ostd_pod::Pod; pub use self::{cpu::cpu_local::CpuLocal, error::Error, prelude::Result}; @@ -123,5 +124,5 @@ mod test { /// The module re-exports everything from the ktest crate #[cfg(ktest)] pub mod ktest { - pub use ktest::*; + pub use ostd_test::*; } diff --git a/ostd/src/mm/io.rs b/ostd/src/mm/io.rs index 869315d7..e923f5d0 100644 --- a/ostd/src/mm/io.rs +++ b/ostd/src/mm/io.rs @@ -6,7 +6,6 @@ use core::marker::PhantomData; use align_ext::AlignExt; use inherit_methods_macro::inherit_methods; -use pod::Pod; use crate::{ arch::mm::__memcpy_fallible, @@ -15,7 +14,7 @@ use crate::{ MAX_USERSPACE_VADDR, }, prelude::*, - Error, + Error, Pod, }; /// A trait that enables reading/writing data from/to a VM object, diff --git a/ostd/src/mm/page_table/mod.rs b/ostd/src/mm/page_table/mod.rs index 0fc7487d..3b688692 100644 --- a/ostd/src/mm/page_table/mod.rs +++ b/ostd/src/mm/page_table/mod.rs @@ -2,14 +2,15 @@ use core::{fmt::Debug, marker::PhantomData, ops::Range}; -use pod::Pod; - use super::{ nr_subpage_per_huge, paddr_to_vaddr, page_prop::{PageFlags, PageProperty}, page_size, Paddr, PagingConstsTrait, PagingLevel, Vaddr, }; -use crate::arch::mm::{PageTableEntry, PagingConsts}; +use crate::{ + arch::mm::{PageTableEntry, PagingConsts}, + Pod, +}; mod node; use node::*; diff --git a/ostd/src/panicking.rs b/ostd/src/panicking.rs index bb247240..d9e4cb1f 100644 --- a/ostd/src/panicking.rs +++ b/ostd/src/panicking.rs @@ -29,7 +29,7 @@ use unwinding::{ /// panic handler in the binary crate. #[export_name = "__aster_panic_handler"] pub fn panic_handler(info: &core::panic::PanicInfo) -> ! { - let throw_info = ktest::PanicInfo { + let throw_info = ostd_test::PanicInfo { message: info.message().to_string(), file: info.location().unwrap().file().to_string(), line: info.location().unwrap().line() as usize, diff --git a/ostd/src/sync/atomic_bits.rs b/ostd/src/sync/atomic_bits.rs index a5fe3dfd..1b92799e 100644 --- a/ostd/src/sync/atomic_bits.rs +++ b/ostd/src/sync/atomic_bits.rs @@ -293,7 +293,6 @@ impl fmt::Debug for AtomicBits { #[cfg(ktest)] mod test { use super::*; - use crate::prelude::*; #[ktest] fn new() {