From 78322d6f31893f31fa84baa3496e48d5eedd8cfd Mon Sep 17 00:00:00 2001 From: Yuekai Jia Date: Tue, 26 Oct 2021 23:27:19 +0800 Subject: [PATCH] Merge crates zircon-loader and linux-loader into one crate --- .github/workflows/build-20210727.yml | 2 +- .github/workflows/docs.yml | 5 ++- Cargo.toml | 7 ++-- drivers/src/irq/mod.rs | 2 + drivers/src/lib.rs | 7 +++- drivers/src/mock/mod.rs | 3 +- kernel-hal/src/hal_fn.rs | 2 +- linux-loader/Cargo.toml | 24 ------------ linux-object/src/loader/mod.rs | 10 ++--- linux-syscall/src/lib.rs | 5 +-- loader/Cargo.toml | 37 +++++++++++++++++++ .../examples/linux-libos.rs | 9 ++++- .../examples/zircon-libos.rs | 4 +- {zircon-loader => loader}/src/kcounter.rs | 0 loader/src/lib.rs | 26 +++++++++++++ .../src/lib.rs => loader/src/linux.rs | 10 +---- .../src/lib.rs => loader/src/zircon.rs | 26 +++++-------- {linux-loader => loader}/tests/linux.rs | 4 +- {zircon-loader => loader}/tests/zircon.rs | 2 +- scripts/libos-libc-tests.py | 2 +- scripts/unix-core-testone.py | 1 - scripts/unix-core-tests.py | 1 - zCore/Cargo.toml | 11 +++--- zCore/src/fs.rs | 11 ++---- zCore/src/main.rs | 8 ++-- zCore/src/utils.rs | 13 ++++++- zircon-loader/Cargo.toml | 24 ------------ zircon-syscall/Cargo.toml | 2 - zircon-syscall/src/vmar.rs | 9 +++-- 29 files changed, 138 insertions(+), 129 deletions(-) delete mode 100644 linux-loader/Cargo.toml create mode 100644 loader/Cargo.toml rename {linux-loader => loader}/examples/linux-libos.rs (63%) rename {zircon-loader => loader}/examples/zircon-libos.rs (74%) rename {zircon-loader => loader}/src/kcounter.rs (100%) create mode 100644 loader/src/lib.rs rename linux-loader/src/lib.rs => loader/src/linux.rs (97%) rename zircon-loader/src/lib.rs => loader/src/zircon.rs (95%) rename {linux-loader => loader}/tests/linux.rs (98%) rename {zircon-loader => loader}/tests/zircon.rs (79%) delete mode 100644 zircon-loader/Cargo.toml diff --git a/.github/workflows/build-20210727.yml b/.github/workflows/build-20210727.yml index f8d912c3..5803ed5f 100644 --- a/.github/workflows/build-20210727.yml +++ b/.github/workflows/build-20210727.yml @@ -69,7 +69,7 @@ jobs: with: command: build use-cross: true - args: --target aarch64-unknown-linux-gnu --workspace --exclude linux-syscall --exclude linux-loader --exclude zcore + args: --target aarch64-unknown-linux-gnu --workspace --exclude linux-syscall --exclude zcore-loader --exclude zcore build-user: runs-on: ${{ matrix.os }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f4e5e7ff..986bed5a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,10 +15,11 @@ jobs: cat >target/doc/index.html < - + + Redirection - look here +

Redirecting to kernel_hal/index.html...

EOF diff --git a/Cargo.toml b/Cargo.toml index bfa7e032..4c5ca580 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,12 @@ [workspace] members = [ + "drivers", + "kernel-hal", "zircon-object", "zircon-syscall", - "zircon-loader", "linux-object", "linux-syscall", - "linux-loader", - "kernel-hal", - "drivers", + "loader", "zCore", ] diff --git a/drivers/src/irq/mod.rs b/drivers/src/irq/mod.rs index 61c1968c..d12ddbf6 100644 --- a/drivers/src/irq/mod.rs +++ b/drivers/src/irq/mod.rs @@ -3,6 +3,7 @@ cfg_if::cfg_if! { mod riscv_intc; mod riscv_plic; + #[doc(cfg(any(target_arch = "riscv32", target_arch = "riscv64")))] pub mod riscv { pub use super::riscv_intc::{Intc, ScauseIntCode}; pub use super::riscv_plic::Plic; @@ -10,6 +11,7 @@ cfg_if::cfg_if! { } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { mod x86_apic; + #[doc(cfg(any(target_arch = "x86", target_arch = "x86_64")))] pub mod x86 { pub use super::x86_apic::Apic; } diff --git a/drivers/src/lib.rs b/drivers/src/lib.rs index 29f3e529..67961b32 100644 --- a/drivers/src/lib.rs +++ b/drivers/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(not(feature = "mock"), no_std)] #![feature(asm)] +#![feature(doc_cfg)] extern crate alloc; @@ -9,10 +10,12 @@ extern crate log; use alloc::sync::Arc; use core::fmt; -#[cfg(feature = "mock")] +#[cfg(any(feature = "mock", doc))] +#[doc(cfg(feature = "mock"))] pub mod mock; -#[cfg(feature = "virtio")] +#[cfg(any(feature = "virtio", doc))] +#[doc(cfg(feature = "virtio"))] pub mod virtio; pub mod builder; diff --git a/drivers/src/mock/mod.rs b/drivers/src/mock/mod.rs index 57f99af7..4e59256d 100644 --- a/drivers/src/mock/mod.rs +++ b/drivers/src/mock/mod.rs @@ -2,5 +2,6 @@ pub mod display; pub mod input; pub mod uart; -#[cfg(feature = "graphic")] +#[cfg(any(feature = "graphic", doc))] +#[doc(cfg(feature = "graphic"))] pub mod graphic; diff --git a/kernel-hal/src/hal_fn.rs b/kernel-hal/src/hal_fn.rs index 94dce320..182a77d0 100644 --- a/kernel-hal/src/hal_fn.rs +++ b/kernel-hal/src/hal_fn.rs @@ -8,7 +8,7 @@ hal_fn_def! { /// Bootstrap and initialization. pub mod boot { /// The kernel command line. - pub fn cmdline() -> String { "".into() } + pub fn cmdline() -> String { String::new() } /// Returns the slice of the initial RAM disk, or `None` if not exist. pub fn init_ram_disk() -> Option<&'static mut [u8]> { diff --git a/linux-loader/Cargo.toml b/linux-loader/Cargo.toml deleted file mode 100644 index c8984c76..00000000 --- a/linux-loader/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "linux-loader" -version = "0.1.0" -authors = ["Runji Wang "] -edition = "2018" -description = "Linux programs loader and runner." - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -log = "0.4" -linux-syscall = { path = "../linux-syscall" } -linux-object = { path = "../linux-object" } -zircon-object = { path = "../zircon-object" } -kernel-hal = { path = "../kernel-hal", default-features = false } - -[features] -default = ["libos"] -libos = ["kernel-hal/libos", "zircon-object/aspace-separate"] - -[dev-dependencies] -env_logger = "0.9" -async-std = { version = "1.10", features = ["attributes"] } -rcore-fs-hostfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec" } diff --git a/linux-object/src/loader/mod.rs b/linux-object/src/loader/mod.rs index 66b358d7..5d5d2fcb 100644 --- a/linux-object/src/loader/mod.rs +++ b/linux-object/src/loader/mod.rs @@ -28,7 +28,7 @@ impl LinuxElfLoader { &self, vmar: &Arc, data: &[u8], - mut args: Vec, + args: Vec, envs: Vec, path: String, ) -> LxResult<(VirtAddr, VirtAddr)> { @@ -45,12 +45,12 @@ impl LinuxElfLoader { debug!("elf info: {:#x?}", elf.header.pt2); if let Ok(interp) = elf.get_interpreter() { - info!("interp: {:?}", interp); + info!("interp: {:?}, path: {:?}", interp, path); let inode = self.root_inode.lookup(interp)?; let data = inode.read_as_vec()?; - args[0] = path.clone(); - args.insert(0, interp.into()); - return self.load(vmar, &data, args, envs, path); + let mut new_args = vec![interp.into(), path.clone()]; + new_args.extend_from_slice(&args[1..]); + return self.load(vmar, &data, new_args, envs, path); } let size = elf.load_segment_size(); diff --git a/linux-syscall/src/lib.rs b/linux-syscall/src/lib.rs index 08044505..8380e3f1 100644 --- a/linux-syscall/src/lib.rs +++ b/linux-syscall/src/lib.rs @@ -1,16 +1,13 @@ //! Linux syscall implementations //! //! ## Example -//! the syscall is called like this in the linux-loader: +//! The syscall is called like this in the [`zcore_loader`](../zcore_loader/index.html): //! ```ignore //! let num = regs.rax as u32; //! let args = [regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9]; //! let mut syscall = Syscall { //! thread, -//! #[cfg(feature = "libos")] //! syscall_entry: kernel_hal::context::syscall_entry as usize, -//! #[cfg(not(feature = "libos"))] -//! syscall_entry: 0, //! thread_fn, //! regs, //! }; diff --git a/loader/Cargo.toml b/loader/Cargo.toml new file mode 100644 index 00000000..2d747505 --- /dev/null +++ b/loader/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "zcore-loader" +version = "0.1.0" +authors = ["Runji Wang ", "Yuekai Jia "] +edition = "2018" +description = "Linux and Zircon user programs loader and runner." + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +log = "0.4" +cfg-if = "1.0" +xmas-elf = { version = "0.7", optional = true } +kernel-hal = { path = "../kernel-hal", default-features = false } +zircon-object = { path = "../zircon-object", features = ["elf"] } +linux-object = { path = "../linux-object", optional = true } +zircon-syscall = { path = "../zircon-syscall", optional = true } +linux-syscall = { path = "../linux-syscall", optional = true } + +[features] +default = ["libos", "linux", "zircon"] +linux = ["linux-object", "linux-syscall"] +zircon = ["zircon-syscall", "xmas-elf"] +libos = ["kernel-hal/libos", "zircon-object/aspace-separate"] + +[dev-dependencies] +env_logger = "0.9" +async-std = { version = "1.10", features = ["attributes"] } +rcore-fs-hostfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec" } + +[[example]] +name = "linux-libos" +required-features = ["linux", "libos"] + +[[example]] +name = "zircon-libos" +required-features = ["zircon", "libos"] diff --git a/linux-loader/examples/linux-libos.rs b/loader/examples/linux-libos.rs similarity index 63% rename from linux-loader/examples/linux-libos.rs rename to loader/examples/linux-libos.rs index 96cae9c6..6822e880 100644 --- a/linux-loader/examples/linux-libos.rs +++ b/loader/examples/linux-libos.rs @@ -6,12 +6,17 @@ async fn main() { env_logger::init(); kernel_hal::init(); - let args = env::args().skip(1).collect(); + let args = std::env::args().collect::>(); + if args.len() < 2 { + println!("Usage: {} PROGRAM", args[0]); + std::process::exit(-1); + } + let envs = vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin".into()]; let rootfs_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("../rootfs"); let hostfs = rcore_fs_hostfs::HostFS::new(rootfs_path); - let proc = linux_loader::run(args, envs, hostfs); + let proc = zcore_loader::linux::run(args[1..].to_vec(), envs, hostfs); let code = proc.wait_for_exit().await; std::process::exit(code as i32); } diff --git a/zircon-loader/examples/zircon-libos.rs b/loader/examples/zircon-libos.rs similarity index 74% rename from zircon-loader/examples/zircon-libos.rs rename to loader/examples/zircon-libos.rs index bdd7c928..52d00f9f 100644 --- a/zircon-loader/examples/zircon-libos.rs +++ b/loader/examples/zircon-libos.rs @@ -13,8 +13,8 @@ async fn main() { } let zbi = std::fs::read(&args[1]).expect("failed to read zbi file"); - let cmdline = args.get(2).map(String::as_str).unwrap_or(""); + let cmdline = args.get(2).map(String::as_str).unwrap_or_default(); - let proc: Arc = zircon_loader::run_userboot(zbi, cmdline); + let proc: Arc = zcore_loader::zircon::run_userboot(zbi, cmdline); proc.wait_signal(Signal::USER_SIGNAL_0).await; } diff --git a/zircon-loader/src/kcounter.rs b/loader/src/kcounter.rs similarity index 100% rename from zircon-loader/src/kcounter.rs rename to loader/src/kcounter.rs diff --git a/loader/src/lib.rs b/loader/src/lib.rs new file mode 100644 index 00000000..c6314c65 --- /dev/null +++ b/loader/src/lib.rs @@ -0,0 +1,26 @@ +//! Linux and Zircon user programs loader and runner. + +#![no_std] +#![feature(asm)] +#![feature(doc_cfg)] +#![deny(warnings, unused_must_use, missing_docs)] + +extern crate alloc; +#[macro_use] +extern crate log; + +cfg_if::cfg_if! { + if #[cfg(any(feature = "linux", doc))] { + #[doc(cfg(feature = "linux"))] + pub mod linux; + } +} + +cfg_if::cfg_if! { + if #[cfg(any(feature = "zircon", doc))] { + mod kcounter; + + #[doc(cfg(feature = "zircon"))] + pub mod zircon; + } +} diff --git a/linux-loader/src/lib.rs b/loader/src/linux.rs similarity index 97% rename from linux-loader/src/lib.rs rename to loader/src/linux.rs index c19760ba..31a6e055 100644 --- a/linux-loader/src/lib.rs +++ b/loader/src/linux.rs @@ -1,12 +1,4 @@ -//! Linux LibOS -//! - run process and manage trap/interrupt/syscall -#![no_std] -#![feature(asm)] -#![deny(warnings, unused_must_use, missing_docs)] - -extern crate alloc; -#[macro_use] -extern crate log; +//! Run Linux process and manage trap/interrupt/syscall. use { alloc::{boxed::Box, string::String, sync::Arc, vec::Vec}, diff --git a/zircon-loader/src/lib.rs b/loader/src/zircon.rs similarity index 95% rename from zircon-loader/src/lib.rs rename to loader/src/zircon.rs index 6471047d..bb63a7c9 100644 --- a/zircon-loader/src/lib.rs +++ b/loader/src/zircon.rs @@ -1,11 +1,4 @@ -#![no_std] -#![feature(asm)] -#![deny(warnings, unused_must_use)] - -#[macro_use] -extern crate alloc; -#[macro_use] -extern crate log; +//! Run Zircon user program (userboot) and manage trap/interrupt/syscall. use { alloc::{boxed::Box, sync::Arc, vec::Vec}, @@ -15,8 +8,6 @@ use { zircon_syscall::Syscall, }; -mod kcounter; - // These describe userboot itself const K_PROC_SELF: usize = 0; const K_VMARROOT_SELF: usize = 1; @@ -32,13 +23,13 @@ const K_COUNTERS: usize = 10; const K_FISTINSTRUMENTATIONDATA: usize = 11; const K_HANDLECOUNT: usize = 15; -macro_rules! boot_firmware { +macro_rules! boot_library { ($name: expr) => {{ cfg_if::cfg_if! { if #[cfg(target_arch = "x86_64")] { - boot_firmware!($name, "../../prebuilt/zircon/x64") + boot_library!($name, "../../prebuilt/zircon/x64") } else if #[cfg(target_arch = "aarch64")] { - boot_firmware!($name, "../../prebuilt/zircon/arm64") + boot_library!($name, "../../prebuilt/zircon/arm64") } else { compile_error!("Unsupported architecture for zircon mode!") } @@ -56,9 +47,10 @@ macro_rules! boot_firmware { }}; } +/// Run Zircon `userboot` process from the prebuilt path, and load the ZBI file as the bootfs. pub fn run_userboot(zbi: impl AsRef<[u8]>, cmdline: &str) -> Arc { - let userboot = boot_firmware!("userboot"); - let vdso = boot_firmware!("libzircon"); + let userboot = boot_library!("userboot"); + let vdso = boot_library!("libzircon"); let job = Job::root(); let proc = Process::create(&job, "userboot").unwrap(); @@ -137,7 +129,7 @@ pub fn run_userboot(zbi: impl AsRef<[u8]>, cmdline: &str) -> Arc { let (user_channel, kernel_channel) = Channel::create(); let handle = Handle::new(user_channel, Rights::DEFAULT_CHANNEL); - let mut handles = vec![Handle::new(proc.clone(), Rights::empty()); K_HANDLECOUNT]; + let mut handles = alloc::vec![Handle::new(proc.clone(), Rights::empty()); K_HANDLECOUNT]; handles[K_PROC_SELF] = Handle::new(proc.clone(), Rights::DEFAULT_PROCESS); handles[K_VMARROOT_SELF] = Handle::new(proc.vmar(), Rights::DEFAULT_VMAR | Rights::IO); handles[K_ROOTJOB] = Handle::new(job, Rights::DEFAULT_JOB); @@ -161,7 +153,7 @@ pub fn run_userboot(zbi: impl AsRef<[u8]>, cmdline: &str) -> Arc { let crash_log_vmo = VmObject::new_paged(1); crash_log_vmo.set_name("crashlog"); handles[K_CRASHLOG] = Handle::new(crash_log_vmo, Rights::DEFAULT_VMO); - let (counter_name_vmo, kcounters_vmo) = kcounter::create_kcounter_vmo(); + let (counter_name_vmo, kcounters_vmo) = super::kcounter::create_kcounter_vmo(); handles[K_COUNTERNAMES] = Handle::new(counter_name_vmo, Rights::DEFAULT_VMO); handles[K_COUNTERS] = Handle::new(kcounters_vmo, Rights::DEFAULT_VMO); // TODO: use correct Instrumentation data handle diff --git a/linux-loader/tests/linux.rs b/loader/tests/linux.rs similarity index 98% rename from linux-loader/tests/linux.rs rename to loader/tests/linux.rs index 50cb87b9..b004fbd2 100644 --- a/linux-loader/tests/linux.rs +++ b/loader/tests/linux.rs @@ -1,5 +1,3 @@ -//! Linux LibOS entrance - use rcore_fs_hostfs::HostFS; use std::fs; @@ -10,7 +8,7 @@ async fn test(cmdline: &str) -> i64 { let args: Vec = cmdline.split(' ').map(|s| s.into()).collect(); let envs = vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/x86_64-alpine-linux-musl/bin".into()]; // TODO let hostfs = HostFS::new("../rootfs"); - let proc = linux_loader::run(args, envs, hostfs); + let proc = zcore_loader::linux::run(args, envs, hostfs); proc.wait_for_exit().await } diff --git a/zircon-loader/tests/zircon.rs b/loader/tests/zircon.rs similarity index 79% rename from zircon-loader/tests/zircon.rs rename to loader/tests/zircon.rs index 7e12c72c..4b140353 100644 --- a/zircon-loader/tests/zircon.rs +++ b/loader/tests/zircon.rs @@ -3,6 +3,6 @@ async fn userboot() { kernel_hal::init(); let zbi = std::fs::read("../prebuilt/zircon/x64/bringup.zbi").expect("failed to read zbi file"); - let proc = zircon_loader::run_userboot(zbi, ""); + let proc = zcore_loader::zircon::run_userboot(zbi, ""); proc.wait_for_exit().await; } diff --git a/scripts/libos-libc-tests.py b/scripts/libos-libc-tests.py index f11de12b..c4c286f6 100755 --- a/scripts/libos-libc-tests.py +++ b/scripts/libos-libc-tests.py @@ -73,4 +73,4 @@ if check_failed: else: print(colored('All checked case passed!', 'green')) -os.system('killall linux-loader') +os.system('killall zcore') diff --git a/scripts/unix-core-testone.py b/scripts/unix-core-testone.py index 12898e88..2f22d8f7 100644 --- a/scripts/unix-core-testone.py +++ b/scripts/unix-core-testone.py @@ -4,7 +4,6 @@ import re import argparse TIMEOUT = 300 -ZIRCON_LOADER_PATH = 'zircon-loader' ZBI_PATH = '../prebuilt/zircon/x64/core-tests.zbi' CMDLINE_BASE = 'LOG=warn:userboot=test/core-standalone-test:userboot.shutdown:core-tests=' diff --git a/scripts/unix-core-tests.py b/scripts/unix-core-tests.py index f95a4448..25d792f5 100644 --- a/scripts/unix-core-tests.py +++ b/scripts/unix-core-tests.py @@ -5,7 +5,6 @@ import os import subprocess TIMEOUT = 300 -ZIRCON_LOADER_PATH = 'zircon-loader' BASE = 'zircon/' OUTPUT_FILE = BASE + 'test-output-libos.txt' RESULT_FILE = BASE + 'test-result-libos.txt' diff --git a/zCore/Cargo.toml b/zCore/Cargo.toml index 4fbc9f3e..f895e3f1 100644 --- a/zCore/Cargo.toml +++ b/zCore/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zcore" version = "0.1.0" -authors = ["PanQL "] +authors = ["PanQL ", "Yuekai Jia "] edition = "2018" default-run = "zcore" @@ -21,10 +21,10 @@ graphic = ["kernel-hal/graphic"] init-ram-disk = [] link-user-img = ["init-ram-disk"] -zircon = ["zircon-loader"] -linux = ["linux-loader", "linux-object", "rcore-fs", "rcore-fs-sfs"] +zircon = ["zcore-loader/zircon"] +linux = ["zcore-loader/linux", "linux-object", "rcore-fs", "rcore-fs-sfs"] -libos = ["async-std", "chrono", "rcore-fs-hostfs", "kernel-hal/libos", "linux-loader/libos", "zircon-loader/libos"] +libos = ["kernel-hal/libos", "zcore-loader/libos", "async-std", "chrono", "rcore-fs-hostfs"] board-qemu = [] board-d1 = ["link-user-img"] @@ -35,10 +35,9 @@ cfg-if = "1.0" lazy_static = { version = "1.4", features = ["spin_no_std" ] } bitmap-allocator = { git = "https://github.com/rcore-os/bitmap-allocator", rev = "b3f9f51" } kernel-hal = { path = "../kernel-hal", default-features = false, features = ["smp"] } +zcore-loader = { path = "../loader", default-features = false } zircon-object = { path = "../zircon-object" } linux-object = { path = "../linux-object", optional = true } -zircon-loader = { path = "../zircon-loader", default-features = false, optional = true } -linux-loader = { path = "../linux-loader", default-features = false, optional = true } rcore-fs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec", optional = true } rcore-fs-sfs = { git = "https://github.com/rcore-os/rcore-fs", rev = "7c232ec", optional = true } diff --git a/zCore/src/fs.rs b/zCore/src/fs.rs index b116407b..8c7d5b5f 100644 --- a/zCore/src/fs.rs +++ b/zCore/src/fs.rs @@ -1,4 +1,5 @@ -#[allow(dead_code)] +#![allow(dead_code)] + fn init_ram_disk() -> &'static mut [u8] { if cfg!(feature = "link-user-img") { extern "C" { @@ -49,12 +50,8 @@ cfg_if! { #[cfg(feature = "libos")] pub fn zbi() -> impl AsRef<[u8]> { - let args = std::env::args().collect::>(); - if args.len() < 2 { - println!("Usage: {} ZBI_FILE [CMDLINE]", args[0]); - std::process::exit(-1); - } - std::fs::read(&args[1]).expect("failed to read zbi file") + let path = std::env::args().nth(1).unwrap(); + std::fs::read(path).expect("failed to read zbi file") } #[cfg(not(feature = "libos"))] diff --git a/zCore/src/main.rs b/zCore/src/main.rs index 3a61c9e6..d7b155cf 100644 --- a/zCore/src/main.rs +++ b/zCore/src/main.rs @@ -35,15 +35,17 @@ fn primary_main(config: kernel_hal::KernelConfig) { kernel_hal::primary_init(); cfg_if! { - if #[cfg(feature = "linux")] { + if #[cfg(all(feature = "linux", feature = "zircon"))] { + panic!("Feature `linux` and `zircon` cannot be enabled at the same time!"); + } else if #[cfg(feature = "linux")] { let args = options.root_proc.split('?').map(Into::into).collect(); // parse "arg0?arg1?arg2" let envs = alloc::vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin".into()]; let rootfs = fs::rootfs(); - let proc = linux_loader::run(args, envs, rootfs); + let proc = zcore_loader::linux::run(args, envs, rootfs); utils::wait_for_exit(Some(proc)) } else if #[cfg(feature = "zircon")] { let zbi = fs::zbi(); - let proc = zircon_loader::run_userboot(zbi, &options.cmdline); + let proc = zcore_loader::zircon::run_userboot(zbi, &options.cmdline); utils::wait_for_exit(Some(proc)) } else { panic!("One of the features `linux` or `zircon` must be specified!"); diff --git a/zCore/src/utils.rs b/zCore/src/utils.rs index e9177e03..5f1cd00b 100644 --- a/zCore/src/utils.rs +++ b/zCore/src/utils.rs @@ -29,9 +29,18 @@ fn parse_cmdline(cmdline: &str) -> BTreeMap<&str, &str> { pub fn boot_options() -> BootOptions { cfg_if! { if #[cfg(feature = "libos")] { + let args = std::env::args().collect::>(); + if args.len() < 2 { + #[cfg(feature = "linux")] + println!("Usage: {} PROGRAM", args[0]); + #[cfg(feature = "zircon")] + println!("Usage: {} ZBI_FILE [CMDLINE]", args[0]); + std::process::exit(-1); + } + let log_level = std::env::var("LOG").unwrap_or_default(); let cmdline = if cfg!(feature = "zircon") { - std::env::args().nth(2).unwrap_or_default() + args.get(2).cloned().unwrap_or_default() } else { String::new() }; @@ -39,7 +48,7 @@ pub fn boot_options() -> BootOptions { cmdline, log_level, #[cfg(feature = "linux")] - root_proc: std::env::args().skip(1).collect::>().join("?"), + root_proc: args[1..].join("?"), } } else { let cmdline = kernel_hal::boot::cmdline(); diff --git a/zircon-loader/Cargo.toml b/zircon-loader/Cargo.toml deleted file mode 100644 index afab5c20..00000000 --- a/zircon-loader/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "zircon-loader" -version = "0.1.0" -authors = ["Runji Wang "] -edition = "2018" -description = "Zircon user program (userboot) loader" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -log = "0.4" -cfg-if = "1.0" -xmas-elf = "0.7" -zircon-object = { path = "../zircon-object", features = ["elf"] } -zircon-syscall = { path = "../zircon-syscall" } -kernel-hal = { path = "../kernel-hal", default-features = false } - -[features] -default = ["libos"] -libos = ["kernel-hal/libos", "zircon-object/aspace-separate", "zircon-syscall/libos"] - -[dev-dependencies] -env_logger = "0.9" -async-std = { version = "1.10", features = ["attributes"] } diff --git a/zircon-syscall/Cargo.toml b/zircon-syscall/Cargo.toml index 17cfea01..041e2bbe 100644 --- a/zircon-syscall/Cargo.toml +++ b/zircon-syscall/Cargo.toml @@ -9,9 +9,7 @@ description = "Zircon syscalls implementation" [features] # hypervisor = ["zircon-object/hypervisor"] -default = [] deny-page-fault = [] -libos = ["deny-page-fault", "kernel-hal/libos"] [dependencies] log = "0.4" diff --git a/zircon-syscall/src/vmar.rs b/zircon-syscall/src/vmar.rs index 0251f99a..742c74f8 100644 --- a/zircon-syscall/src/vmar.rs +++ b/zircon-syscall/src/vmar.rs @@ -129,10 +129,11 @@ impl Syscall<'_> { mapping_flags.set(MMUFlags::WRITE, options.contains(VmOptions::PERM_WRITE)); mapping_flags.set(MMUFlags::EXECUTE, options.contains(VmOptions::PERM_EXECUTE)); let overwrite = options.contains(VmOptions::SPECIFIC_OVERWRITE); - #[cfg(feature = "deny-page-fault")] - let map_range = true; - #[cfg(not(feature = "deny-page-fault"))] - let map_range = options.contains(VmOptions::MAP_RANGE); + let map_range = if cfg!(any(feature = "deny-page-fault", not(target_os = "none"))) { + true + } else { + options.contains(VmOptions::MAP_RANGE) + }; info!( "mmuflags: {:?}, is_specific {:?}, overwrite {:?}, map_range {:?}",