Skip to content

Commit ac981e0

Browse files
committed
Moves EINTR and EIO to Kernel
1 parent dd2974f commit ac981e0

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

kernel-1100/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use self::thread::Thread;
1010
use self::ucred::Ucred;
1111
use self::uio::Uio;
1212
use core::ffi::{c_char, c_int};
13+
use core::num::NonZero;
1314
use okf::fd::OpenFlags;
1415
use okf::malloc::MallocFlags;
1516
use okf::queue::TailQueue;
@@ -34,6 +35,8 @@ pub struct Kernel(*const u8);
3435
impl okf::Kernel for Kernel {
3536
#[offset(0x221CCF8)]
3637
const ACCEPT_MTX: StaticMut<Self::Mtx>;
38+
const EINTR: NonZero<c_int> = unsafe { NonZero::new_unchecked(4) };
39+
const EIO: NonZero<c_int> = unsafe { NonZero::new_unchecked(5) };
3740
#[offset(0x15415B0)]
3841
const M_TEMP: StaticMut<Self::Malloc>;
3942
const MBF_MNTLSTLOCK: c_int = 2;

src/errno/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use core::ffi::c_int;
22
use core::num::NonZero;
33

4-
pub const EINTR: Errno = unsafe { Errno(NonZero::new_unchecked(4)) };
5-
pub const EIO: Errno = unsafe { Errno(NonZero::new_unchecked(5)) };
6-
74
/// Encapsulates an errno value.
85
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
96
pub struct Errno(NonZero<c_int>);

src/fd/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use crate::errno::{Errno, EINTR, EIO};
1+
use crate::errno::Errno;
22
use crate::pcpu::Pcpu;
33
use crate::thread::Thread;
44
use crate::uio::{IoVec, Uio, UioRw, UioSeg};
55
use crate::Kernel;
66
use bitflags::bitflags;
77
use core::ffi::{c_char, c_int};
88
use core::marker::PhantomData;
9+
use core::num::NonZero;
910

1011
pub const AT_FDCWD: c_int = -100;
1112

@@ -42,16 +43,16 @@ pub unsafe fn write_all<K: Kernel>(
4243
mut data: &[u8],
4344
seg: UioSeg,
4445
td: *mut K::Thread,
45-
) -> Result<(), Errno> {
46+
) -> Result<(), NonZero<c_int>> {
4647
while !data.is_empty() {
4748
let written = match write(kern, fd, data, seg, td) {
4849
Ok(v) => v,
49-
Err(EINTR) => continue,
50+
Err(e) if e == K::EINTR => continue,
5051
Err(e) => return Err(e),
5152
};
5253

5354
if written == 0 {
54-
return Err(EIO);
55+
return Err(K::EIO);
5556
}
5657

5758
data = &data[written..];
@@ -69,7 +70,7 @@ pub unsafe fn write<K: Kernel>(
6970
data: &[u8],
7071
seg: UioSeg,
7172
td: *mut K::Thread,
72-
) -> Result<usize, Errno> {
73+
) -> Result<usize, NonZero<c_int>> {
7374
// Setup iovec.
7475
let mut vec = IoVec {
7576
ptr: data.as_ptr().cast_mut(),
@@ -80,7 +81,7 @@ pub unsafe fn write<K: Kernel>(
8081
let mut uio = K::Uio::new(td, UioRw::Write, seg, &mut vec, 1).unwrap();
8182
let errno = kern.kern_writev(td, fd, &mut uio);
8283

83-
match Errno::new(errno) {
84+
match NonZero::new(errno) {
8485
Some(v) => Err(v),
8586
None => Ok((*td).ret(0)),
8687
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use self::uio::{Uio, UioSeg};
1414
use core::alloc::{GlobalAlloc, Layout};
1515
use core::ffi::{c_char, c_int};
1616
use core::marker::PhantomData;
17+
use core::num::NonZero;
1718
use core::ops::Deref;
1819
use core::ptr::{null_mut, read_unaligned, write_unaligned};
1920
pub use okf_macros::*;
@@ -45,6 +46,8 @@ macro_rules! kernel {
4546
/// Some modules may provide high-level wrappers that are easy to use.
4647
pub trait Kernel: MappedKernel {
4748
const ACCEPT_MTX: StaticMut<Self::Mtx>;
49+
const EINTR: NonZero<c_int>;
50+
const EIO: NonZero<c_int>;
4851
const M_TEMP: StaticMut<Self::Malloc>;
4952
const MBF_MNTLSTLOCK: c_int;
5053
const MBF_NOWAIT: c_int;

0 commit comments

Comments
 (0)