Add system info query fn
This commit is contained in:
parent
74ae797a2c
commit
c1885ebf81
@ -6,7 +6,7 @@ authors = ["Mark Poliakov <mark@alnyan.me>"]
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
yggdrasil-abi = { git = "https://git.alnyan.me/yggdrasil/yggdrasil-abi.git", features = ["rustc_std_alloc"] }
|
||||
yggdrasil-abi = { git = "https://git.alnyan.me/yggdrasil/yggdrasil-abi.git" }
|
||||
|
||||
core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" }
|
||||
alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" }
|
||||
@ -17,6 +17,7 @@ cc = "*"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
alloc = ["dep:alloc", "yggdrasil-abi/alloc"]
|
||||
rustc-dep-of-std = [
|
||||
"core",
|
||||
"alloc",
|
||||
|
63
src/lib.rs
63
src/lib.rs
@ -1,11 +1,9 @@
|
||||
//! Yggdrasil OS application runtime
|
||||
#![feature(rustc_private, ip_in_core)]
|
||||
#![feature(rustc_private)]
|
||||
#![no_std]
|
||||
#![deny(missing_docs)]
|
||||
#![allow(nonstandard_style)]
|
||||
|
||||
use core::ffi::{c_char, c_void};
|
||||
|
||||
#[cfg(not(feature = "rustc-dep-of-std"))]
|
||||
extern crate compiler_builtins;
|
||||
extern crate yggdrasil_abi as abi;
|
||||
@ -25,11 +23,22 @@ pub mod mem {
|
||||
pub use abi::mem::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;
|
||||
@ -55,56 +64,19 @@ unsafe extern "C" fn memcmp(p0: *const c_void, p1: *const c_void, len: usize) ->
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
#[cfg(feature = "rustc-dep-of-std")]
|
||||
{
|
||||
compiler_builtins::mem::memcpy(p0 as _, p1 as _, len) as _
|
||||
}
|
||||
#[cfg(not(feature = "rustc-dep-of-std"))]
|
||||
{
|
||||
let mut i = 0;
|
||||
while i < len {
|
||||
*(p0 as *mut u8).add(i) = *(p1 as *const u8).add(i);
|
||||
i += 1;
|
||||
}
|
||||
p0
|
||||
}
|
||||
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 {
|
||||
#[cfg(feature = "compiler_builtins")]
|
||||
{
|
||||
compiler_builtins::mem::memmove(dst as _, src as _, n) as _
|
||||
}
|
||||
#[cfg(not(feature = "compiler_builtins"))]
|
||||
{
|
||||
let dst = dst as usize;
|
||||
let src = src as usize;
|
||||
|
||||
if dst == src {
|
||||
return dst as _;
|
||||
}
|
||||
|
||||
if src + n <= dst || dst + n <= src {
|
||||
return memcpy(dst as _, src as _, n);
|
||||
}
|
||||
|
||||
if dst < src {
|
||||
let a = src - dst;
|
||||
memcpy(dst as _, src as _, a);
|
||||
memcpy(src as _, (src + a) as _, n - a);
|
||||
} else {
|
||||
let a = dst - src;
|
||||
memcpy((dst + a) as _, dst as _, n - a);
|
||||
memcpy(dst as _, src as _, a);
|
||||
}
|
||||
|
||||
dst as _
|
||||
}
|
||||
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;
|
||||
@ -115,6 +87,7 @@ unsafe extern "C" fn memset(dst: *mut c_void, val: i32, len: usize) -> *mut c_vo
|
||||
dst
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustc-dep-of-std")]
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn strlen(mut s: *mut c_char) -> usize {
|
||||
if s.is_null() {
|
||||
|
@ -16,6 +16,7 @@ use abi::{
|
||||
SpawnOptions, ThreadSpawnOptions,
|
||||
},
|
||||
syscall::SyscallFunction,
|
||||
system::SystemInfo,
|
||||
};
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
@ -840,3 +841,15 @@ pub unsafe fn accept(
|
||||
pub unsafe fn create_timer(repeat: bool) -> Result<RawFd, Error> {
|
||||
RawFd::from_syscall_result(syscall!(SyscallFunction::CreateTimer, argn!(repeat)))
|
||||
}
|
||||
|
||||
/// System call: query system information
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// Unsafe: direct system call
|
||||
pub unsafe fn get_system_info(info: &mut SystemInfo) -> Result<(), Error> {
|
||||
<()>::from_syscall_result(syscall!(
|
||||
SyscallFunction::GetSystemInfo,
|
||||
argp!(info as *mut _)
|
||||
))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user