Skip to content

Commit

Permalink
Merge pull request #1098 from stlankes/no_std
Browse files Browse the repository at this point in the history
introduce feature flag `nostd` to boot the kernel without `std`
  • Loading branch information
stlankes authored Mar 15, 2024
2 parents dd0112f + fc0ab35 commit d8b600a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ udp = ["smoltcp", "smoltcp/socket-udp"]
trace = []
vga = []
common-os = []
nostd = []
semihosting = ["dep:semihosting"]
shell = ["simple-shell"]

Expand Down
8 changes: 6 additions & 2 deletions src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> = 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! {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit d8b600a

Please sign in to comment.