114 lines
2.4 KiB
Rust

//! Yggdrasil OS application runtime
#![feature(
rustc_private,
decl_macro,
f128,
linkage,
naked_functions,
thread_local
)]
#![no_std]
#![deny(missing_docs)]
#![allow(nonstandard_style)]
#![allow(unused)]
// #[cfg(not(feature = "rustc-dep-of-std"))]
extern crate compiler_builtins;
extern crate yggdrasil_abi as abi;
extern crate alloc;
pub use abi::error::Error;
pub use abi::path;
pub mod debug;
pub mod io;
pub mod net;
pub mod process;
pub mod sync;
pub mod sys;
pub mod time;
pub mod mem {
//! Memory-related data structures
pub use abi::mem::{MappingFlags, MappingSource};
}
pub mod system {
//! System-related data structures
pub use abi::system::*;
}
#[cfg(feature = "rustc-dep-of-std")]
use core::ffi::{c_char, c_void};
#[cfg(feature = "rustc-dep-of-std")]
#[no_mangle]
unsafe extern "C" fn bcmp(p0: *const c_void, p1: *const c_void, len: usize) -> i32 {
memcmp(p0, p1, len)
}
#[cfg(feature = "rustc-dep-of-std")]
#[no_mangle]
unsafe extern "C" fn memcmp(p0: *const c_void, p1: *const c_void, len: usize) -> i32 {
let mut offset = 0;
if len == 0 {
return 0;
}
while offset < len {
let c0 = (p0 as *const u8).add(offset).read_volatile();
let c1 = (p1 as *const u8).add(offset).read_volatile();
if c0 > c1 {
return (c0 - c1) as i32;
} else if c0 < c1 {
return -((c1 - c0) as i32);
}
offset += 1;
}
0
}
/// XXX
#[cfg(feature = "rustc-dep-of-std")]
#[no_mangle]
pub unsafe extern "C" fn memcpy(p0: *mut c_void, p1: *const c_void, len: usize) -> *mut c_void {
compiler_builtins::mem::memcpy(p0 as _, p1 as _, len) as _
}
#[cfg(feature = "rustc-dep-of-std")]
#[no_mangle]
unsafe extern "C" fn memmove(dst: *mut c_void, src: *const c_void, n: usize) -> *mut c_void {
compiler_builtins::mem::memmove(dst as _, src as _, n) as _
}
#[cfg(feature = "rustc-dep-of-std")]
#[no_mangle]
unsafe extern "C" fn memset(dst: *mut c_void, val: i32, len: usize) -> *mut c_void {
let mut offset = 0;
while offset < len {
(dst as *mut u8).add(offset).write_volatile(val as u8);
offset += 1;
}
dst
}
#[cfg(feature = "rustc-dep-of-std")]
#[no_mangle]
unsafe extern "C" fn strlen(mut s: *mut c_char) -> usize {
if s.is_null() {
return 0;
}
let mut len = 0;
while s.read() != 0 {
len += 1;
s = s.add(1);
}
len
}