Skip to content

Commit

Permalink
Merge branch 'main' into sys-593
Browse files Browse the repository at this point in the history
  • Loading branch information
SuchAFuriousDeath authored Feb 24, 2024
2 parents 1055b86 + c2c9ac2 commit 2c8b500
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/kernel/src/fs/tmp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl Filesystem for TempFs {
}
}

#[allow(unused_variables)] // TODO: remove when implementing
fn alloc_vnode(mnt: &Arc<Mount>, node: &Arc<Node>) -> Result<Arc<Vnode>, AllocVnodeError> {
todo!()
}
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ impl MemoryManager {
Err(SysErr::Raw(EOPNOTSUPP))
}

fn sys_mmap(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_mmap(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
// Get arguments.
let addr: usize = i.args[0].into();
let len: usize = i.args[1].into();
Expand Down Expand Up @@ -594,7 +594,7 @@ impl MemoryManager {
Ok(pages.into_raw().into())
}

fn sys_mname(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_mname(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let addr: usize = i.args[0].into();
let len: usize = i.args[1].into();
let name = unsafe { i.args[2].to_str(32)?.unwrap() };
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/namedobj/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl NamedObjManager {
namedobj
}

fn sys_namedobj_create(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_namedobj_create(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
// Get arguments.
let name = unsafe { i.args[0].to_str(32) }?.ok_or(SysErr::Raw(EINVAL))?;
let data: usize = i.args[1].into();
Expand Down
2 changes: 2 additions & 0 deletions src/kernel/src/net/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ impl Socket {
}

/// See `sosend` on the PS4 for a reference.
#[allow(unused_variables)] // TODO: remove when implementing
fn send(&self, buf: &mut Uio, td: Option<&VThread>) -> Result<usize, SendError> {
todo!()
}

/// See `soreceive` on the PS4 for a reference.
#[allow(unused_variables)] // TODO: remove when implementing
fn receive(&self, buf: &mut UioMut, td: Option<&VThread>) -> Result<usize, ReceiveError> {
todo!()
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/osem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl OsemManager {
osem
}

fn sys_osem_create(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_osem_create(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let name = unsafe { i.args[0].to_str(32) }?.unwrap();
let flags = {
let flags = i.args[1].try_into().unwrap();
Expand Down
51 changes: 49 additions & 2 deletions src/kernel/src/process/cpuset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub const CPU_LEVEL_WHICH: i32 = 3;
pub const CPU_WHICH_TID: i32 = 1;
use crate::{errno::EINVAL, syscalls::SysErr};

/// An implementation of `cpuset`.
#[derive(Debug)]
Expand All @@ -23,3 +22,51 @@ impl CpuSet {
pub struct CpuMask {
pub bits: [u64; 1],
}

/// An implementation of `cpulevel_t`.
#[derive(Debug, Clone, Copy)]
#[repr(i32)]
pub(super) enum CpuLevel {
Root = 1,
Cpuset = 2,
Which = 3,
}

impl TryFrom<i32> for CpuLevel {
type Error = SysErr;

fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
1 => Ok(Self::Root),
2 => Ok(Self::Cpuset),
3 => Ok(Self::Which),
_ => Err(SysErr::Raw(EINVAL)),
}
}
}

/// An implementation of `cpuwhich_t`.
#[derive(Debug, Clone, Copy)]
#[repr(i32)]
pub(super) enum CpuWhich {
Tid = 1,
Pid = 2,
Cpuset = 3,
Irq = 4,
Jail = 5,
}

impl TryFrom<i32> for CpuWhich {
type Error = SysErr;

fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
1 => Ok(Self::Tid),
2 => Ok(Self::Pid),
3 => Ok(Self::Cpuset),
4 => Ok(Self::Irq),
5 => Ok(Self::Jail),
_ => Err(SysErr::Raw(EINVAL)),
}
}
}
72 changes: 45 additions & 27 deletions src/kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub struct VProc {
app_info: AppInfo,
ptc: u64,
uptc: AtomicPtr<u8>,
gg: Arc<GutexGroup>,
}

impl VProc {
Expand Down Expand Up @@ -104,7 +103,6 @@ impl VProc {
app_info: AppInfo::new(),
ptc: 0,
uptc: AtomicPtr::new(null_mut()),
gg,
});

sys.register(20, &vp, Self::sys_getpid);
Expand All @@ -116,6 +114,7 @@ impl VProc {
sys.register(464, &vp, Self::sys_thr_set_name);
sys.register(466, &vp, Self::sys_rtprio_thread);
sys.register(487, &vp, Self::sys_cpuset_getaffinity);
sys.register(488, &vp, Self::sys_cpuset_setaffinity);
sys.register(585, &vp, Self::sys_is_in_sandbox);
sys.register(587, &vp, Self::sys_get_authinfo);
sys.register(602, &vp, Self::sys_randomized_path);
Expand Down Expand Up @@ -171,10 +170,6 @@ impl VProc {
&self.uptc
}

pub fn gutex_group(&self) -> &Arc<GutexGroup> {
&self.gg
}

fn sys_getpid(self: &Arc<Self>, _: &VThread, _: &SysIn) -> Result<SysOut, SysErr> {
Ok(self.id.into())
}
Expand Down Expand Up @@ -284,7 +279,7 @@ impl VProc {
Ok(SysOut::ZERO)
}

fn sys_sigaction(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_sigaction(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
// Get arguments.
let sig: i32 = i.args[0].try_into().unwrap();
let act: *const SignalAct = i.args[1].into();
Expand Down Expand Up @@ -419,8 +414,8 @@ impl VProc {
Ok(SysOut::ZERO)
}

fn sys_thr_set_name(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let tid: i64 = i.args[0].into();
fn sys_thr_set_name(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let tid: i64 = i.args[0].try_into().unwrap();
let name: Option<&str> = unsafe { i.args[1].to_str(32) }?;

if tid == -1 {
Expand Down Expand Up @@ -478,10 +473,10 @@ impl VProc {
Ok(SysOut::ZERO)
}

fn sys_cpuset_getaffinity(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_cpuset_getaffinity(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
// Get arguments.
let level: i32 = i.args[0].try_into().unwrap();
let which: i32 = i.args[1].try_into().unwrap();
let level: CpuLevel = TryInto::<i32>::try_into(i.args[0]).unwrap().try_into()?;
let which: CpuWhich = TryInto::<i32>::try_into(i.args[1]).unwrap().try_into()?;
let id: i64 = i.args[2].into();
let cpusetsize: usize = i.args[3].into();
let mask: *mut u8 = i.args[4].into();
Expand All @@ -491,18 +486,18 @@ impl VProc {
return Err(SysErr::Raw(ERANGE));
}

let ttd = self.cpuset_which(which, id)?;
let td = self.cpuset_which(which, id)?;
let mut buf = vec![0u8; cpusetsize];

match level {
CPU_LEVEL_WHICH => match which {
CPU_WHICH_TID => {
let v = ttd.cpuset().mask().bits[0].to_ne_bytes();
CpuLevel::Which => match which {
CpuWhich::Tid => {
let v = td.cpuset().mask().bits[0].to_ne_bytes();
buf[..v.len()].copy_from_slice(&v);
}
v => todo!("sys_cpuset_getaffinity with which = {v}"),
v => todo!("sys_cpuset_getaffinity with which = {v:?}"),
},
v => todo!("sys_cpuset_getaffinity with level = {v}"),
v => todo!("sys_cpuset_getaffinity with level = {v:?}"),
}

// TODO: What is this?
Expand All @@ -522,24 +517,47 @@ impl VProc {
Ok(SysOut::ZERO)
}

fn sys_cpuset_setaffinity(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let level: CpuLevel = TryInto::<i32>::try_into(i.args[0]).unwrap().try_into()?;
let which: CpuWhich = TryInto::<i32>::try_into(i.args[1]).unwrap().try_into()?;
let _id: i64 = i.args[2].into();
let cpusetsize: usize = i.args[3].into();
let _mask: *const u8 = i.args[4].into();

// TODO: Refactor this for readability.
if cpusetsize.wrapping_sub(8) > 8 {
return Err(SysErr::Raw(ERANGE));
}

match level {
CpuLevel::Which => match which {
CpuWhich::Tid => {
todo!();
}
v => todo!("sys_cpuset_setaffinity with which = {v:?}"),
},
v => todo!("sys_cpuset_setaffinity with level = {v:?}"),
}
}

/// See `cpuset_which` on the PS4 for a reference.
fn cpuset_which(&self, which: i32, id: i64) -> Result<Arc<VThread>, SysErr> {
fn cpuset_which(&self, which: CpuWhich, id: i64) -> Result<Arc<VThread>, SysErr> {
let td = match which {
CPU_WHICH_TID => {
CpuWhich::Tid => {
if id == -1 {
todo!("cpuset_which with id = -1");
} else {
let threads = self.threads.read();
let td = threads.iter().find(|t| t.id().get() == id as i32).cloned();

if td.is_none() {
return Err(SysErr::Raw(ESRCH));
}
let td = threads
.iter()
.find(|t| t.id().get() == id as i32)
.ok_or(SysErr::Raw(ESRCH))?
.clone();

td
Some(td)
}
}
v => todo!("cpuset_which with which = {v}"),
v => todo!("cpuset_which with which = {v:?}"),
};

match td {
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/src/rtld/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl<E: ExecutionEngine> RuntimeLinker<E> {
Ok(SysOut::ZERO)
}

fn sys_dynlib_get_list(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_dynlib_get_list(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
// Get arguments.
let buf: *mut u32 = i.args[0].into();
let max: usize = i.args[1].into();
Expand Down Expand Up @@ -656,7 +656,7 @@ impl<E: ExecutionEngine> RuntimeLinker<E> {

fn sys_dynlib_process_needed_and_relocate(
self: &Arc<Self>,
td: &VThread,
_: &VThread,
_: &SysIn,
) -> Result<SysOut, SysErr> {
// Check if application is dynamic linking.
Expand Down

0 comments on commit 2c8b500

Please sign in to comment.