From fc0ab35390e98d132c810d791ff8b3d6d405a353 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 15 Mar 2024 07:46:42 +0100 Subject: [PATCH] introduce feature flag `nostd` to boot the kernel without `std` --- Cargo.toml | 1 + src/errno.rs | 8 ++++++-- src/lib.rs | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 02dd3ca2c2..a2eec32ab9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ udp = ["smoltcp", "smoltcp/socket-udp"] trace = [] vga = [] common-os = [] +nostd = [] semihosting = ["dep:semihosting"] shell = ["simple-shell"] diff --git a/src/errno.rs b/src/errno.rs index 07c68b64f7..271c2afd95 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -396,11 +396,15 @@ pub const ERFKILL: i32 = 132; /// Robust mutexes: Memory page has hardware error pub const EHWPOISON: i32 = 133; -#[cfg(all(not(feature = "common-os"), not(target_arch = "riscv64")))] +#[cfg(all( + not(any(feature = "common-os", feature = "nostd")), + not(target_arch = "riscv64") +))] #[thread_local] pub(crate) static ERRNO: core::cell::UnsafeCell = core::cell::UnsafeCell::new(0); /// Get the error number from the thread local storage +#[cfg(not(feature = "nostd"))] #[no_mangle] pub extern "C" fn sys_get_errno() -> i32 { cfg_if::cfg_if! { @@ -423,7 +427,7 @@ pub(crate) trait ToErrno { { if let Some(errno) = self.to_errno() { cfg_if::cfg_if! { - if #[cfg(any(feature = "common-os", target_arch = "riscv64"))] { + if #[cfg(any(feature = "common-os", feature = "nostd", target_arch = "riscv64"))] { let _ = errno; } else { unsafe { diff --git a/src/lib.rs b/src/lib.rs index cd51074329..a0a6df9227 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -252,9 +252,9 @@ pub(crate) extern "C" fn __sys_free(ptr: *mut u8, size: usize, align: usize) { #[cfg(target_os = "none")] extern "C" fn initd(_arg: usize) { extern "C" { - #[cfg(all(not(test), not(feature = "common-os")))] + #[cfg(all(not(test), not(any(feature = "nostd", feature = "common-os"))))] fn runtime_entry(argc: i32, argv: *const *const u8, env: *const *const u8) -> !; - #[cfg(all(not(test), feature = "common-os"))] + #[cfg(all(not(test), any(feature = "nostd", feature = "common-os")))] fn main(argc: i32, argv: *const *const u8, env: *const *const u8); #[cfg(feature = "newlib")] fn init_lwip(); @@ -298,9 +298,9 @@ extern "C" fn initd(_arg: usize) { #[cfg(not(test))] unsafe { // And finally start the application. - #[cfg(all(not(test), not(feature = "common-os")))] + #[cfg(all(not(test), not(any(feature = "nostd", feature = "common-os"))))] runtime_entry(argc, argv, environ); - #[cfg(all(not(test), feature = "common-os"))] + #[cfg(all(not(test), any(feature = "nostd", feature = "common-os")))] main(argc, argv, environ); } #[cfg(test)]