maint/proc: add /sys/proc + migrate to rustc 1.87.0-nightly
This commit is contained in:
parent
a45c54faf8
commit
31fa51e64c
@ -3,7 +3,7 @@
|
||||
"os": "none",
|
||||
"abi": "softfloat",
|
||||
"llvm-target": "aarch64-unknown-none",
|
||||
"data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
|
||||
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
|
||||
"max-atomic-width": 128,
|
||||
"target-pointer-width": "64",
|
||||
"features": "+v8a,+strict-align,-neon,-fp-armv8",
|
||||
|
@ -3,11 +3,12 @@
|
||||
"cpu": "x86-64",
|
||||
"os": "none",
|
||||
"abi": "softfloat",
|
||||
"rustc-abi": "x86-softfloat",
|
||||
"llvm-target": "x86_64-unknown-linux-gnu",
|
||||
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
|
||||
"max-atomic-width": 64,
|
||||
"target-pointer-width": "64",
|
||||
"features": "-avx,-sse,+soft-float",
|
||||
"features": "-avx,-sse,-avx2,+soft-float",
|
||||
|
||||
"disable-redzone": true,
|
||||
"executables": true,
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![no_std]
|
||||
#![feature(naked_functions, trait_upcasting, decl_macro)]
|
||||
#![feature(naked_functions, decl_macro)]
|
||||
#![allow(clippy::new_without_default)]
|
||||
|
||||
extern crate alloc;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![no_std]
|
||||
#![allow(clippy::new_without_default)]
|
||||
#![feature(naked_functions, trait_upcasting)]
|
||||
#![feature(naked_functions)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
|
@ -84,8 +84,7 @@ impl ScsiTransportWrapper {
|
||||
response_buffer.slice_mut(0..R::RESPONSE_LEN),
|
||||
)
|
||||
.await?;
|
||||
let response_bytes =
|
||||
unsafe { MaybeUninit::slice_assume_init_ref(&response_buffer[..response_len]) };
|
||||
let response_bytes = unsafe { response_buffer[..response_len].assume_init_ref() };
|
||||
|
||||
R::parse_response(response_bytes)
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ impl UsbDriver for UsbHidKeyboardDriver {
|
||||
event_count += state.retain(&buffer[2..], &mut events[event_count..]);
|
||||
event_count += state.press(&buffer[2..], &mut events[event_count..]);
|
||||
|
||||
let events = unsafe { MaybeUninit::slice_assume_init_ref(&events[..event_count]) };
|
||||
let events = unsafe { events[..event_count].assume_init_ref() };
|
||||
|
||||
for &event in events {
|
||||
log::trace!("Generic Keyboard: {:?}", event);
|
||||
|
@ -4,7 +4,6 @@
|
||||
iter_array_chunks,
|
||||
maybe_uninit_slice,
|
||||
maybe_uninit_as_bytes,
|
||||
maybe_uninit_uninit_array,
|
||||
maybe_uninit_write_slice,
|
||||
maybe_uninit_fill
|
||||
)]
|
||||
|
@ -215,7 +215,7 @@ impl UsbControlPipeAccess {
|
||||
}
|
||||
|
||||
pub async fn query_string(&self, index: u8) -> Result<String, UsbError> {
|
||||
let mut buffer = MaybeUninit::uninit_array::<256>();
|
||||
let mut buffer = [MaybeUninit::uninit(); 256];
|
||||
|
||||
let len = self
|
||||
.control_transfer_in(
|
||||
@ -229,7 +229,7 @@ impl UsbControlPipeAccess {
|
||||
&mut buffer[..],
|
||||
)
|
||||
.await?;
|
||||
let data = unsafe { MaybeUninit::slice_assume_init_ref(&buffer[..len]) };
|
||||
let data = unsafe { buffer[..len].assume_init_ref() };
|
||||
let len = data[0] as usize;
|
||||
|
||||
decode_usb_string(&data[2..len])
|
||||
|
@ -15,7 +15,7 @@ pub trait UsbNormalPipeIn: UsbGenericPipe {
|
||||
async fn read(&self, buffer: &mut [u8]) -> Result<usize, UsbError> {
|
||||
let mut dma_buffer = self.allocate_dma_buffer(buffer.len())?;
|
||||
let len = self.read_dma(dma_buffer.slice_mut(0..buffer.len())).await?;
|
||||
let dma_slice = unsafe { MaybeUninit::slice_assume_init_ref(&dma_buffer[..len]) };
|
||||
let dma_slice = unsafe { dma_buffer[..len].assume_init_ref() };
|
||||
buffer[..len].copy_from_slice(dma_slice);
|
||||
Ok(len)
|
||||
}
|
||||
@ -35,7 +35,7 @@ pub trait UsbNormalPipeOut: UsbGenericPipe {
|
||||
|
||||
async fn write(&self, buffer: &[u8]) -> Result<usize, UsbError> {
|
||||
let mut dma_buffer = self.allocate_dma_buffer(buffer.len())?;
|
||||
MaybeUninit::copy_from_slice(&mut dma_buffer, buffer);
|
||||
dma_buffer[..].write_copy_of_slice(buffer);
|
||||
let dma_buffer = unsafe { DmaBuffer::assume_init_slice(dma_buffer) };
|
||||
|
||||
self.write_dma(dma_buffer.slice(0..buffer.len())).await
|
||||
|
@ -28,8 +28,8 @@ impl<'a, A: BlockAllocator> BVec<'a, A> {
|
||||
///
|
||||
/// The function is guaranteed to make no allocations before the vector is actually written to.
|
||||
pub fn new() -> Self {
|
||||
let mut l0 = MaybeUninit::uninit_array();
|
||||
let mut l1 = MaybeUninit::uninit_array();
|
||||
let mut l0 = [const { MaybeUninit::uninit() }; L0_BLOCKS];
|
||||
let mut l1 = [const { MaybeUninit::uninit() }; L1_BLOCKS];
|
||||
|
||||
for it in l0.iter_mut() {
|
||||
it.write(BlockData::null());
|
||||
|
@ -2,7 +2,7 @@
|
||||
#![no_std]
|
||||
#![deny(missing_docs)]
|
||||
#![allow(clippy::new_without_default, clippy::new_ret_no_self)]
|
||||
#![feature(maybe_uninit_uninit_array, maybe_uninit_array_assume_init)]
|
||||
#![feature(maybe_uninit_array_assume_init)]
|
||||
|
||||
use core::{
|
||||
marker::PhantomData,
|
||||
|
@ -1,4 +1,5 @@
|
||||
#![no_std]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
use core::{mem::MaybeUninit, time::Duration};
|
||||
|
||||
|
@ -123,7 +123,7 @@ impl<'a, T: Transport> CommandExecution<'a, T> {
|
||||
return Err(Error::InvalidArgument);
|
||||
}
|
||||
|
||||
let payload = unsafe { MaybeUninit::slice_assume_init_ref(&buffer[..len]) };
|
||||
let payload = unsafe { buffer[..len].assume_init_ref() };
|
||||
let header = bytemuck::from_bytes(&payload[..size_of::<ControlHeader>()]);
|
||||
let data = &payload[size_of::<ControlHeader>()..len];
|
||||
|
||||
|
@ -144,7 +144,7 @@ impl<T> PageBox<T, GlobalPhysicalAllocator> {
|
||||
T: Copy,
|
||||
{
|
||||
let mut uninit = Self::new_uninit_slice(slice.len())?;
|
||||
MaybeUninit::copy_from_slice(&mut uninit[..], slice);
|
||||
uninit[..].write_copy_of_slice(slice);
|
||||
Ok(unsafe { uninit.assume_init_slice() })
|
||||
}
|
||||
}
|
||||
@ -357,7 +357,7 @@ impl<T, A: PhysicalMemoryAllocator<Address = PhysicalAddress>> PageBox<[MaybeUni
|
||||
// 1. MaybeUninit<T> is transparent
|
||||
// 2. self.value still points to the same memory and is not deallocated
|
||||
let page_count = self.page_count;
|
||||
let value = MaybeUninit::slice_assume_init_mut(&mut *self.value);
|
||||
let value = (&mut *self.value).assume_init_mut();
|
||||
|
||||
core::mem::forget(self);
|
||||
|
||||
@ -374,7 +374,7 @@ impl<T, A: PhysicalMemoryAllocator<Address = PhysicalAddress>> PageBox<[MaybeUni
|
||||
///
|
||||
/// See [MaybeUninit::slice_assume_init_ref]
|
||||
pub unsafe fn assume_init_slice_ref(&self) -> &[T] {
|
||||
MaybeUninit::slice_assume_init_ref(self.deref())
|
||||
(&*self.value).assume_init_ref()
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the slice data with [MaybeUninit] removed.
|
||||
@ -383,7 +383,7 @@ impl<T, A: PhysicalMemoryAllocator<Address = PhysicalAddress>> PageBox<[MaybeUni
|
||||
///
|
||||
/// See [MaybeUninit::slice_assume_init_mut]
|
||||
pub unsafe fn assume_init_slice_mut(&mut self) -> &mut [T] {
|
||||
MaybeUninit::slice_assume_init_mut(self.deref_mut())
|
||||
(&mut *self.value).assume_init_mut()
|
||||
}
|
||||
|
||||
/// Fills a slice of MaybeUninit<T> with zeroes.
|
||||
|
@ -144,13 +144,13 @@ impl<T, const N: usize> Deref for StaticVector<T, N> {
|
||||
type Target = [T];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
unsafe { MaybeUninit::slice_assume_init_ref(&self.data[..self.len]) }
|
||||
unsafe { self.data[..self.len].assume_init_ref() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, const N: usize> DerefMut for StaticVector<T, N> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
unsafe { MaybeUninit::slice_assume_init_mut(&mut self.data[..self.len]) }
|
||||
unsafe { self.data[..self.len].assume_init_mut() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
#![allow(clippy::missing_transmute_annotations)]
|
||||
use core::{
|
||||
mem::MaybeUninit,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
use core::ops::{Deref, DerefMut};
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use libk_util::{lru_hash_table::LruCache, sync::spin_rwlock::IrqSafeRwLock};
|
||||
@ -132,7 +129,7 @@ impl UncachedCache {
|
||||
self.device
|
||||
.read_aligned(pos, buffer.slice_mut(0..self.block_size))
|
||||
.await?;
|
||||
let result = mapper(unsafe { MaybeUninit::slice_assume_init_ref(&buffer[..]) })?;
|
||||
let result = mapper(unsafe { buffer[..].assume_init_ref() })?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
@ -121,11 +121,7 @@ pub trait BlockDevice: Device + PageProvider {
|
||||
let slice = read_buffer.slice_mut(0..block_count * bs);
|
||||
self.read_aligned(lba * bs as u64, slice).await?;
|
||||
|
||||
let src = unsafe {
|
||||
MaybeUninit::slice_assume_init_ref(
|
||||
&read_buffer[block_offset..block_offset + amount],
|
||||
)
|
||||
};
|
||||
let src = unsafe { read_buffer[block_offset..block_offset + amount].assume_init_ref() };
|
||||
let dst = &mut buffer[offset..offset + amount];
|
||||
|
||||
dst.copy_from_slice(src);
|
||||
|
@ -85,7 +85,7 @@ impl<T> DmaBuffer<T> {
|
||||
T: Copy,
|
||||
{
|
||||
let mut uninit = DmaBuffer::new_uninit_slice(allocator, source.len())?;
|
||||
MaybeUninit::copy_from_slice(&mut uninit[..], source);
|
||||
uninit[..].write_copy_of_slice(source);
|
||||
Ok(unsafe { DmaBuffer::assume_init_slice(uninit) })
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,10 @@ pub fn bus() -> Option<&'static Arc<KObject<()>>> {
|
||||
object::BUS_OBJECT.try_get()
|
||||
}
|
||||
|
||||
pub fn proc() -> Option<&'static Arc<KObject<()>>> {
|
||||
object::PROC_OBJECT.try_get()
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
ROOT.init(object::setup_fixed_objects());
|
||||
}
|
||||
|
@ -46,6 +46,11 @@ impl<D> KObject<D> {
|
||||
pub(super) fn data(&self) -> &D {
|
||||
&self.data
|
||||
}
|
||||
|
||||
pub fn unlink(&self) {
|
||||
let parent = self.node.parent();
|
||||
parent.unlink_child(&self.node).ok();
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> Deref for KObject<D> {
|
||||
@ -76,6 +81,8 @@ pub static DEVICE_OBJECT: OneTimeInit<Arc<KObject<()>>> = OneTimeInit::new();
|
||||
pub static DEBUG_OBJECT: OneTimeInit<Arc<KObject<()>>> = OneTimeInit::new();
|
||||
// `/bus`
|
||||
pub static BUS_OBJECT: OneTimeInit<Arc<KObject<()>>> = OneTimeInit::new();
|
||||
// `/proc`
|
||||
pub static PROC_OBJECT: OneTimeInit<Arc<KObject<()>>> = OneTimeInit::new();
|
||||
|
||||
fn setup_fixed_object(root: &Arc<KObject<()>>, obj: &OneTimeInit<Arc<KObject<()>>>, name: &str) {
|
||||
let obj = obj.init(KObject::new(()));
|
||||
@ -89,6 +96,7 @@ pub fn setup_fixed_objects() -> Arc<Node> {
|
||||
setup_fixed_object(root, &DEVICE_OBJECT, "device");
|
||||
setup_fixed_object(root, &DEBUG_OBJECT, "debug");
|
||||
setup_fixed_object(root, &BUS_OBJECT, "bus");
|
||||
setup_fixed_object(root, &PROC_OBJECT, "proc");
|
||||
|
||||
root.node.clone()
|
||||
}
|
||||
|
@ -13,10 +13,8 @@
|
||||
never_type,
|
||||
let_chains,
|
||||
allocator_api,
|
||||
maybe_uninit_uninit_array,
|
||||
trait_alias,
|
||||
if_let_guard,
|
||||
trait_upcasting,
|
||||
arbitrary_self_types,
|
||||
slice_split_once,
|
||||
arbitrary_self_types_pointers,
|
||||
|
@ -6,6 +6,7 @@ use core::{
|
||||
use abi_lib::SyscallRegister;
|
||||
use alloc::{
|
||||
collections::{btree_map, BTreeMap},
|
||||
format,
|
||||
string::String,
|
||||
sync::{Arc, Weak},
|
||||
vec::Vec,
|
||||
@ -32,6 +33,11 @@ use yggdrasil_abi::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
fs::sysfs::{
|
||||
self,
|
||||
attribute::{StringAttribute, StringAttributeOps},
|
||||
object::KObject,
|
||||
},
|
||||
task::{
|
||||
futex::UserspaceMutex, thread::Thread, types::AllocateProcessId, TaskContextImpl, ThreadId,
|
||||
},
|
||||
@ -89,6 +95,8 @@ pub struct Process {
|
||||
pub(crate) exit: OneTimeEvent<ExitCode>,
|
||||
pub(crate) child_exit_notify: BoolEvent,
|
||||
|
||||
sysfs_node: IrqSafeRwLock<Option<Arc<KObject<Weak<Process>>>>>,
|
||||
|
||||
/// Process I/O information
|
||||
pub io: IrqSafeSpinlock<ProcessIo>,
|
||||
}
|
||||
@ -123,9 +131,12 @@ impl Process {
|
||||
signal_entry: AtomicUsize::new(0),
|
||||
child_exit_notify: BoolEvent::new(),
|
||||
exit: OneTimeEvent::new(),
|
||||
sysfs_node: IrqSafeRwLock::new(None),
|
||||
io: IrqSafeSpinlock::new(ProcessIo::new()),
|
||||
});
|
||||
|
||||
*process.sysfs_node.write() = Some(add_sysfs_node(&process));
|
||||
|
||||
// Add a child if parent specified
|
||||
if let Some(parent) = parent {
|
||||
parent.inner.write().register_child(&process);
|
||||
@ -483,6 +494,7 @@ impl Process {
|
||||
|
||||
/// Cleans up process resources
|
||||
fn cleanup(&self, mut inner: IrqSafeRwLockWriteGuard<ProcessInner>) {
|
||||
self.remove_sysfs_node();
|
||||
self.io.lock().handle_exit();
|
||||
inner.threads.clear();
|
||||
if let Some(space) = inner.space.take() {
|
||||
@ -492,6 +504,12 @@ impl Process {
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_sysfs_node(&self) {
|
||||
if let Some(node) = self.sysfs_node.write().take() {
|
||||
node.unlink();
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the signal entry point
|
||||
pub fn set_signal_entry(&self, entry: usize) -> usize {
|
||||
self.signal_entry.swap(entry, Ordering::Release)
|
||||
@ -745,3 +763,44 @@ impl ProcessIo {
|
||||
self.ioctx = Some(ioctx);
|
||||
}
|
||||
}
|
||||
|
||||
fn add_sysfs_node(process: &Arc<Process>) -> Arc<KObject<Weak<Process>>> {
|
||||
struct Name;
|
||||
struct Parent;
|
||||
|
||||
impl StringAttributeOps for Name {
|
||||
type Data = Weak<Process>;
|
||||
const NAME: &'static str = "name";
|
||||
|
||||
fn read(state: &Self::Data) -> Result<String, Error> {
|
||||
let process = state.upgrade().ok_or(Error::ProcessNotFound)?;
|
||||
Ok(process.name.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl StringAttributeOps for Parent {
|
||||
type Data = Weak<Process>;
|
||||
const NAME: &'static str = "parent";
|
||||
|
||||
fn read(state: &Self::Data) -> Result<String, Error> {
|
||||
let process = state.upgrade().ok_or(Error::ProcessNotFound)?;
|
||||
if let Some(parent) = process.parent.as_ref().and_then(Weak::upgrade) {
|
||||
Ok(format!("{}", parent.id))
|
||||
} else {
|
||||
Ok("0".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let name = format!("{}", process.id);
|
||||
let process = Arc::downgrade(process);
|
||||
let object = KObject::new(process);
|
||||
|
||||
object.add_attribute(StringAttribute::from(Name)).ok();
|
||||
object.add_attribute(StringAttribute::from(Parent)).ok();
|
||||
|
||||
if let Some(proc) = sysfs::proc() {
|
||||
proc.add_object(name, object.clone()).ok();
|
||||
}
|
||||
object
|
||||
}
|
||||
|
@ -785,7 +785,7 @@ mod tests {
|
||||
|
||||
unsafe {
|
||||
assert_eq!(
|
||||
MaybeUninit::slice_assume_init_ref(&entries[..count]),
|
||||
entries[..count].assume_init_ref(),
|
||||
&[
|
||||
DirectoryEntry {
|
||||
name: FixedString::from_str("f1").unwrap(),
|
||||
@ -831,7 +831,7 @@ mod tests {
|
||||
assert_eq!(count, 3);
|
||||
unsafe {
|
||||
assert_eq!(
|
||||
MaybeUninit::slice_assume_init_ref(&entries[..count]),
|
||||
entries[..count].assume_init_ref(),
|
||||
&[
|
||||
DirectoryEntry {
|
||||
name: FixedString::from_str(".").unwrap(),
|
||||
|
@ -4,8 +4,6 @@ extern crate alloc;
|
||||
|
||||
pub mod pty;
|
||||
|
||||
pub(crate) mod asyncio;
|
||||
// pub(crate) mod channel;
|
||||
pub(crate) mod file;
|
||||
pub(crate) mod filesystem;
|
||||
pub(crate) mod ioctx;
|
||||
@ -19,8 +17,6 @@ pub(crate) mod terminal;
|
||||
pub(crate) mod timer;
|
||||
pub(crate) mod traits;
|
||||
|
||||
// pub use channel::{Channel, ChannelDescriptor, Subscription};
|
||||
// pub use device::CharDevice;
|
||||
pub use file::{DirectoryOpenPosition, File, FileRef, FileSet, InstanceData};
|
||||
pub use filesystem::{
|
||||
parse_mount_options, register_root, roots as filesystem_roots, Filesystem,
|
||||
|
@ -1,3 +1,4 @@
|
||||
use alloc::sync::Arc;
|
||||
use yggdrasil_abi::error::Error;
|
||||
|
||||
use crate::vfs::path::OwnedFilename;
|
||||
@ -43,4 +44,18 @@ impl Node {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn unlink_child(self: &NodeRef, child_node: &NodeRef) -> Result<(), Error> {
|
||||
let directory = self.as_directory()?;
|
||||
let mut children = directory.children.lock();
|
||||
|
||||
let parent = child_node.parent.replace(None);
|
||||
let Some(parent) = parent else {
|
||||
unreachable!("Tried to unlink node from no parent");
|
||||
};
|
||||
assert!(Arc::ptr_eq(&parent, self));
|
||||
children.retain(|(_, n)| !Arc::ptr_eq(n, child_node));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ impl InputBuffer {
|
||||
}
|
||||
|
||||
pub fn flush(&mut self) -> &[u8] {
|
||||
let data = unsafe { MaybeUninit::slice_assume_init_ref(&self.pending[..self.position]) };
|
||||
let data = unsafe { self.pending[..self.position].assume_init_ref() };
|
||||
self.position = 0;
|
||||
data
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
iter_collect_into,
|
||||
iter_next_chunk,
|
||||
exact_size_is_empty,
|
||||
maybe_uninit_uninit_array,
|
||||
never_type,
|
||||
format_args_nl,
|
||||
associated_type_defaults
|
||||
|
@ -9,7 +9,7 @@ macro_rules! primitive_enum {
|
||||
$([ $enum_extra:tt ]),* $(,)?
|
||||
) => {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[repr($repr)]
|
||||
// #[repr($repr)]
|
||||
$(#[$struct_meta])*
|
||||
$vis enum $name {
|
||||
$(
|
||||
|
@ -52,7 +52,7 @@ pub fn create_pipe_pair(
|
||||
read_nonblocking: bool,
|
||||
write_nonblocking: bool,
|
||||
) -> Result<(RawFd, RawFd), Error> {
|
||||
let mut fds = MaybeUninit::uninit_array();
|
||||
let mut fds = [MaybeUninit::uninit(); 2];
|
||||
unsafe { crate::sys::create_pipe(&mut fds) }?;
|
||||
let fds = unsafe { MaybeUninit::array_assume_init(fds) };
|
||||
let read = fds[0];
|
||||
|
@ -7,7 +7,6 @@
|
||||
naked_functions,
|
||||
thread_local,
|
||||
generic_const_exprs,
|
||||
maybe_uninit_uninit_array,
|
||||
maybe_uninit_array_assume_init
|
||||
)]
|
||||
#![no_std]
|
||||
|
@ -2,7 +2,7 @@
|
||||
"arch": "aarch64",
|
||||
"os": "none",
|
||||
"llvm-target": "aarch64-unknown-none",
|
||||
"data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
|
||||
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
|
||||
"max-atomic-width": 128,
|
||||
"target-pointer-width": "64",
|
||||
"features": "+v8a,+strict-align,+neon,+fp-armv8",
|
||||
|
@ -6,13 +6,16 @@ use core::{
|
||||
|
||||
use libyalloc::{allocator::BucketAllocator, sys::PageProvider};
|
||||
use yggdrasil_rt::{
|
||||
mem::{MappingFlags, MappingSource}, sync::mutex::Mutex, sys as syscall
|
||||
mem::{MappingFlags, MappingSource},
|
||||
sync::mutex::Mutex,
|
||||
sys as syscall,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::{EResult, OptionExt},
|
||||
headers::{
|
||||
errno::Errno, string::mem::{memcpy, memset}
|
||||
errno::Errno,
|
||||
string::mem::{memcpy, memset},
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -13,7 +13,8 @@ use crate::{
|
||||
allocator::{c_alloc, c_free},
|
||||
error::EResult,
|
||||
headers::{
|
||||
errno::Errno, string::{mem::memcpy, str::strlen}
|
||||
errno::Errno,
|
||||
string::{mem::memcpy, str::strlen},
|
||||
},
|
||||
thread,
|
||||
util::PointerExt,
|
||||
|
@ -116,7 +116,7 @@ impl<T> EResult<T> {
|
||||
pub fn map<U, F: FnOnce(T) -> U>(self, map: F) -> EResult<U> {
|
||||
match self {
|
||||
Self::Ok(value) => EResult::Ok(map(value)),
|
||||
Self::Err(err) => EResult::Err(err)
|
||||
Self::Err(err) => EResult::Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ impl<T, E> ResultExt<T, E> for Result<T, E> {
|
||||
fn e_map_err<F: FnOnce(E) -> Errno>(self, map: F) -> EResult<T> {
|
||||
match self {
|
||||
Ok(value) => EResult::Ok(value),
|
||||
Err(value) => EResult::Err(map(value))
|
||||
Err(value) => EResult::Err(map(value)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,7 +159,7 @@ impl<T> OptionExt<T> for Option<T> {
|
||||
fn e_ok_or(self, err: Errno) -> EResult<T> {
|
||||
match self {
|
||||
Some(value) => EResult::Ok(value),
|
||||
None => EResult::Err(err)
|
||||
None => EResult::Err(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn htonl(v: u32) -> u32 {
|
||||
v.to_be()
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -85,7 +85,7 @@ unsafe extern "C" fn newlocale(
|
||||
_base: locale_t,
|
||||
) -> locale_t {
|
||||
let locale = Box::new(__locale_struct {
|
||||
__locales: [null_mut(); __LC_LAST]
|
||||
__locales: [null_mut(); __LC_LAST],
|
||||
});
|
||||
|
||||
Box::into_raw(locale)
|
||||
|
@ -1,4 +1,7 @@
|
||||
use core::{ffi::c_int, net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}};
|
||||
use core::{
|
||||
ffi::c_int,
|
||||
net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::EResult,
|
||||
@ -102,11 +105,7 @@ impl sockaddr_in6 {
|
||||
}
|
||||
|
||||
impl SocketAddrExt<sockaddr_in> for SocketAddrV4 {
|
||||
fn to_c(
|
||||
&self,
|
||||
storage: *mut sockaddr_in,
|
||||
len: socklen_t,
|
||||
) -> EResult<socklen_t> {
|
||||
fn to_c(&self, storage: *mut sockaddr_in, len: socklen_t) -> EResult<socklen_t> {
|
||||
let storage = unsafe { storage.ensure_mut() };
|
||||
debug_assert!(len >= size_of::<sockaddr_in>());
|
||||
storage.sin_family = AF_INET as u16;
|
||||
|
@ -6,7 +6,11 @@ use core::{
|
||||
use crate::{
|
||||
error::{self, CIntZeroResult, CResult, OptionExt},
|
||||
headers::{
|
||||
errno::Errno, pthread::{PTHREAD_CREATE_JOINABLE, PTHREAD_INHERIT_SCHED, PTHREAD_SCOPE_PROCESS}, sched::{__ygg_sched_param_t, SCHED_RR}, sys_time::timespec, sys_types::pthread_attr_t
|
||||
errno::Errno,
|
||||
pthread::{PTHREAD_CREATE_JOINABLE, PTHREAD_INHERIT_SCHED, PTHREAD_SCOPE_PROCESS},
|
||||
sched::{__ygg_sched_param_t, SCHED_RR},
|
||||
sys_time::timespec,
|
||||
sys_types::pthread_attr_t,
|
||||
},
|
||||
thread,
|
||||
util::PointerExt,
|
||||
|
@ -6,7 +6,11 @@ use crate::{error::CIntZeroResult, headers::sys_types::pthread_once_t, util::Poi
|
||||
|
||||
impl pthread_once_t {
|
||||
fn once(&self, constructor: extern "C" fn()) {
|
||||
if self.__state.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed).is_err() {
|
||||
if self
|
||||
.__state
|
||||
.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
|
||||
.is_err()
|
||||
{
|
||||
return;
|
||||
}
|
||||
constructor();
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
// int pthread_spin_destroy(pthread_spinlock_t *);
|
||||
// int pthread_spin_init(pthread_spinlock_t *, int);
|
||||
// int pthread_spin_lock(pthread_spinlock_t *);
|
||||
|
@ -1,4 +1,7 @@
|
||||
use core::{ffi::{c_int, c_void}, ptr::NonNull};
|
||||
use core::{
|
||||
ffi::{c_int, c_void},
|
||||
ptr::NonNull,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::CIntZeroResult,
|
||||
|
@ -197,7 +197,11 @@ unsafe extern "C" fn asprintf(dst: *mut *mut c_char, fmt: *const c_char, mut arg
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn vasprintf(_dst: *mut *mut c_char, _fmt: *const c_char, _args: VaList) -> c_int {
|
||||
unsafe extern "C" fn vasprintf(
|
||||
_dst: *mut *mut c_char,
|
||||
_fmt: *const c_char,
|
||||
_args: VaList,
|
||||
) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
use crate::{error::EResult, io::{managed::FILE, Read}};
|
||||
use crate::{
|
||||
error::EResult,
|
||||
io::{managed::FILE, Read},
|
||||
};
|
||||
|
||||
pub trait GetChar {
|
||||
fn getc(&mut self) -> EResult<Option<u8>>;
|
||||
|
@ -4,21 +4,21 @@ use core::ffi::{c_int, c_long, c_longlong};
|
||||
#[repr(C)]
|
||||
pub struct div_t {
|
||||
pub quot: c_int,
|
||||
pub rem: c_int
|
||||
pub rem: c_int,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct ldiv_t {
|
||||
pub quot: c_long,
|
||||
pub rem: c_long
|
||||
pub rem: c_long,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct lldiv_t {
|
||||
pub quot: c_longlong,
|
||||
pub rem: c_longlong
|
||||
pub rem: c_longlong,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -40,7 +40,7 @@ unsafe extern "C" fn llabs(v: c_longlong) -> c_longlong {
|
||||
unsafe extern "C" fn div(x: c_int, y: c_int) -> div_t {
|
||||
div_t {
|
||||
quot: x / y,
|
||||
rem: x % y
|
||||
rem: x % y,
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ unsafe extern "C" fn div(x: c_int, y: c_int) -> div_t {
|
||||
unsafe extern "C" fn ldiv(x: c_long, y: c_long) -> ldiv_t {
|
||||
ldiv_t {
|
||||
quot: x / y,
|
||||
rem: x % y
|
||||
rem: x % y,
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,6 +56,6 @@ unsafe extern "C" fn ldiv(x: c_long, y: c_long) -> ldiv_t {
|
||||
unsafe extern "C" fn lldiv(x: c_longlong, y: c_longlong) -> lldiv_t {
|
||||
lldiv_t {
|
||||
quot: x / y,
|
||||
rem: x % y
|
||||
rem: x % y,
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,11 @@ use core::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
env, error::{CIntZeroResult, CPtrResult, CResult, OptionExt}, headers::errno::Errno, process, util::PointerStrExt
|
||||
env,
|
||||
error::{CIntZeroResult, CPtrResult, CResult, OptionExt},
|
||||
headers::errno::Errno,
|
||||
process,
|
||||
util::PointerStrExt,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1,6 +1,10 @@
|
||||
use core::ffi::{c_char, c_int};
|
||||
|
||||
use crate::{error::CResult, headers::wchar::{mbstate_t, multibyte::mbrtowc}, types::wchar_t};
|
||||
use crate::{
|
||||
error::CResult,
|
||||
headers::wchar::{mbstate_t, multibyte::mbrtowc},
|
||||
types::wchar_t,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn mblen(_s: *const c_char, _n: usize) -> c_int {
|
||||
|
@ -27,13 +27,13 @@ pub const RLIMIT_AS: c_int = 7;
|
||||
#[repr(C)]
|
||||
pub struct rlimit {
|
||||
pub rlim_cur: rlim_t,
|
||||
pub rlim_max: rlim_t
|
||||
pub rlim_max: rlim_t,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct rusage {
|
||||
pub ru_utime: __ygg_timeval_t,
|
||||
pub ru_stime: __ygg_timeval_t
|
||||
pub ru_stime: __ygg_timeval_t,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1,4 +1,7 @@
|
||||
use core::{ffi::{c_int, c_void}, net::SocketAddr};
|
||||
use core::{
|
||||
ffi::{c_int, c_void},
|
||||
net::SocketAddr,
|
||||
};
|
||||
|
||||
use crate::{error::EResult, headers::errno::Errno, util::PointerExt};
|
||||
|
||||
|
@ -1,9 +1,14 @@
|
||||
use core::{ffi::{c_char, c_int}, ptr::NonNull};
|
||||
use core::{
|
||||
ffi::{c_char, c_int},
|
||||
ptr::NonNull,
|
||||
};
|
||||
|
||||
use yggdrasil_rt::io::{FileAttr, FileMode, FileType, RawFd};
|
||||
|
||||
use crate::{
|
||||
error::{CIntZeroResult, TryFromExt}, io, util::{self, PointerStrExt}
|
||||
error::{CIntZeroResult, TryFromExt},
|
||||
io,
|
||||
util::{self, PointerStrExt},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -16,7 +16,7 @@ pub struct statvfs {
|
||||
|
||||
pub f_fsid: c_ulong,
|
||||
pub f_flag: c_ulong,
|
||||
pub f_namemax: c_ulong
|
||||
pub f_namemax: c_ulong,
|
||||
}
|
||||
|
||||
pub const ST_RDONLY: c_ulong = 1 << 0;
|
||||
|
@ -1,4 +1,7 @@
|
||||
use core::{ffi::{c_char, c_int, c_long, c_void}, time::Duration};
|
||||
use core::{
|
||||
ffi::{c_char, c_int, c_long, c_void},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use yggdrasil_abi::time::MICROSECONDS_IN_SECOND;
|
||||
|
||||
@ -22,7 +25,7 @@ pub struct timespec {
|
||||
#[repr(C)]
|
||||
pub struct itimerval {
|
||||
pub it_interval: timeval,
|
||||
pub it_value: timeval
|
||||
pub it_value: timeval,
|
||||
}
|
||||
|
||||
pub type __ygg_timeval_t = timeval;
|
||||
@ -43,7 +46,11 @@ unsafe extern "C" fn gettimeofday(_time: *mut timeval, _d: *mut c_void) -> c_int
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn setitimer(_timer: c_int, _new: *const itimerval, _old: *mut itimerval) -> c_int {
|
||||
unsafe extern "C" fn setitimer(
|
||||
_timer: c_int,
|
||||
_new: *const itimerval,
|
||||
_old: *mut itimerval,
|
||||
) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@ -56,7 +63,7 @@ impl timespec {
|
||||
pub const fn zero() -> Self {
|
||||
Self {
|
||||
tv_sec: time_t(0),
|
||||
tv_nsec: 0
|
||||
tv_nsec: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,7 +72,7 @@ impl timeval {
|
||||
pub const fn zero() -> Self {
|
||||
Self {
|
||||
tv_sec: time_t(0),
|
||||
tv_usec: 0
|
||||
tv_usec: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +80,8 @@ impl timeval {
|
||||
if self.tv_sec.0 == 0 && self.tv_usec == 0 {
|
||||
None
|
||||
} else {
|
||||
let seconds = (self.tv_sec.0 as u64).saturating_add(self.tv_usec / MICROSECONDS_IN_SECOND);
|
||||
let seconds =
|
||||
(self.tv_sec.0 as u64).saturating_add(self.tv_usec / MICROSECONDS_IN_SECOND);
|
||||
let nanoseconds = (self.tv_usec % MICROSECONDS_IN_SECOND) * 1000;
|
||||
Some(Duration::new(seconds, nanoseconds as u32))
|
||||
}
|
||||
@ -93,7 +101,7 @@ impl From<Duration> for __ygg_timespec_t {
|
||||
fn from(value: Duration) -> Self {
|
||||
Self {
|
||||
tv_sec: time_t(value.as_secs().try_into().unwrap()),
|
||||
tv_nsec: value.subsec_nanos().try_into().unwrap()
|
||||
tv_nsec: value.subsec_nanos().try_into().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,7 +110,7 @@ impl From<Duration> for timeval {
|
||||
fn from(value: Duration) -> Self {
|
||||
Self {
|
||||
tv_sec: time_t(value.as_secs().try_into().unwrap()),
|
||||
tv_usec: value.subsec_micros() as _
|
||||
tv_usec: value.subsec_micros() as _,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,8 @@
|
||||
use core::{ffi::{c_int, c_ulong, c_void}, ptr::NonNull, sync::atomic::{AtomicBool, AtomicU32}};
|
||||
use core::{
|
||||
ffi::{c_int, c_ulong, c_void},
|
||||
ptr::NonNull,
|
||||
sync::atomic::{AtomicBool, AtomicU32},
|
||||
};
|
||||
|
||||
#[cfg(any(target_pointer_width = "64", rust_analyzer))]
|
||||
mod bits64;
|
||||
@ -10,7 +14,6 @@ mod bits32;
|
||||
#[cfg(any(target_pointer_width = "32", rust_analyzer))]
|
||||
pub use bits32::*;
|
||||
|
||||
|
||||
pub type pid_t = i32;
|
||||
pub type uid_t = i32;
|
||||
pub type gid_t = i32;
|
||||
@ -73,7 +76,7 @@ pub type pthread_key_t = usize;
|
||||
pub struct pthread_mutex_t {
|
||||
pub(crate) __mode: c_int,
|
||||
pub(crate) __state: AtomicU32,
|
||||
pub(crate) __recursion: AtomicU32
|
||||
pub(crate) __recursion: AtomicU32,
|
||||
}
|
||||
#[repr(C)]
|
||||
pub struct pthread_mutexattr_t {
|
||||
@ -82,12 +85,12 @@ pub struct pthread_mutexattr_t {
|
||||
|
||||
#[repr(C)]
|
||||
pub struct pthread_once_t {
|
||||
pub(crate) __state: AtomicBool
|
||||
pub(crate) __state: AtomicBool,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct pthread_rwlock_t {
|
||||
__dummy: c_int
|
||||
__dummy: c_int,
|
||||
}
|
||||
pub struct pthread_rwlockattr_t {}
|
||||
|
||||
|
@ -1,8 +1,14 @@
|
||||
use core::{ffi::c_char, ptr::{null_mut, NonNull}};
|
||||
use core::{
|
||||
ffi::c_char,
|
||||
ptr::{null_mut, NonNull},
|
||||
};
|
||||
|
||||
use chrono::{Datelike, TimeZone, Timelike, Utc};
|
||||
|
||||
use crate::{headers::{locale::locale_t, sys_types::time_t}, util::CStringWriter};
|
||||
use crate::{
|
||||
headers::{locale::locale_t, sys_types::time_t},
|
||||
util::CStringWriter,
|
||||
};
|
||||
|
||||
use super::{get_timezone, tm, CDateTime};
|
||||
|
||||
@ -51,7 +57,7 @@ unsafe extern "C" fn asctime_r(timep: *const tm, buffer: *mut c_char) -> *mut c_
|
||||
// Utc, already accounts for timezone
|
||||
match fmt_time(timep, Utc, buffer) {
|
||||
Some(ptr) => ptr.as_ptr(),
|
||||
None => null_mut()
|
||||
None => null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +75,7 @@ unsafe extern "C" fn ctime_r(tp: *const time_t, buffer: *mut c_char) -> *mut c_c
|
||||
|
||||
match fmt_time(tp, tz, buffer) {
|
||||
Some(ptr) => ptr.as_ptr(),
|
||||
None => null_mut()
|
||||
None => null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,11 @@ unsafe extern "C" fn execp(file: *const c_char, argv: *const *mut c_char) -> c_i
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn execve(file: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int {
|
||||
unsafe extern "C" fn execve(
|
||||
file: *const c_char,
|
||||
argv: *const *mut c_char,
|
||||
envp: *const *mut c_char,
|
||||
) -> c_int {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,18 @@
|
||||
use core::{ffi::{c_char, c_int, c_void}, mem::MaybeUninit};
|
||||
use core::{
|
||||
ffi::{c_char, c_int, c_void},
|
||||
mem::MaybeUninit,
|
||||
};
|
||||
|
||||
use yggdrasil_rt::{io::{RawFd, SeekFrom}};
|
||||
use yggdrasil_rt::io::{RawFd, SeekFrom};
|
||||
|
||||
use crate::{
|
||||
error::{CFdResult, CIntZeroResult, CIsizeResult, COffsetResult, ResultExt, TryFromExt},
|
||||
headers::{errno::Errno, sys_types::{off_t, pid_t}},
|
||||
io::{self, raw::RawFile, IntoRawFd, Read, ReadAt, Seek, Write, WriteAt}, util::PointerExt,
|
||||
headers::{
|
||||
errno::Errno,
|
||||
sys_types::{off_t, pid_t},
|
||||
},
|
||||
io::{self, raw::RawFile, IntoRawFd, Read, ReadAt, Seek, Write, WriteAt},
|
||||
util::PointerExt,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1,4 +1,8 @@
|
||||
use core::{mem::MaybeUninit, ops::{Deref, DerefMut}, slice::memchr};
|
||||
use core::{
|
||||
mem::MaybeUninit,
|
||||
ops::{Deref, DerefMut},
|
||||
slice::memchr,
|
||||
};
|
||||
|
||||
use alloc::{boxed::Box, vec::Vec};
|
||||
|
||||
@ -10,13 +14,13 @@ use super::{Read, Write};
|
||||
|
||||
enum ReadBufferBacking<'a> {
|
||||
Owned(Box<[MaybeUninit<u8>]>),
|
||||
Borrowed(&'a mut [MaybeUninit<u8>])
|
||||
Borrowed(&'a mut [MaybeUninit<u8>]),
|
||||
}
|
||||
|
||||
pub struct ReadBuffer<'a> {
|
||||
data: ReadBufferBacking<'a>,
|
||||
position: usize,
|
||||
len: usize
|
||||
len: usize,
|
||||
}
|
||||
|
||||
// Write
|
||||
@ -26,17 +30,17 @@ pub trait FileWriter: Write {
|
||||
}
|
||||
|
||||
pub struct UnbufferedWriter<W: Write> {
|
||||
inner: W
|
||||
inner: W,
|
||||
}
|
||||
|
||||
pub struct FullBufferedWriter<W: Write> {
|
||||
inner: W,
|
||||
buffer: Vec<u8>
|
||||
buffer: Vec<u8>,
|
||||
}
|
||||
|
||||
pub struct LineBufferedWriter<W: Write> {
|
||||
inner: FullBufferedWriter<W>,
|
||||
need_flush: bool
|
||||
need_flush: bool,
|
||||
}
|
||||
|
||||
// Read impl
|
||||
@ -46,7 +50,7 @@ impl<'a> ReadBuffer<'a> {
|
||||
Self {
|
||||
data: ReadBufferBacking::Owned(Box::new_uninit_slice(capacity)),
|
||||
position: 0,
|
||||
len: 0
|
||||
len: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +58,7 @@ impl<'a> ReadBuffer<'a> {
|
||||
Self {
|
||||
data: ReadBufferBacking::Borrowed(data),
|
||||
position: 0,
|
||||
len: 0
|
||||
len: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +85,7 @@ impl<'a> ReadBuffer<'a> {
|
||||
|
||||
impl ReadBufferBacking<'_> {
|
||||
unsafe fn as_slice_mut(&mut self) -> &mut [u8] {
|
||||
MaybeUninit::slice_assume_init_mut(self.deref_mut())
|
||||
self.deref_mut().assume_init_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +95,7 @@ impl Deref for ReadBufferBacking<'_> {
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
Self::Owned(owned) => owned.deref(),
|
||||
Self::Borrowed(borrowed) => borrowed.deref()
|
||||
Self::Borrowed(borrowed) => borrowed.deref(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,7 +135,7 @@ impl<W: Write> FullBufferedWriter<W> {
|
||||
pub fn with_capacity(inner: W, capacity: usize) -> Self {
|
||||
Self {
|
||||
inner,
|
||||
buffer: Vec::with_capacity(capacity)
|
||||
buffer: Vec::with_capacity(capacity),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,7 +186,7 @@ impl<W: Write> LineBufferedWriter<W> {
|
||||
pub fn with_capacity(inner: W, capacity: usize) -> Self {
|
||||
Self {
|
||||
inner: FullBufferedWriter::with_capacity(inner, capacity),
|
||||
need_flush: false
|
||||
need_flush: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,9 +54,7 @@ impl DirReader {
|
||||
self.len = count;
|
||||
}
|
||||
|
||||
EResult::Ok(unsafe {
|
||||
MaybeUninit::slice_assume_init_ref(&self.buffer[self.position..self.len])
|
||||
})
|
||||
EResult::Ok(unsafe { self.buffer[self.position..self.len].assume_init_ref() })
|
||||
}
|
||||
|
||||
fn consume(&mut self, count: usize) {
|
||||
|
@ -18,7 +18,8 @@ use yggdrasil_rt::{
|
||||
use crate::{
|
||||
error::{EResult, TryFromExt},
|
||||
headers::{
|
||||
errno::Errno, stdio::{BUFSIZ, UNGETC_MAX, _IOFBF, _IOLBF, _IONBF}
|
||||
errno::Errno,
|
||||
stdio::{BUFSIZ, UNGETC_MAX, _IOFBF, _IOLBF, _IONBF},
|
||||
},
|
||||
};
|
||||
|
||||
@ -567,7 +568,9 @@ impl TryFromExt<c_int> for BufferingMode {
|
||||
|
||||
impl FileSet {
|
||||
const fn new() -> Self {
|
||||
Self { files: BTreeSet::new() }
|
||||
Self {
|
||||
files: BTreeSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn insert(&mut self, file: NonNull<FILE>) {
|
||||
|
@ -1,20 +1,24 @@
|
||||
use core::{ffi::c_int, mem::MaybeUninit};
|
||||
|
||||
use yggdrasil_rt::{
|
||||
io::{FileAttr, FileMode, RawFd, SeekFrom}, path::{Path, PathBuf}, sys as syscall
|
||||
io::{FileAttr, FileMode, RawFd, SeekFrom},
|
||||
path::{Path, PathBuf},
|
||||
sys as syscall,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::{EResult, TryFromExt},
|
||||
headers::{
|
||||
errno::Errno, stdio::{SEEK_CUR, SEEK_END, SEEK_SET}, sys_types::off_t
|
||||
errno::Errno,
|
||||
stdio::{SEEK_CUR, SEEK_END, SEEK_SET},
|
||||
sys_types::off_t,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod buffer;
|
||||
pub mod dir;
|
||||
pub mod managed;
|
||||
pub mod raw;
|
||||
pub mod dir;
|
||||
|
||||
pub trait ReadAt {
|
||||
fn read_at(&mut self, pos: u64, buffer: &mut [u8]) -> EResult<usize>;
|
||||
@ -155,11 +159,11 @@ pub fn realpath<P: AsRef<Path>>(path: P) -> EResult<PathBuf> {
|
||||
".." => {
|
||||
// Remove the last element
|
||||
buffer = buffer.split_right().0.into();
|
||||
},
|
||||
}
|
||||
"." | "" => (),
|
||||
name => {
|
||||
buffer.push(name);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
path = tail;
|
||||
|
@ -1,7 +1,6 @@
|
||||
#![feature(
|
||||
try_trait_v2,
|
||||
decl_macro,
|
||||
maybe_uninit_uninit_array,
|
||||
maybe_uninit_array_assume_init,
|
||||
c_variadic,
|
||||
arbitrary_self_types_pointers,
|
||||
@ -23,7 +22,7 @@
|
||||
clippy::identity_op,
|
||||
clippy::missing_safety_doc,
|
||||
clippy::missing_transmute_annotations,
|
||||
clippy::upper_case_acronyms,
|
||||
clippy::upper_case_acronyms
|
||||
)]
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
|
||||
@ -43,21 +42,21 @@ extern crate compiler_builtins;
|
||||
#[cfg(test)]
|
||||
extern crate std;
|
||||
|
||||
mod debug;
|
||||
mod allocator;
|
||||
mod cxxabi;
|
||||
mod debug;
|
||||
mod env;
|
||||
mod error;
|
||||
mod init;
|
||||
mod io;
|
||||
mod panic;
|
||||
mod process;
|
||||
mod random;
|
||||
mod signal;
|
||||
mod ssp;
|
||||
mod thread;
|
||||
mod types;
|
||||
mod util;
|
||||
mod random;
|
||||
|
||||
pub mod headers;
|
||||
|
||||
|
@ -1,11 +1,15 @@
|
||||
use core::{
|
||||
ffi::{c_char, c_int, c_void, CStr}, mem::MaybeUninit, time::Duration
|
||||
ffi::{c_char, c_int, c_void, CStr},
|
||||
mem::MaybeUninit,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use yggdrasil_rt::{
|
||||
process::{ExitCode, Signal}, sync::mutex::Mutex, sys as syscall
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
use yggdrasil_rt::{
|
||||
process::{ExitCode, Signal},
|
||||
sync::mutex::Mutex,
|
||||
sys as syscall,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
headers::sys_types::pid_t,
|
||||
@ -13,7 +17,7 @@ use crate::{
|
||||
};
|
||||
|
||||
struct DsoDestructor {
|
||||
f: extern "C" fn (*mut c_void),
|
||||
f: extern "C" fn(*mut c_void),
|
||||
arg: *mut c_void,
|
||||
}
|
||||
|
||||
@ -72,10 +76,7 @@ pub fn at_exit(f: extern "C" fn()) {
|
||||
|
||||
pub fn at_dso_exit(f: extern "C" fn(*mut c_void), arg: *mut c_void, _dso_handle: *mut c_void) {
|
||||
// TODO no support for dlopen/dlclose, so at_dso_exit == at_exit right now
|
||||
AT_DSO_EXIT.lock().push(DsoDestructor {
|
||||
f,
|
||||
arg
|
||||
});
|
||||
AT_DSO_EXIT.lock().push(DsoDestructor { f, arg });
|
||||
}
|
||||
|
||||
unsafe fn call_atexit() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use core::cell::RefCell;
|
||||
|
||||
struct RandomState {
|
||||
xs64: u64
|
||||
xs64: u64,
|
||||
}
|
||||
|
||||
impl RandomState {
|
||||
@ -20,9 +20,7 @@ impl RandomState {
|
||||
}
|
||||
|
||||
#[thread_local]
|
||||
static STATE: RefCell<RandomState> = RefCell::new(RandomState {
|
||||
xs64: 1234,
|
||||
});
|
||||
static STATE: RefCell<RandomState> = RefCell::new(RandomState { xs64: 1234 });
|
||||
|
||||
pub fn random_u64() -> u64 {
|
||||
STATE.borrow_mut().generate()
|
||||
|
Loading…
x
Reference in New Issue
Block a user