Skip to content

Commit

Permalink
Merge branch 'main' into handle_negative_tid_in_thr_set_name
Browse files Browse the repository at this point in the history
  • Loading branch information
SuchAFuriousDeath authored Feb 23, 2024
2 parents 5d55551 + c84b2fa commit a858604
Show file tree
Hide file tree
Showing 31 changed files with 507 additions and 343 deletions.
3 changes: 1 addition & 2 deletions src/kernel/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ impl MachDep {
mach
}

fn sysarch(self: &Arc<Self>, i: &SysIn) -> Result<SysOut, SysErr> {
fn sysarch(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let op: u32 = i.args[0].try_into().unwrap();
let parms: *mut u8 = i.args[1].into();
let td = VThread::current().unwrap();
let mut pcb = td.pcb_mut();

if op < 2 {
Expand Down
12 changes: 3 additions & 9 deletions src/kernel/src/budget/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::errno::{ENOENT, ENOSYS, ESRCH};
use crate::idt::Idt;
use crate::idt::{Entry, Idt};
use crate::info;
use crate::process::VThread;
use crate::syscalls::{SysErr, SysIn, SysOut, Syscalls};
use std::convert::Infallible;
use std::sync::{Arc, Mutex};

/// An implementation of budget system on the PS4.
Expand All @@ -25,20 +24,15 @@ impl BudgetManager {
pub fn create(&self, budget: Budget) -> usize {
let name = budget.name.clone();
let mut budgets = self.budgets.lock().unwrap();
let (entry, id) = budgets
.alloc::<_, Infallible>(|_| Ok(Arc::new(budget)))
.unwrap();

entry.set_name(Some(name));
entry.set_ty(0x2000);
let id = budgets.alloc_infallible(|_| Entry::new(Some(name), Arc::new(budget), 0x2000));

id
}

fn sys_budget_get_ptype(self: &Arc<Self>, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_budget_get_ptype(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
// Check if PID is our process.
let pid: i32 = i.args[0].try_into().unwrap();
let td = VThread::current().unwrap();

info!("Getting budget process type for process {pid}.");

Expand Down
5 changes: 2 additions & 3 deletions src/kernel/src/dmem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ impl DmemManager {
dmem
}

fn sys_dmem_container(self: &Arc<Self>, i: &SysIn) -> Result<SysOut, SysErr> {
let td = VThread::current().unwrap();
fn sys_dmem_container(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let set: i32 = i.args[0].try_into().unwrap();
let get: i32 = td.proc().dmem_container().try_into().unwrap();

Expand All @@ -35,7 +34,7 @@ impl DmemManager {
Ok(get.into())
}

fn sys_blockpool_open(self: &Arc<Self>, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_blockpool_open(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
let flags: u32 = i.args[0].try_into().unwrap();

if flags & 0xffafffff != 0 {
Expand Down
8 changes: 6 additions & 2 deletions src/kernel/src/fs/dev/cdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,18 @@ pub(super) trait Device: Debug + Sync + Send + 'static {
#[allow(unused_variables)]
fn read(
self: Arc<Self>,
data: &mut [u8],
data: &mut UioMut,
td: Option<&VThread>,
) -> Result<usize, Box<dyn Errno>> {
Err(Box::new(DefaultError::ReadNotSupported))
}

#[allow(unused_variables)]
fn write(self: Arc<Self>, data: &[u8], td: Option<&VThread>) -> Result<usize, Box<dyn Errno>> {
fn write(
self: Arc<Self>,
data: &mut Uio,
td: Option<&VThread>,
) -> Result<usize, Box<dyn Errno>> {
Err(Box::new(DefaultError::WriteNotSupported))
}

Expand Down
10 changes: 6 additions & 4 deletions src/kernel/src/fs/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use self::dirent::Dirent;
use self::vnode::VnodeBackend;
use super::{
path_contains, DirentType, Filesystem, FsConfig, Mode, Mount, MountFlags, MountOpts,
MountSource, VPathBuf, Vnode, VnodeType,
MountSource, VPathBuf, Vnode, VnodeItem, VnodeType,
};
use crate::errno::{Errno, EEXIST, ENOENT, EOPNOTSUPP};
use crate::ucred::{Gid, Ucred, Uid};
Expand Down Expand Up @@ -105,7 +105,7 @@ fn alloc_vnode(
.ok_or(AllocVnodeError::DeviceGone)?;
let vn = Vnode::new(mnt, VnodeType::Character, tag, backend);

*vn.item_mut() = Some(dev);
*vn.item_mut() = Some(VnodeItem::Device(dev));
vn
}
DirentType::Directory => Vnode::new(
Expand Down Expand Up @@ -358,10 +358,12 @@ pub fn mount(
}

impl Filesystem for DevFs {
fn root(self: Arc<Self>, mnt: &Arc<Mount>) -> Arc<Vnode> {
fn root(self: Arc<Self>, mnt: &Arc<Mount>) -> Result<Arc<Vnode>, Box<dyn Errno>> {
let ent = self.root.clone();

alloc_vnode(self, mnt, ent).unwrap()
let vnode = alloc_vnode(self, mnt, ent)?;

Ok(vnode)
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/kernel/src/fs/dev/vnode.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::dirent::Dirent;
use super::{alloc_vnode, AllocVnodeError, Cdev, DevFs};
use super::{alloc_vnode, AllocVnodeError, DevFs};
use crate::errno::{Errno, EIO, ENOENT, ENOTDIR, ENXIO};
use crate::fs::{
check_access, Access, IoCmd, OpenFlags, RevokeFlags, VFile, Vnode, VnodeAttrs, VnodeType,
check_access, Access, IoCmd, OpenFlags, RevokeFlags, VFile, Vnode, VnodeAttrs, VnodeItem,
VnodeType,
};
use crate::process::VThread;
use macros::Errno;
Expand Down Expand Up @@ -175,7 +176,10 @@ impl crate::fs::VnodeBackend for VnodeBackend {
}

// Not sure why FreeBSD check if vnode is VBLK because all of vnode here always be VCHR.
let dev = vn.item().unwrap().downcast::<Cdev>().unwrap();
let item = vn.item();
let Some(VnodeItem::Device(dev)) = item.as_ref() else {
unreachable!();
};
let sw = dev.sw();

if file.is_none() && sw.fdopen().is_some() {
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub enum VFileType {

bitflags! {
/// Flags for [`VFile`].
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct VFileFlags: u32 {
const READ = 0x00000001; // FREAD
const WRITE = 0x00000002; // FWRITE
Expand Down
15 changes: 12 additions & 3 deletions src/kernel/src/fs/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use param::Param;
use std::collections::HashMap;
use std::fs::create_dir;
use std::io::ErrorKind;
use std::num::NonZeroI32;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Weak};
use thiserror::Error;
Expand Down Expand Up @@ -114,8 +115,10 @@ pub fn mount(
}

impl Filesystem for HostFs {
fn root(self: Arc<Self>, mnt: &Arc<Mount>) -> Arc<Vnode> {
get_vnode(&self, mnt, None).unwrap()
fn root(self: Arc<Self>, mnt: &Arc<Mount>) -> Result<Arc<Vnode>, Box<dyn Errno>> {
let vnode = get_vnode(&self, mnt, None)?;

Ok(vnode)
}
}

Expand Down Expand Up @@ -146,7 +149,7 @@ fn get_vnode(
// Get vnode type.
let ty = match file.is_directory() {
Ok(true) => VnodeType::Directory(path == fs.root),
Ok(false) => todo!(),
Ok(false) => VnodeType::File,
Err(e) => return Err(GetVnodeError::GetFileTypeFailed(e)),
};

Expand Down Expand Up @@ -182,3 +185,9 @@ enum GetVnodeError {
#[error("cannot determine file type")]
GetFileTypeFailed(#[source] std::io::Error),
}

impl Errno for GetVnodeError {
fn errno(&self) -> NonZeroI32 {
todo!()
}
}
Loading

0 comments on commit a858604

Please sign in to comment.