Skip to content

Commit

Permalink
Changes td type on syscall handler (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Jun 2, 2024
1 parent ff6715a commit 9688b75
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/kernel/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl MachDep {
mach
}

fn sysarch(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sysarch(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let op: u32 = i.args[0].try_into().unwrap();
let parms: *mut u8 = i.args[1].into();
let mut pcb = td.pcb_mut();
Expand Down
6 changes: 5 additions & 1 deletion src/kernel/src/budget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ impl BudgetManager {
budgets.alloc(Entry::new(Some(name), Arc::new(budget), 0x2000))
}

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

Expand Down
32 changes: 26 additions & 6 deletions src/kernel/src/dmem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ impl DmemManager {
Ok(dmem)
}

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

let dmem_container = td.proc().dmem_container_mut();
Expand All @@ -126,7 +130,11 @@ impl DmemManager {
Ok(current_container.into())
}

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

if flags & 0xffafffff != 0 {
Expand All @@ -145,7 +153,7 @@ impl DmemManager {
Ok(fd.into())
}

fn sys_blockpool_map(self: &Arc<Self>, _: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_blockpool_map(self: &Arc<Self>, _: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let addr: usize = i.args[0].into();
let len: usize = i.args[1].into();
let mem_type: i32 = i.args[2].try_into().unwrap();
Expand All @@ -160,15 +168,27 @@ impl DmemManager {
todo!()
}

fn sys_blockpool_unmap(self: &Arc<Self>, _: &VThread, _i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_blockpool_unmap(
self: &Arc<Self>,
_: &Arc<VThread>,
_i: &SysIn,
) -> Result<SysOut, SysErr> {
todo!()
}

fn sys_blockpool_batch(self: &Arc<Self>, _: &VThread, _i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_blockpool_batch(
self: &Arc<Self>,
_: &Arc<VThread>,
_i: &SysIn,
) -> Result<SysOut, SysErr> {
todo!()
}

fn sys_blockpool_move(self: &Arc<Self>, _: &VThread, _i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_blockpool_move(
self: &Arc<Self>,
_: &Arc<VThread>,
_i: &SysIn,
) -> Result<SysOut, SysErr> {
todo!()
}
}
Expand Down
44 changes: 22 additions & 22 deletions src/kernel/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl Fs {
}
}

fn sys_read(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_read(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
let ptr: *mut u8 = i.args[1].into();
let len: IoLen = i.args[2].try_into()?;
Expand All @@ -375,7 +375,7 @@ impl Fs {
todo!("sys_read")
}

fn sys_write(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_write(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
let ptr: *const u8 = i.args[1].into();
let len: IoLen = i.args[2].try_into()?;
Expand All @@ -385,7 +385,7 @@ impl Fs {
todo!("sys_write")
}

fn sys_open(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_open(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
// Get arguments.
let path = unsafe { i.args[0].to_path()?.unwrap() };
let flags: OpenFlags = i.args[1].try_into().unwrap();
Expand Down Expand Up @@ -428,7 +428,7 @@ impl Fs {
Ok(fd.into())
}

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

info!("Closing fd {fd}.");
Expand All @@ -438,7 +438,7 @@ impl Fs {
Ok(SysOut::ZERO)
}

fn sys_ioctl(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_ioctl(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
// Our IoCmd contains both the command and the argument (if there is one).
let cmd = IoCmd::try_from_raw_parts(i.args[1].into(), i.args[2].into())?;
Expand Down Expand Up @@ -474,7 +474,7 @@ impl Fs {
Ok(SysOut::ZERO)
}

fn sys_revoke(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_revoke(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let path = unsafe { i.args[0].to_path()?.unwrap() };

info!("Revoking access to {path}.");
Expand Down Expand Up @@ -511,7 +511,7 @@ impl Fs {
Ok(())
}

fn sys_readv(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_readv(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
let iovec: *mut IoVec = i.args[1].into();
let count: u32 = i.args[2].try_into().unwrap();
Expand All @@ -523,7 +523,7 @@ impl Fs {
todo!()
}

fn sys_writev(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_writev(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
let iovec: *const IoVec = i.args[1].into();
let iovcnt: u32 = i.args[2].try_into().unwrap();
Expand All @@ -537,7 +537,7 @@ impl Fs {
todo!()
}

fn sys_stat(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_stat(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let path = unsafe { i.args[0].to_path() }?.unwrap();
let stat_out: *mut Stat = i.args[1].into();

Expand All @@ -555,7 +555,7 @@ impl Fs {
self.statat(AtFlags::empty(), At::Cwd, path, td)
}

fn sys_fstat(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_fstat(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
let stat_out: *mut Stat = i.args[1].into();

Expand All @@ -577,7 +577,7 @@ impl Fs {
Ok(stat)
}

fn sys_lstat(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_lstat(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let path = unsafe { i.args[0].to_path() }?.unwrap();
let stat_out: *mut Stat = i.args[1].into();

Expand All @@ -597,7 +597,7 @@ impl Fs {
self.statat(AtFlags::SYMLINK_NOFOLLOW, At::Cwd, path, td)
}

fn sys_pread(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_pread(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
let ptr: *mut u8 = i.args[1].into();
let len: IoLen = i.args[2].try_into()?;
Expand All @@ -611,7 +611,7 @@ impl Fs {
Ok(read.into())
}

fn sys_pwrite(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_pwrite(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
let ptr: *const u8 = i.args[1].into();
let len: IoLen = i.args[2].try_into()?;
Expand All @@ -625,7 +625,7 @@ impl Fs {
Ok(written.into())
}

fn sys_preadv(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_preadv(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
// Get arguments.
let fd: i32 = i.args[0].try_into().unwrap();
let iovec: *mut IoVecMut = i.args[1].into();
Expand Down Expand Up @@ -680,7 +680,7 @@ impl Fs {
todo!()
}

fn sys_pwritev(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_pwritev(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
// Get arguments.
let fd: i32 = i.args[0].try_into().unwrap();
let iovec: *const IoVec = i.args[1].into();
Expand Down Expand Up @@ -729,7 +729,7 @@ impl Fs {
todo!()
}

fn sys_fstatat(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_fstatat(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let dirfd: i32 = i.args[0].try_into().unwrap();
let path = unsafe { i.args[1].to_path() }?.unwrap();
let stat_out: *mut Stat = i.args[2].into();
Expand Down Expand Up @@ -759,15 +759,15 @@ impl Fs {
todo!()
}

fn sys_mkdir(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_mkdir(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let path = unsafe { i.args[0].to_path() }?.unwrap();
let mode: u32 = i.args[1].try_into().unwrap();

self.mkdirat(At::Cwd, path, mode, Some(td))
}

#[allow(unused_variables)]
fn sys_poll(self: &Arc<Self>, _td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_poll(self: &Arc<Self>, _td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fds: *mut PollFd = i.args[0].into();
let nfds: u32 = i.args[1].try_into().unwrap();
let timeout: i32 = i.args[2].try_into().unwrap();
Expand All @@ -779,7 +779,7 @@ impl Fs {
todo!()
}

fn sys_lseek(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_lseek(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd: i32 = i.args[0].try_into().unwrap();
let mut offset: i64 = i.args[1].into();
let whence: Whence = {
Expand Down Expand Up @@ -817,7 +817,7 @@ impl Fs {
todo!()
}

fn sys_truncate(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_truncate(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let path = unsafe { i.args[0].to_path() }?.unwrap();
let length = i.args[1].into();

Expand All @@ -836,7 +836,7 @@ impl Fs {
todo!()
}

fn sys_ftruncate(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_ftruncate(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
let fd = i.args[0].try_into().unwrap();
let length = i.args[1].into();

Expand All @@ -859,7 +859,7 @@ impl Fs {
Ok(())
}

fn sys_mkdirat(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_mkdirat(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
td.priv_check(Privilege::SCE683)?;

let fd: i32 = i.args[0].try_into().unwrap();
Expand Down
16 changes: 8 additions & 8 deletions src/kernel/src/ipmi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::{
info,
process::VThread,
syscalls::{SysErr, SysIn, SysOut, Syscalls},
warn,
use self::cmd::{
ClientDisconnectArgs, ConnectArgs, CreateClientArgs, CreateServerArgs, CreateSessionArgs,
InvokeAsyncMethodArgs, InvokeSyncMethodArgs, IpmiCommand, PollEventFlagArgs,
ServerReceivePacketArgs, TryGetMessagetArgs, TryGetResultArgs,
};
use crate::info;
use crate::process::VThread;
use crate::syscalls::{SysErr, SysIn, SysOut, Syscalls};
use std::sync::Arc;

mod cmd;

use cmd::*;

pub struct IpmiManager {}

impl IpmiManager {
Expand All @@ -21,7 +21,7 @@ impl IpmiManager {
ipmi
}

fn sys_ipmi_mgr_call(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_ipmi_mgr_call(self: &Arc<Self>, td: &Arc<VThread>, i: &SysIn) -> Result<SysOut, SysErr> {
const BUF_SIZE: usize = 0x40;

let cmd: u32 = i.args[0].try_into().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/src/kqueue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ impl KernelQueueManager {
kq
}

fn sys_kqueueex(self: &Arc<Self>, _: &VThread, _: &SysIn) -> Result<SysOut, SysErr> {
fn sys_kqueueex(self: &Arc<Self>, _: &Arc<VThread>, _: &SysIn) -> Result<SysOut, SysErr> {
todo!()
}

fn sys_kqueue(self: &Arc<Self>, td: &VThread, _: &SysIn) -> Result<SysOut, SysErr> {
fn sys_kqueue(self: &Arc<Self>, td: &Arc<VThread>, _: &SysIn) -> Result<SysOut, SysErr> {
let filedesc = td.proc().files();

let fd = filedesc.alloc_with_budget::<Infallible>(
Expand Down
6 changes: 5 additions & 1 deletion src/kernel/src/namedobj/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ impl NamedObjManager {
namedobj
}

fn sys_namedobj_create(self: &Arc<Self>, td: &VThread, i: &SysIn) -> Result<SysOut, SysErr> {
fn sys_namedobj_create(
self: &Arc<Self>,
td: &Arc<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
Loading

0 comments on commit 9688b75

Please sign in to comment.