From 9bc3dc32876e1dc05d97ff8caef561d5049f750e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Wed, 27 Mar 2024 10:56:55 +0100 Subject: [PATCH 01/23] Fixes mkdir on Windows --- src/kernel/src/fs/host/file.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kernel/src/fs/host/file.rs b/src/kernel/src/fs/host/file.rs index d001e4f6f..67bea032a 100644 --- a/src/kernel/src/fs/host/file.rs +++ b/src/kernel/src/fs/host/file.rs @@ -209,7 +209,7 @@ impl HostFile { use std::ptr::null_mut; use windows_sys::Wdk::{ Foundation::OBJECT_ATTRIBUTES, - Storage::FileSystem::{NtCreateFile, FILE_DIRECTORY_FILE, FILE_OPEN}, + Storage::FileSystem::{NtCreateFile, FILE_CREATE, FILE_DIRECTORY_FILE}, }; use windows_sys::Win32::{ Foundation::{RtlNtStatusToDosError, STATUS_SUCCESS, UNICODE_STRING}, @@ -256,7 +256,7 @@ impl HostFile { null_mut(), FILE_ATTRIBUTE_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE, - FILE_OPEN, + FILE_CREATE, FILE_DIRECTORY_FILE, null_mut(), 0, From 8eb422ee6fcfe0408a8ea3f4a9a7c300f80dee88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Wed, 27 Mar 2024 10:58:53 +0100 Subject: [PATCH 02/23] Revert "Fixes mkdir on Windows" This reverts commit a6652078dfdf3766bd258eb95baf71b6e01125e2. --- src/kernel/src/fs/host/file.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kernel/src/fs/host/file.rs b/src/kernel/src/fs/host/file.rs index 67bea032a..d001e4f6f 100644 --- a/src/kernel/src/fs/host/file.rs +++ b/src/kernel/src/fs/host/file.rs @@ -209,7 +209,7 @@ impl HostFile { use std::ptr::null_mut; use windows_sys::Wdk::{ Foundation::OBJECT_ATTRIBUTES, - Storage::FileSystem::{NtCreateFile, FILE_CREATE, FILE_DIRECTORY_FILE}, + Storage::FileSystem::{NtCreateFile, FILE_DIRECTORY_FILE, FILE_OPEN}, }; use windows_sys::Win32::{ Foundation::{RtlNtStatusToDosError, STATUS_SUCCESS, UNICODE_STRING}, @@ -256,7 +256,7 @@ impl HostFile { null_mut(), FILE_ATTRIBUTE_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE, - FILE_CREATE, + FILE_OPEN, FILE_DIRECTORY_FILE, null_mut(), 0, From d405d70521f1f61f7de5e082f5de55c676cb5a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sat, 6 Apr 2024 17:11:07 +0200 Subject: [PATCH 03/23] Implements sys_netcontrol --- src/kernel/src/dev/dipsw.rs | 4 ++-- src/kernel/src/dev/dmem.rs | 2 +- src/kernel/src/dev/mod.rs | 2 ++ src/kernel/src/net/mod.rs | 39 ++++++++++++++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/kernel/src/dev/dipsw.rs b/src/kernel/src/dev/dipsw.rs index 59beec616..ee8c604ca 100644 --- a/src/kernel/src/dev/dipsw.rs +++ b/src/kernel/src/dev/dipsw.rs @@ -31,13 +31,13 @@ impl DeviceDriver for Dipsw { let td = td.unwrap(); if !td.cred().is_system() { - todo!() - } else { match cmd { // TODO: properly implement this IoCmd::DIPSWCHECK2(val) => *val = false as i32, _ => todo!(), } + } else { + todo!() } Ok(()) diff --git a/src/kernel/src/dev/dmem.rs b/src/kernel/src/dev/dmem.rs index 6270b5398..d251fcbea 100644 --- a/src/kernel/src/dev/dmem.rs +++ b/src/kernel/src/dev/dmem.rs @@ -71,7 +71,7 @@ impl DeviceDriver for Dmem { // TODO: properly implement this IoCmd::DMEMTOTAL(size) => *size = self.total_size, IoCmd::DMEMGETPRT(_prt) => todo!(), - IoCmd::DMEMGETAVAIL(_avail) => todo!(), + IoCmd::DMEMGETAVAIL(_avail) => {} IoCmd::DMEMALLOC(_alloc) => todo!(), IoCmd::DMEMQUERY(_query) => todo!(), _ => todo!(), diff --git a/src/kernel/src/dev/mod.rs b/src/kernel/src/dev/mod.rs index 3708bda70..1936e9ec0 100644 --- a/src/kernel/src/dev/mod.rs +++ b/src/kernel/src/dev/mod.rs @@ -1,3 +1,4 @@ +pub use camera::*; pub use deci::*; pub use dipsw::*; pub use dmem::*; @@ -8,6 +9,7 @@ pub use rng::*; pub use sbl_srv::*; pub use ttyconsole::*; +mod camera; mod deci; mod dipsw; mod dmem; diff --git a/src/kernel/src/net/mod.rs b/src/kernel/src/net/mod.rs index 6d6203849..bc1508c22 100644 --- a/src/kernel/src/net/mod.rs +++ b/src/kernel/src/net/mod.rs @@ -1,7 +1,7 @@ use crate::budget::BudgetType; use crate::errno::{Errno, EFAULT, EINVAL}; use crate::fs::{IoVec, VFileFlags, VFileType}; -use crate::info; +use crate::{arnd, info}; use crate::{ process::VThread, syscalls::{SysErr, SysIn, SysOut, Syscalls}, @@ -30,6 +30,7 @@ impl NetManager { sys.register(28, &net, Self::sys_sendmsg); sys.register(29, &net, Self::sys_recvfrom); sys.register(97, &net, Self::sys_socket); + sys.register(99, &net, Self::sys_netcontrol); sys.register(105, &net, Self::sys_setsockopt); sys.register(113, &net, Self::sys_socketex); sys.register(114, &net, Self::sys_socketclose); @@ -77,6 +78,42 @@ impl NetManager { todo!() } + fn sys_netcontrol(self: &Arc, td: &VThread, i: &SysIn) -> Result { + let fd: i32 = i.args[0].try_into().unwrap(); + let op: i32 = i.args[1].try_into().unwrap(); + let buf: *mut u8 = i.args[2].into(); + let buflen: u32 = i.args[3].try_into().unwrap(); + + let buf = if buf.is_null() { + None + } else { + if buflen > 160 { + return Err(SysErr::Raw(EINVAL)); + } + + Some(unsafe { core::slice::from_raw_parts_mut(buf, buflen as usize) }) + }; + + let _ = if fd < 0 { + } else { + todo!() + }; + + match buf { + Some(buf) => match op { + 0x14 if buf.len() > 3 => arnd::rand_bytes(&mut buf[..4]), + _ => todo!("netcontrol with op = {op}"), + }, + None => todo!("netcontrol with buf = null"), + } + + if fd > -1 { + todo!() + } + + Ok(SysOut::ZERO) + } + fn sys_setsockopt(self: &Arc, td: &VThread, i: &SysIn) -> Result { let fd: i32 = i.args[0].try_into().unwrap(); let level: i32 = i.args[1].try_into().unwrap(); From f6e5916dcad273a23cd1f9047f1cab3bd0cf4871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sat, 6 Apr 2024 17:13:12 +0200 Subject: [PATCH 04/23] add comment --- src/kernel/src/net/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kernel/src/net/mod.rs b/src/kernel/src/net/mod.rs index bc1508c22..a870d4231 100644 --- a/src/kernel/src/net/mod.rs +++ b/src/kernel/src/net/mod.rs @@ -101,6 +101,7 @@ impl NetManager { match buf { Some(buf) => match op { + // bnet_get_secure_seed 0x14 if buf.len() > 3 => arnd::rand_bytes(&mut buf[..4]), _ => todo!("netcontrol with op = {op}"), }, From 31e0dd695918e7f42e023738b3a38659b0611249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sat, 6 Apr 2024 17:14:42 +0200 Subject: [PATCH 05/23] remove camera module --- src/kernel/src/dev/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/kernel/src/dev/mod.rs b/src/kernel/src/dev/mod.rs index 1936e9ec0..3708bda70 100644 --- a/src/kernel/src/dev/mod.rs +++ b/src/kernel/src/dev/mod.rs @@ -1,4 +1,3 @@ -pub use camera::*; pub use deci::*; pub use dipsw::*; pub use dmem::*; @@ -9,7 +8,6 @@ pub use rng::*; pub use sbl_srv::*; pub use ttyconsole::*; -mod camera; mod deci; mod dipsw; mod dmem; From c442e450e4a87ab6c5243119dfba3ec3d4fa7325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sat, 6 Apr 2024 18:43:18 +0200 Subject: [PATCH 06/23] change mode --- src/kernel/src/fs/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/kernel/src/fs/mod.rs b/src/kernel/src/fs/mod.rs index a2534722e..dd3a48341 100644 --- a/src/kernel/src/fs/mod.rs +++ b/src/kernel/src/fs/mod.rs @@ -389,7 +389,6 @@ impl Fs { // Get arguments. let path = unsafe { i.args[0].to_path()?.unwrap() }; let flags: OpenFlags = i.args[1].try_into().unwrap(); - let mode: u32 = i.args[2].try_into().unwrap(); // Check flags. if flags.intersects(OpenFlags::O_EXEC) { @@ -409,8 +408,11 @@ impl Fs { todo!("open({path}) with flags & O_EXLOCK"); } else if flags.intersects(OpenFlags::O_TRUNC) { todo!("open({path}) with flags & O_TRUNC"); - } else if mode != 0 { - todo!("open({path}, {flags}) with mode = {mode}"); + } else { + let mode: u32 = i.args[2].try_into().unwrap(); + if mode != 0 { + todo!("open({path}, {flags}) with mode = {mode}"); + } } info!("Opening {path} with flags = {flags}."); From 89eebbcd7ff7f5a2ee9afe198589de3aa4468361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 11:00:49 +0200 Subject: [PATCH 07/23] put todo back --- src/kernel/src/dev/dmem.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/src/dev/dmem.rs b/src/kernel/src/dev/dmem.rs index d251fcbea..6270b5398 100644 --- a/src/kernel/src/dev/dmem.rs +++ b/src/kernel/src/dev/dmem.rs @@ -71,7 +71,7 @@ impl DeviceDriver for Dmem { // TODO: properly implement this IoCmd::DMEMTOTAL(size) => *size = self.total_size, IoCmd::DMEMGETPRT(_prt) => todo!(), - IoCmd::DMEMGETAVAIL(_avail) => {} + IoCmd::DMEMGETAVAIL(_avail) => todo!(), IoCmd::DMEMALLOC(_alloc) => todo!(), IoCmd::DMEMQUERY(_query) => todo!(), _ => todo!(), From cfd645b8733fd084c376be5bbf81f875de7db558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 12:36:14 +0200 Subject: [PATCH 08/23] refactors open --- src/kernel/src/budget/mod.rs | 15 +++++-------- src/kernel/src/dmem/mod.rs | 7 ++++-- src/kernel/src/fs/file.rs | 8 ++----- src/kernel/src/fs/ioctl.rs | 3 +++ src/kernel/src/fs/mod.rs | 13 ++++++----- src/kernel/src/kqueue/mod.rs | 6 +++-- src/kernel/src/net/mod.rs | 8 +++---- src/kernel/src/net/socket.rs | 7 +++++- src/kernel/src/process/filedesc.rs | 36 +++++++++++++++++++++++------- src/kernel/src/rtld/mod.rs | 5 +++-- src/kernel/src/shm/mod.rs | 19 +++++++--------- 11 files changed, 76 insertions(+), 51 deletions(-) diff --git a/src/kernel/src/budget/mod.rs b/src/kernel/src/budget/mod.rs index 449f17fb4..c4ad31bf2 100644 --- a/src/kernel/src/budget/mod.rs +++ b/src/kernel/src/budget/mod.rs @@ -82,21 +82,18 @@ pub enum BudgetType { FdIpcSocket = 11, } -#[allow(dead_code)] #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ProcType { - BigApp, - MiniApp, - System, // TODO: Verify this. + BigApp = 0, + #[allow(unused)] + MiniApp = 1, + #[allow(unused)] + System = 2, // TODO: Verify this. } impl Into for ProcType { fn into(self) -> u32 { - match self { - ProcType::BigApp => 0, - ProcType::MiniApp => 1, - ProcType::System => 2, - } + self as u32 } } diff --git a/src/kernel/src/dmem/mod.rs b/src/kernel/src/dmem/mod.rs index b26afc621..72f60da27 100644 --- a/src/kernel/src/dmem/mod.rs +++ b/src/kernel/src/dmem/mod.rs @@ -1,7 +1,8 @@ use crate::dev::{Dmem, DmemContainer}; use crate::errno::EINVAL; use crate::fs::{ - make_dev, CharacterDevice, DriverFlags, Fs, MakeDevError, MakeDevFlags, Mode, VFile, VFileType, + make_dev, CharacterDevice, DriverFlags, Fs, MakeDevError, MakeDevFlags, Mode, VFile, + VFileFlags, VFileType, }; use crate::info; use crate::process::VThread; @@ -132,10 +133,12 @@ impl DmemManager { let bp = BlockPool::new(); + let flags = VFileFlags::from_bits_retain(flags) | VFileFlags::WRITE; + let fd = td .proc() .files() - .alloc(Arc::new(VFile::new(VFileType::Blockpool(bp)))); + .alloc(Arc::new(VFile::new(VFileType::Blockpool(bp), flags))); Ok(fd.into()) } diff --git a/src/kernel/src/fs/file.rs b/src/kernel/src/fs/file.rs index 60c4f4098..11c1ae75b 100644 --- a/src/kernel/src/fs/file.rs +++ b/src/kernel/src/fs/file.rs @@ -24,12 +24,12 @@ pub struct VFile { } impl VFile { - pub fn new(ty: VFileType) -> Self { + pub fn new(ty: VFileType, flags: VFileFlags) -> Self { let gg = GutexGroup::new(); Self { ty, - flags: VFileFlags::empty(), + flags, offset: gg.spawn(0), } } @@ -38,10 +38,6 @@ impl VFile { self.flags } - pub fn flags_mut(&mut self) -> &mut VFileFlags { - &mut self.flags - } - /// Checking if this returns `Some` is equivalent to when FreeBSD and the PS4 check /// fp->f_ops->fo_flags & DFLAG_SEEKABLE != 0, therefore we use this instead. pub fn seekable_vnode(&self) -> Option<&Arc> { diff --git a/src/kernel/src/fs/ioctl.rs b/src/kernel/src/fs/ioctl.rs index 57fd72b71..f38c5e8f2 100644 --- a/src/kernel/src/fs/ioctl.rs +++ b/src/kernel/src/fs/ioctl.rs @@ -152,6 +152,8 @@ commands! { /// Unkown rng command RNG2 = 0x40445302, + BNISSYSTMPROC(&Unknown36) = 0x802450c9, + /// Become controlling terminal. TIOCSCTTY = 0x20007461, } @@ -160,6 +162,7 @@ commands! { type Unknown2 = Unknown<2>; type Unknown8 = Unknown<8>; type Unknown16 = Unknown<16>; +type Unknown36 = Unknown<36>; /// A dummy type to be used as a placeholder for unknown data. #[derive(Debug)] diff --git a/src/kernel/src/fs/mod.rs b/src/kernel/src/fs/mod.rs index dd3a48341..c38cadd09 100644 --- a/src/kernel/src/fs/mod.rs +++ b/src/kernel/src/fs/mod.rs @@ -170,7 +170,12 @@ impl Fs { self.root.read().clone() } - pub fn open(&self, path: impl AsRef, td: Option<&VThread>) -> Result { + pub fn open( + &self, + path: impl AsRef, + flags: VFileFlags, + td: Option<&VThread>, + ) -> Result { let vnode = self .lookup(path, true, td) .map_err(OpenError::LookupFailed)?; @@ -181,7 +186,7 @@ impl Fs { VFileType::Vnode(vnode.clone()) }; - Ok(VFile::new(ty)) + Ok(VFile::new(ty, flags)) } pub fn lookup( @@ -418,9 +423,7 @@ impl Fs { info!("Opening {path} with flags = {flags}."); // Lookup file. - let mut file = self.open(path, Some(td))?; - - *file.flags_mut() = flags.into_fflags(); + let mut file = self.open(path, flags.into_fflags(), Some(td))?; // Install to descriptor table. let fd = td.proc().files().alloc(Arc::new(file)); diff --git a/src/kernel/src/kqueue/mod.rs b/src/kernel/src/kqueue/mod.rs index 72ce736d5..9c1043571 100644 --- a/src/kernel/src/kqueue/mod.rs +++ b/src/kernel/src/kqueue/mod.rs @@ -38,9 +38,11 @@ impl KernelQueueManager { filedesc.insert_kqueue(kq.clone()); - Ok(VFileType::KernelQueue(kq)) + Ok(VFile::new( + VFileType::KernelQueue(kq), + VFileFlags::READ | VFileFlags::WRITE, + )) }, - VFileFlags::READ | VFileFlags::WRITE, BudgetType::FdEqueue, )?; diff --git a/src/kernel/src/net/mod.rs b/src/kernel/src/net/mod.rs index a870d4231..cc1fd6a46 100644 --- a/src/kernel/src/net/mod.rs +++ b/src/kernel/src/net/mod.rs @@ -1,6 +1,6 @@ use crate::budget::BudgetType; use crate::errno::{Errno, EFAULT, EINVAL}; -use crate::fs::{IoVec, VFileFlags, VFileType}; +use crate::fs::{IoVec, VFile, VFileFlags, VFileType}; use crate::{arnd, info}; use crate::{ process::VThread, @@ -148,9 +148,8 @@ impl NetManager { VFileType::Socket(so) }; - Ok(ty) + Ok(VFile::new(ty, VFileFlags::READ | VFileFlags::WRITE)) }, - VFileFlags::WRITE | VFileFlags::READ, budget, )?; @@ -191,9 +190,8 @@ impl NetManager { VFileType::Socket(so) }; - Ok(ty) + Ok(VFile::new(ty, VFileFlags::READ | VFileFlags::WRITE)) }, - VFileFlags::WRITE | VFileFlags::READ, budget, )?; diff --git a/src/kernel/src/net/socket.rs b/src/kernel/src/net/socket.rs index 587daf594..f35733c01 100644 --- a/src/kernel/src/net/socket.rs +++ b/src/kernel/src/net/socket.rs @@ -33,7 +33,12 @@ impl Socket { td: &VThread, name: Option<&str>, ) -> Result, SocketCreateError> { - todo!() + Ok(Arc::new(Socket { + ty, + options: SocketOptions::empty(), + cred: cred.clone(), + name: name.map(|s| s.to_string().into_boxed_str()), + })) } fn options(&self) -> SocketOptions { diff --git a/src/kernel/src/process/filedesc.rs b/src/kernel/src/process/filedesc.rs index d57675529..184fbd613 100644 --- a/src/kernel/src/process/filedesc.rs +++ b/src/kernel/src/process/filedesc.rs @@ -1,6 +1,6 @@ use crate::budget::BudgetType; use crate::errno::{Errno, EBADF}; -use crate::fs::{VFile, VFileFlags, VFileType, Vnode}; +use crate::fs::{VFile, VFileFlags, Vnode}; use crate::kqueue::KernelQueue; use gmtx::{Gutex, GutexGroup}; use macros::Errno; @@ -55,20 +55,40 @@ impl FileDesc { #[allow(unused_variables)] // TODO: remove when implementing; add budget argument pub fn alloc_with_budget( &self, - constructor: impl FnOnce(i32) -> Result, - flags: VFileFlags, - budget: BudgetType, + constructor: impl FnOnce(i32) -> Result, + _budget: BudgetType, ) -> Result> { - todo!() + // TODO: check budget + + self.alloc_without_budget(constructor) } #[allow(unused_variables)] // TODO: remove when implementing; pub fn alloc_without_budget( &self, - constructor: impl FnOnce(i32) -> Result, - flags: VFileFlags, + constructor: impl FnOnce(i32) -> Result, ) -> Result> { - todo!() + // TODO: Implement fdalloc. + let mut files = self.files.write(); + + for i in 0..=(i32::MAX) as usize { + if i == files.len() { + let file = constructor(i as i32).map_err(FileAllocError::Inner)?; + + files.push(Some(Arc::new(file))); + } else if files[i].is_none() { + let file = constructor(i as i32).map_err(FileAllocError::Inner)?; + + files[i] = Some(Arc::new(file)); + } else { + continue; + } + + return Ok(i as i32); + } + + // This should never happen. + panic!("Too many files has been opened."); } /// See `finstall` on the PS4 for a reference. diff --git a/src/kernel/src/rtld/mod.rs b/src/kernel/src/rtld/mod.rs index 26c559117..c4b9bb0fd 100644 --- a/src/kernel/src/rtld/mod.rs +++ b/src/kernel/src/rtld/mod.rs @@ -4,6 +4,7 @@ use self::resolver::{ResolveFlags, SymbolResolver}; use crate::budget::ProcType; use crate::ee::native::{NativeEngine, SetupModuleError}; use crate::errno::{Errno, EINVAL, ENOENT, ENOEXEC, ENOMEM, EPERM, ESRCH}; +use crate::fs::VFileFlags; use crate::fs::{Fs, OpenError, VPath, VPathBuf}; use crate::idt::Entry; use crate::imgact::orbis::{DynamicFlags, Elf, FileType, ReadProgramError, Relocation, Symbol}; @@ -91,7 +92,7 @@ impl RuntimeLinker { let path = path.as_ref(); let file = self .fs - .open(path, Some(td)) + .open(path, VFileFlags::READ, Some(td)) .map_err(ExecError::OpenExeFailed)?; let elf = Elf::open(path.as_str(), file).map_err(ExecError::ReadExeFailed)?; @@ -209,7 +210,7 @@ impl RuntimeLinker { } // Get file. - let file = match self.fs.open(path, Some(td)) { + let file = match self.fs.open(path, VFileFlags::READ, Some(td)) { Ok(v) => v, Err(e) => return Err(LoadError::OpenFileFailed(e)), }; diff --git a/src/kernel/src/shm/mod.rs b/src/kernel/src/shm/mod.rs index e0df17d4e..0b9f58415 100644 --- a/src/kernel/src/shm/mod.rs +++ b/src/kernel/src/shm/mod.rs @@ -49,17 +49,14 @@ impl SharedMemoryManager { #[allow(unused_variables)] // TODO: remove when implementing. let mode = mode & filedesc.cmask() & 0o7777; - let fd = filedesc.alloc_without_budget::( - |_| match path { - ShmPath::Anon => { - todo!() - } - ShmPath::Path(_) => { - todo!() - } - }, - (flags & OpenFlags::O_ACCMODE).into_fflags(), - )?; + let fd = filedesc.alloc_without_budget::(|_| match path { + ShmPath::Anon => { + todo!() + } + ShmPath::Path(_) => { + todo!() + } + })?; Ok(fd.into()) } From 9353bdc9889c6fbf5eaee3a226f847bcb99c8edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 12:38:55 +0200 Subject: [PATCH 09/23] add logging --- src/kernel/src/net/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/kernel/src/net/mod.rs b/src/kernel/src/net/mod.rs index cc1fd6a46..42ebaf929 100644 --- a/src/kernel/src/net/mod.rs +++ b/src/kernel/src/net/mod.rs @@ -84,6 +84,8 @@ impl NetManager { let buf: *mut u8 = i.args[2].into(); let buflen: u32 = i.args[3].try_into().unwrap(); + info!("Netcontrol called with op = {op}."); + let buf = if buf.is_null() { None } else { @@ -153,6 +155,8 @@ impl NetManager { budget, )?; + info!("Opened a socket at fd {fd}."); + Ok(fd.into()) } @@ -195,6 +199,8 @@ impl NetManager { budget, )?; + info!("Opened a socket(ex) at fd {fd}."); + Ok(fd.into()) } From 14d49b447bd6ed64a48f40e422881804ab06e80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 12:40:54 +0200 Subject: [PATCH 10/23] put back todo --- src/kernel/src/net/socket.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/kernel/src/net/socket.rs b/src/kernel/src/net/socket.rs index f35733c01..ed1509624 100644 --- a/src/kernel/src/net/socket.rs +++ b/src/kernel/src/net/socket.rs @@ -33,12 +33,7 @@ impl Socket { td: &VThread, name: Option<&str>, ) -> Result, SocketCreateError> { - Ok(Arc::new(Socket { - ty, - options: SocketOptions::empty(), - cred: cred.clone(), - name: name.map(|s| s.to_string().into_boxed_str()), - })) + todo!("socreate") } fn options(&self) -> SocketOptions { From d36d78e1293c1c373a8c58c8eff23237e17ad16d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 12:45:40 +0200 Subject: [PATCH 11/23] log proc type info --- src/kernel/src/process/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/kernel/src/process/mod.rs b/src/kernel/src/process/mod.rs index 526b9c982..a19400400 100644 --- a/src/kernel/src/process/mod.rs +++ b/src/kernel/src/process/mod.rs @@ -734,6 +734,8 @@ impl VProc { fn sys_get_proc_type_info(self: &Arc, td: &VThread, i: &SysIn) -> Result { let info = unsafe { &mut *Into::<*mut ProcTypeInfo>::into(i.args[0]) }; + info!("Getting proc_type_info."); + if info.len != size_of::() { return Err(SysErr::Raw(EINVAL)); } From 66477ce1acb74bd2cb3c3e5b0757cc5a5ce390b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 12:50:20 +0200 Subject: [PATCH 12/23] log dmem container --- src/kernel/src/dmem/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/kernel/src/dmem/mod.rs b/src/kernel/src/dmem/mod.rs index 72f60da27..aa45bbc81 100644 --- a/src/kernel/src/dmem/mod.rs +++ b/src/kernel/src/dmem/mod.rs @@ -117,6 +117,8 @@ impl DmemManager { let dmem_container = td.proc().dmem_container_mut(); let current_container = *dmem_container; + info!("Getting dmem container"); + if dmem_id != -1 { todo!() } @@ -140,6 +142,8 @@ impl DmemManager { .files() .alloc(Arc::new(VFile::new(VFileType::Blockpool(bp), flags))); + info!("Opened a blockpool at fd = {fd}"); + Ok(fd.into()) } From 30cf25e752ef5fc0a6fffd59f56751339c8baa86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 12:58:44 +0200 Subject: [PATCH 13/23] roll back --- src/kernel/src/net/mod.rs | 6 +++--- src/kernel/src/net/socket.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kernel/src/net/mod.rs b/src/kernel/src/net/mod.rs index 42ebaf929..694740f37 100644 --- a/src/kernel/src/net/mod.rs +++ b/src/kernel/src/net/mod.rs @@ -173,7 +173,7 @@ impl NetManager { } fn sys_socketex(self: &Arc, td: &VThread, i: &SysIn) -> Result { - let name = unsafe { i.args[0].to_str(32)? }; + let name = unsafe { i.args[0].to_str(32)? }.unwrap(); let domain: i32 = i.args[1].try_into().unwrap(); let ty: i32 = i.args[2].try_into().unwrap(); let proto: Option = i.args[3].try_into().unwrap(); @@ -186,7 +186,7 @@ impl NetManager { let fd = td.proc().files().alloc_with_budget::( |_| { - let so = Socket::new(domain, ty, proto, td.cred(), td, name)?; + let so = Socket::new(domain, ty, proto, td.cred(), td, Some(name))?; let ty = if domain == 1 { VFileType::IpcSocket(so) @@ -199,7 +199,7 @@ impl NetManager { budget, )?; - info!("Opened a socket(ex) at fd {fd}."); + info!("Opened a socket with name = {name} at fd {fd}."); Ok(fd.into()) } diff --git a/src/kernel/src/net/socket.rs b/src/kernel/src/net/socket.rs index ed1509624..587daf594 100644 --- a/src/kernel/src/net/socket.rs +++ b/src/kernel/src/net/socket.rs @@ -33,7 +33,7 @@ impl Socket { td: &VThread, name: Option<&str>, ) -> Result, SocketCreateError> { - todo!("socreate") + todo!() } fn options(&self) -> SocketOptions { From c77b231e91af13f8caf63e9a4aa84d607626a2d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 13:02:07 +0200 Subject: [PATCH 14/23] move and rename bnet command --- src/kernel/src/fs/ioctl.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kernel/src/fs/ioctl.rs b/src/kernel/src/fs/ioctl.rs index f38c5e8f2..5e6a66693 100644 --- a/src/kernel/src/fs/ioctl.rs +++ b/src/kernel/src/fs/ioctl.rs @@ -93,6 +93,9 @@ commands! { /// sceKernelMemoryPoolGetBlockStats BPOOLSTATS(&mut BlockpoolStats) = 0x4010A802, + /// An unkown bnet command, called from libSceNet + BNETUNK(&Unknown36) = 0x802450c9, + /// Get media size in bytes. DIOCGMEDIASIZE(&mut i64) = 0x40086418, @@ -152,8 +155,6 @@ commands! { /// Unkown rng command RNG2 = 0x40445302, - BNISSYSTMPROC(&Unknown36) = 0x802450c9, - /// Become controlling terminal. TIOCSCTTY = 0x20007461, } From cd840107b3b757fcd580b0e236e882204a521fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 13:05:01 +0200 Subject: [PATCH 15/23] log proc type info --- src/kernel/src/process/proc.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/kernel/src/process/proc.rs b/src/kernel/src/process/proc.rs index ee79cdfec..2284cd568 100644 --- a/src/kernel/src/process/proc.rs +++ b/src/kernel/src/process/proc.rs @@ -722,6 +722,8 @@ impl VProc { fn sys_get_proc_type_info(self: &Arc, td: &VThread, i: &SysIn) -> Result { let info = unsafe { &mut *Into::<*mut ProcTypeInfo>::into(i.args[0]) }; + info!("Getting process type information."); + if info.len != size_of::() { return Err(SysErr::Raw(EINVAL)); } From 9a3cd67f07ac215465f0451cb0bea9ffcb797a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 14:14:26 +0200 Subject: [PATCH 16/23] rng iocmds --- src/kernel/src/fs/ioctl.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kernel/src/fs/ioctl.rs b/src/kernel/src/fs/ioctl.rs index 5e6a66693..1bc919498 100644 --- a/src/kernel/src/fs/ioctl.rs +++ b/src/kernel/src/fs/ioctl.rs @@ -151,9 +151,9 @@ commands! { FIOSEEKHOLE(&mut i64) = 0xC0086662, /// Unkown rng command - RNG1 = 0x40445301, + RNG1(&mut Unknown68) = 0x40445301, /// Unkown rng command - RNG2 = 0x40445302, + RNG2(&mut Unknown68) = 0x40445302, /// Become controlling terminal. TIOCSCTTY = 0x20007461, @@ -164,6 +164,7 @@ type Unknown2 = Unknown<2>; type Unknown8 = Unknown<8>; type Unknown16 = Unknown<16>; type Unknown36 = Unknown<36>; +type Unknown68 = Unknown<68>; /// A dummy type to be used as a placeholder for unknown data. #[derive(Debug)] From af5fe0a6fb408f0fc8b09554b9646812d836d5e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 14:21:54 +0200 Subject: [PATCH 17/23] fix rng --- src/kernel/src/dev/rng.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kernel/src/dev/rng.rs b/src/kernel/src/dev/rng.rs index 14bf1927a..ce7661d46 100644 --- a/src/kernel/src/dev/rng.rs +++ b/src/kernel/src/dev/rng.rs @@ -16,8 +16,8 @@ impl DeviceDriver for Rng { _: Option<&VThread>, ) -> Result<(), Box> { match cmd { - IoCmd::RNG1 => todo!(), - IoCmd::RNG2 => todo!(), + IoCmd::RNG1(_) => todo!(), + IoCmd::RNG2(_) => todo!(), _ => todo!(), // ENOIOCTL, } } From bb143b662b5ade4c226fbe6c46fa16375ee0f249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 14:37:40 +0200 Subject: [PATCH 18/23] rename rng --- src/kernel/src/dev/rng.rs | 4 ++-- src/kernel/src/fs/ioctl.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/kernel/src/dev/rng.rs b/src/kernel/src/dev/rng.rs index ce7661d46..f12a10782 100644 --- a/src/kernel/src/dev/rng.rs +++ b/src/kernel/src/dev/rng.rs @@ -16,8 +16,8 @@ impl DeviceDriver for Rng { _: Option<&VThread>, ) -> Result<(), Box> { match cmd { - IoCmd::RNG1(_) => todo!(), - IoCmd::RNG2(_) => todo!(), + IoCmd::RNGGETGENUINE(_) => todo!(), + IoCmd::RNGFIPS(_) => todo!(), _ => todo!(), // ENOIOCTL, } } diff --git a/src/kernel/src/fs/ioctl.rs b/src/kernel/src/fs/ioctl.rs index 1bc919498..60587ac9c 100644 --- a/src/kernel/src/fs/ioctl.rs +++ b/src/kernel/src/fs/ioctl.rs @@ -150,10 +150,10 @@ commands! { /// Seek hole. FIOSEEKHOLE(&mut i64) = 0xC0086662, - /// Unkown rng command - RNG1(&mut Unknown68) = 0x40445301, - /// Unkown rng command - RNG2(&mut Unknown68) = 0x40445302, + /// Get genuine random + RNGGETGENUINE(&mut Unknown68) = 0x40445301, + /// Fips186Prng + RNGFIPS(&mut Unknown68) = 0x40445302, /// Become controlling terminal. TIOCSCTTY = 0x20007461, From 4d8255c83b1d6db9d4b423c9118b576a60be6678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 14:41:00 +0200 Subject: [PATCH 19/23] put back todos --- src/kernel/src/dev/ttyconsole.rs | 2 +- src/kernel/src/fs/dev/vnode.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/kernel/src/dev/ttyconsole.rs b/src/kernel/src/dev/ttyconsole.rs index b0ecb0317..fa50090b0 100644 --- a/src/kernel/src/dev/ttyconsole.rs +++ b/src/kernel/src/dev/ttyconsole.rs @@ -92,7 +92,7 @@ impl Tty { match cmd { // TODO: implement this properly - IoCmd::TIOCSCTTY => return Ok(()), + IoCmd::TIOCSCTTY => todo!(), _ => todo!(), } } diff --git a/src/kernel/src/fs/dev/vnode.rs b/src/kernel/src/fs/dev/vnode.rs index ce0748469..57fc171ff 100644 --- a/src/kernel/src/fs/dev/vnode.rs +++ b/src/kernel/src/fs/dev/vnode.rs @@ -169,8 +169,7 @@ impl crate::fs::VnodeBackend for VnodeBackend { } fn revoke(&self, vn: &Arc, _flags: RevokeFlags) -> Result<(), Box> { - // TODO: Implement this. - Ok(()) + todo!() } fn read( From aac88bb9325613b1d6d856eef7b2c496b4084590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Proch=C3=A1zka?= Date: Sun, 7 Apr 2024 16:43:09 +0200 Subject: [PATCH 20/23] address review --- src/kernel/src/dev/ttyconsole.rs | 3 +-- src/kernel/src/net/mod.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/kernel/src/dev/ttyconsole.rs b/src/kernel/src/dev/ttyconsole.rs index fa50090b0..97f2f2f30 100644 --- a/src/kernel/src/dev/ttyconsole.rs +++ b/src/kernel/src/dev/ttyconsole.rs @@ -87,11 +87,10 @@ impl Tty { } /// See `tty_ioctl` on the PS4 for a reference. - fn generic_ioctl(&self, cmd: IoCmd, td: Option<&VThread>) -> Result<(), TtyIoctlError> { + fn generic_ioctl(&self, cmd: IoCmd, _td: Option<&VThread>) -> Result<(), TtyIoctlError> { // TODO: implement ttydevsw_ioctl match cmd { - // TODO: implement this properly IoCmd::TIOCSCTTY => todo!(), _ => todo!(), } diff --git a/src/kernel/src/net/mod.rs b/src/kernel/src/net/mod.rs index 694740f37..5325d81c4 100644 --- a/src/kernel/src/net/mod.rs +++ b/src/kernel/src/net/mod.rs @@ -173,7 +173,7 @@ impl NetManager { } fn sys_socketex(self: &Arc, td: &VThread, i: &SysIn) -> Result { - let name = unsafe { i.args[0].to_str(32)? }.unwrap(); + let name = unsafe { i.args[0].to_str(32)? }; let domain: i32 = i.args[1].try_into().unwrap(); let ty: i32 = i.args[2].try_into().unwrap(); let proto: Option = i.args[3].try_into().unwrap(); @@ -186,7 +186,7 @@ impl NetManager { let fd = td.proc().files().alloc_with_budget::( |_| { - let so = Socket::new(domain, ty, proto, td.cred(), td, Some(name))?; + let so = Socket::new(domain, ty, proto, td.cred(), td, name)?; let ty = if domain == 1 { VFileType::IpcSocket(so) @@ -199,7 +199,11 @@ impl NetManager { budget, )?; - info!("Opened a socket with name = {name} at fd {fd}."); + if let Some(name) = name { + info!("Opened a socket with name = {name} at fd {fd}."); + } else { + info!("Opened a socket at fd {fd}."); + } Ok(fd.into()) } From c8777c581050ba424d69f6f14c8cdeb6c1e8ee4e Mon Sep 17 00:00:00 2001 From: tompro Date: Mon, 8 Apr 2024 10:41:05 +0200 Subject: [PATCH 21/23] fix build --- src/kernel/src/process/proc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kernel/src/process/proc.rs b/src/kernel/src/process/proc.rs index d4d279afa..56cbbf3a6 100644 --- a/src/kernel/src/process/proc.rs +++ b/src/kernel/src/process/proc.rs @@ -8,6 +8,7 @@ use crate::errno::Errno; use crate::errno::{EINVAL, ERANGE, ESRCH}; use crate::fs::Vnode; use crate::idt::Idt; +use crate::info; use crate::signal::{SignalSet, SIGKILL, SIGSTOP, SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK}; use crate::syscalls::{SysErr, SysIn, SysOut, Syscalls}; use crate::sysent::ProcAbi; From aef68a16c2880a3231274ead498ad6a2cd1d3b95 Mon Sep 17 00:00:00 2001 From: tompro Date: Mon, 8 Apr 2024 10:50:23 +0200 Subject: [PATCH 22/23] ref --- src/kernel/src/net/mod.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/kernel/src/net/mod.rs b/src/kernel/src/net/mod.rs index 5325d81c4..4a287a010 100644 --- a/src/kernel/src/net/mod.rs +++ b/src/kernel/src/net/mod.rs @@ -81,19 +81,26 @@ impl NetManager { fn sys_netcontrol(self: &Arc, td: &VThread, i: &SysIn) -> Result { let fd: i32 = i.args[0].try_into().unwrap(); let op: i32 = i.args[1].try_into().unwrap(); - let buf: *mut u8 = i.args[2].into(); + let ptr: *mut u8 = i.args[2].into(); let buflen: u32 = i.args[3].try_into().unwrap(); info!("Netcontrol called with op = {op}."); - let buf = if buf.is_null() { + let mut buf = if ptr.is_null() { None } else { if buflen > 160 { return Err(SysErr::Raw(EINVAL)); } - Some(unsafe { core::slice::from_raw_parts_mut(buf, buflen as usize) }) + let buf = Box::new([0u8; 160]); + + if op & 0x30000000 != 0 { + // TODO: copyin + todo!() + } + + Some(buf) }; let _ = if fd < 0 { @@ -101,7 +108,7 @@ impl NetManager { todo!() }; - match buf { + match buf.as_mut() { Some(buf) => match op { // bnet_get_secure_seed 0x14 if buf.len() > 3 => arnd::rand_bytes(&mut buf[..4]), @@ -114,6 +121,12 @@ impl NetManager { todo!() } + if let Some(buf) = buf { + if op & 0x30000000 != 0x20000000 { + unsafe { std::ptr::copy_nonoverlapping(buf.as_ptr(), ptr, buflen as usize) }; + } + } + Ok(SysOut::ZERO) } From 9b52af6f9a111deb6293c432daff49da29afc521 Mon Sep 17 00:00:00 2001 From: tompro Date: Mon, 8 Apr 2024 11:56:26 +0200 Subject: [PATCH 23/23] fix logical error --- src/kernel/src/net/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/src/net/mod.rs b/src/kernel/src/net/mod.rs index 4a287a010..c1602025b 100644 --- a/src/kernel/src/net/mod.rs +++ b/src/kernel/src/net/mod.rs @@ -111,7 +111,7 @@ impl NetManager { match buf.as_mut() { Some(buf) => match op { // bnet_get_secure_seed - 0x14 if buf.len() > 3 => arnd::rand_bytes(&mut buf[..4]), + 0x14 if buflen > 3 => arnd::rand_bytes(&mut buf[..4]), _ => todo!("netcontrol with op = {op}"), }, None => todo!("netcontrol with buf = null"),