fix up io

This commit is contained in:
SArpnt 2024-10-27 02:18:27 -04:00
parent 94f9244c57
commit 4cda70cfc1
Signed by: SArpnt
SSH key fingerprint: SHA256:ILwik1t84eNKC17MXphK5x4eDEMNJlOQCX7SVILre+o
2 changed files with 18 additions and 18 deletions

4
Cargo.lock generated
View file

@ -22,9 +22,9 @@ dependencies = [
[[package]]
name = "libm"
version = "0.2.8"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
checksum = "3bda4c6077b0b08da2c48b172195795498381a7c8988c9e6212a6c55c5b9bd70"
[[package]]
name = "syscalls"

View file

@ -1,5 +1,4 @@
use syscalls::*;
use core::mem::MaybeUninit;
use core::ffi::*;
use core::ptr;
use core::arch::asm;
@ -45,10 +44,11 @@ pub fn exit(status: c_int) -> ! {
}
}
#[repr(C)]
// fields get used in asm, not sure why rust won't detect it
#[allow(dead_code)]
pub struct Timespec {
pub sec: u64, // time_t?
pub nanos: u64, // implementation defined?
pub sec: i64,
pub nanos: c_long,
}
/// time.nanos must be < 999_999_999
/// does not resume if interrupted by signal handler
@ -59,7 +59,6 @@ pub unsafe fn nanosleep(time: Timespec) {
}
pub unsafe fn handle_ctrlc(handler: extern "C" fn(c_int)) -> Result<(), ()> {
return Ok(()); // TODO
#[repr(C)]
pub struct Sigset {
#[cfg(target_pointer_width = "32")]
@ -69,24 +68,25 @@ pub unsafe fn handle_ctrlc(handler: extern "C" fn(c_int)) -> Result<(), ()> {
}
#[repr(C)]
struct Sigaction {
sa_sigaction: *const extern "C" fn(c_int),
sa_mask: Sigset,
sa_flags: c_int,
sa_restorer: Option<extern "C" fn()>,
sigaction: *const extern "C" fn(c_int),
mask: Sigset,
flags: c_int,
restorer: Option<extern "C" fn()>,
}
match unsafe {
let mut sa_mask = MaybeUninit::<Sigset>::uninit();
//libc::sigemptyset(sa_mask.as_mut_ptr());
// mask is horribly documented. glibc zeroes it and i'm just going to assume that's fine.
let mask = core::mem::zeroed::<Sigset>();
raw_syscall!(
Sysno::rt_sigaction,
2,
&Sigaction {
sa_sigaction: handler as *const _,
sa_mask: sa_mask.assume_init(),
sa_flags: 0x10000000, // SA_RESTART
sa_restorer: None,
sigaction: handler as *const _,
mask,
flags: 0x10000000, // SA_RESTART
restorer: None,
} as *const _,
ptr::null_mut::<Sigaction>()
ptr::null_mut::<Sigaction>(),
core::mem::size_of::<Sigset>() // TODO is this correct?
)
} {
0 => Ok(()),