alnyan/yggdrasil: i686 relocations, TimerOptions

This commit is contained in:
2024-10-31 13:41:42 +02:00
parent 80a283a334
commit c81bf8ec22
6 changed files with 33 additions and 17 deletions
@@ -5,8 +5,7 @@ pub fn target() -> Target {
base.disable_redzone = true;
base.panic_strategy = PanicStrategy::Abort;
// TODO kernel support for FPU context switch in AArch64
base.features = "-fp-armv8,-neon,+strict-align,+v8a".into();
base.features = "+fp-armv8,+neon,+strict-align,+v8a".into();
base.plt_by_default = true;
Target {
@@ -1,6 +1,4 @@
use crate::spec::{PanicStrategy, RelocModel, Target};
const LINKER_SCRIPT: &str = include_str!("./i686_unknown_yggdrasil_linker_script.ld");
use crate::spec::{PanicStrategy, Target};
pub fn target() -> Target {
let mut base = crate::spec::base::yggdrasil::opts();
@@ -8,12 +6,7 @@ pub fn target() -> Target {
base.panic_strategy = PanicStrategy::Abort;
base.features = "+sse".into();
base.has_thread_local = false;
base.dynamic_linking = false;
base.link_script = Some(LINKER_SCRIPT.into());
base.position_independent_executables = false;
base.relocation_model = RelocModel::Static;
base.pre_link_args.clear();
base.plt_by_default = true;
Target {
llvm_target: "i686-unknown-none".into(),
+7
View File
@@ -28,6 +28,13 @@ impl PollChannel {
})
}
#[unstable(feature = "yggdrasil_os", issue = "none")]
pub fn remove(&mut self, fd: RawFd) -> io::Result<()> {
cvt_io(unsafe {
yggdrasil_rt::sys::poll_channel_control(self.0.as_raw_fd(), PollControl::RemoveFd, fd)
})
}
#[unstable(feature = "yggdrasil_os", issue = "none")]
pub fn wait(
&mut self,
+19 -3
View File
@@ -6,15 +6,22 @@ use crate::sys::cvt_io;
use crate::sys::fd::FileDesc;
use crate::time::Duration;
use yggdrasil_rt::sys as syscall;
use yggdrasil_rt::{io::TimerOptions, sys as syscall};
#[unstable(feature = "yggdrasil_os", issue = "none")]
pub struct TimerFd(FileDesc);
impl TimerFd {
#[unstable(feature = "yggdrasil_os", issue = "none")]
pub fn new(repeat: bool) -> io::Result<Self> {
let raw = cvt_io(unsafe { syscall::create_timer(repeat) })?;
pub fn new(repeat: bool, nonblocking: bool) -> io::Result<Self> {
let mut options = TimerOptions::empty();
if repeat {
options |= TimerOptions::REPEAT;
}
if nonblocking {
options |= TimerOptions::NON_BLOCKING;
}
let raw = cvt_io(unsafe { syscall::create_timer(options) })?;
let fd = unsafe { FileDesc::from_raw_fd(raw) };
Ok(Self(fd))
}
@@ -24,6 +31,15 @@ impl TimerFd {
cvt_io(unsafe { syscall::write(self.0.as_raw_fd(), &tval.to_ne_bytes()) })?;
Ok(())
}
pub fn is_expired(&mut self) -> io::Result<bool> {
let mut buf = [0; 1];
match cvt_io(unsafe { syscall::read(self.0.as_raw_fd(), &mut buf) }) {
Ok(_) => Ok(true),
Err(e) if e.kind() == io::ErrorKind::WouldBlock => Ok(false),
Err(e) => Err(e),
}
}
}
#[unstable(feature = "yggdrasil_os", issue = "none")]
@@ -34,7 +34,7 @@ struct DnsRequester {
impl DnsRequester {
pub fn new(nameserver: SocketAddr) -> io::Result<Self> {
let mut poll = PollChannel::new()?;
let timer = TimerFd::new(false)?;
let timer = TimerFd::new(false, false)?;
let socket = UdpSocket::bind("0.0.0.0:0")?;
poll.add(timer.as_raw_fd())?;
+3 -2
View File
@@ -3,6 +3,7 @@ use yggdrasil_rt::{process::ThreadSpawnOptions, sys as syscall};
use super::cvt_io;
use crate::ffi::CStr;
use crate::io;
use crate::mem::align_of;
use crate::num::NonZeroUsize;
use crate::time::Duration;
@@ -19,7 +20,7 @@ impl Thread {
let (stack_base, _, _) = Vec::into_raw_parts(stack);
let stack_top = stack_base.add(stack_size).addr();
let argument: Box<Box<dyn FnOnce()>> = Box::new(p);
let argument = Box::into_raw(argument).addr() as u64;
let argument = Box::into_raw(argument).addr();
// TODO pass stack_base to Self::entry for proper cleanup
let opts = ThreadSpawnOptions { argument, entry: Self::entry, stack_top };
@@ -47,7 +48,7 @@ impl Thread {
}
}
extern "C" fn entry(argument: u64) -> ! {
extern "C" fn entry(mut argument: usize) -> ! {
let argument: *mut Box<dyn FnOnce()> = crate::ptr::from_exposed_addr_mut(argument as usize);
let argument: Box<Box<dyn FnOnce()>> = unsafe { Box::from_raw(argument) };