diff --git a/src/Cargo.toml b/src/Cargo.toml index 96e7271be..568be57c4 100644 --- a/src/Cargo.toml +++ b/src/Cargo.toml @@ -13,7 +13,6 @@ members = [ "param", "pfs", "pkg", - "system", "tls" ] diff --git a/src/core.hpp b/src/core.hpp index 4c324f5cc..09f9ce473 100644 --- a/src/core.hpp +++ b/src/core.hpp @@ -15,6 +15,13 @@ extern "C" { void param_title_get(const param *param, QString &buf); void param_title_id_get(const param *param, QString &buf); + + error *system_download( + const char *from, + const char *to, + bool explicit_decryption, + void (*status) (const char *, std::uint64_t, std::uint64_t, void *), + void *ud); } class Error final { diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index cc6103b08..cdf7b1e1a 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -8,6 +8,7 @@ crate-type = ["staticlib"] [dependencies] error = { path = "../error" } +ftp = { path = "../ftp" } param = { path = "../param" } pkg = { path = "../pkg" } -system = { path = "../system" } +thiserror = "1.0" diff --git a/src/system/src/lib.rs b/src/core/src/fwdl.rs similarity index 98% rename from src/system/src/lib.rs rename to src/core/src/fwdl.rs index 855f11776..b8c276f5b 100644 --- a/src/system/src/lib.rs +++ b/src/core/src/fwdl.rs @@ -10,8 +10,6 @@ use std::path::{Path, PathBuf}; use std::ptr::null_mut; use thiserror::Error; -/// # Safety -/// `from` and `to` must be pointed to a null-terminated C string. #[no_mangle] pub unsafe extern "C" fn system_download( from: *const c_char, diff --git a/src/core/src/lib.rs b/src/core/src/lib.rs index fbb22422f..a68bbe0f3 100644 --- a/src/core/src/lib.rs +++ b/src/core/src/lib.rs @@ -1,9 +1,11 @@ +#![allow(clippy::enum_variant_names)] + // The purpose of this crate is to generate a static library to link with the GUI. So it is required // to add other crates that expose API to the GUI as a dependency of this crate then re-export all // of those APIs here. pub use error::*; pub use pkg::*; -pub use system::*; mod ffi; +mod fwdl; mod param; diff --git a/src/kernel/src/process/thread.rs b/src/kernel/src/process/thread.rs index 9f6548b80..c78d329e0 100644 --- a/src/kernel/src/process/thread.rs +++ b/src/kernel/src/process/thread.rs @@ -14,6 +14,8 @@ pub struct VThread { id: NonZeroI32, // td_tid cred: Ucred, // td_ucred sigmask: GroupMutex, // td_sigmask + pri_class: u16, // td_pri_class + base_user_pri: u16, // td_base_user_pri } impl VThread { @@ -23,6 +25,8 @@ impl VThread { id, cred, sigmask: mtxg.new_member(SignalSet::default()), + pri_class: 3, // TODO: Check the actual value on the PS4 when a thread is created. + base_user_pri: 120, // TODO: Same here. } } @@ -44,6 +48,14 @@ impl VThread { self.sigmask.write() } + pub fn pri_class(&self) -> u16 { + self.pri_class + } + + pub fn base_user_pri(&self) -> u16 { + self.base_user_pri + } + /// An implementation of `priv_check`. pub fn priv_check(&self, p: Privilege) -> Result<(), PrivilegeError> { self.cred.priv_check(p) diff --git a/src/kernel/src/syscalls/input.rs b/src/kernel/src/syscalls/input.rs index 5fadca927..4ad7a21f2 100644 --- a/src/kernel/src/syscalls/input.rs +++ b/src/kernel/src/syscalls/input.rs @@ -109,6 +109,13 @@ impl Display for OpenFlags { } } +/// Outout pf rtprio_thread. +#[repr(C)] +pub struct RtPrio { + pub ty: u16, + pub prio: u16, +} + /// Contains information about the loaded SELF. #[repr(C)] pub struct DynlibInfoEx { diff --git a/src/kernel/src/syscalls/mod.rs b/src/kernel/src/syscalls/mod.rs index 9d430c3a4..ab27277fe 100644 --- a/src/kernel/src/syscalls/mod.rs +++ b/src/kernel/src/syscalls/mod.rs @@ -95,6 +95,11 @@ impl Syscalls { i.args[2].into(), ), 432 => self.thr_self(i.args[0].into()), + 466 => self.rtprio_thread( + i.args[0].try_into().unwrap(), + i.args[1].try_into().unwrap(), + i.args[2].into(), + ), 477 => self.mmap( i.args[0].into(), i.args[1].into(), @@ -461,6 +466,39 @@ impl Syscalls { Ok(Output::ZERO) } + unsafe fn rtprio_thread( + &self, + function: i32, + lwpid: i32, + rtp: *mut RtPrio, + ) -> Result { + const RTP_LOOKUP: i32 = 0; + const RTP_SET: i32 = 1; + const RTP_UNK: i32 = 2; + + let td = VThread::current(); + + if function == RTP_SET { + todo!("rtprio_thread with function = 1"); + } + + if function == RTP_UNK && td.cred().is_system() { + todo!("rtprio_thread with function = 2"); + } else if lwpid != 0 && lwpid != td.id().get() { + return Err(Error::Raw(ESRCH)); + } else if function == RTP_LOOKUP { + (*rtp).ty = td.pri_class(); + (*rtp).prio = match td.pri_class() & 0xfff7 { + 2 | 3 | 4 => td.base_user_pri(), + _ => 0, + }; + } else { + todo!("rtprio_thread with function = {function}"); + } + + Ok(Output::ZERO) + } + unsafe fn mmap( &self, addr: usize, diff --git a/src/system/Cargo.toml b/src/system/Cargo.toml deleted file mode 100644 index 5675dc1d7..000000000 --- a/src/system/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "system" -version = "0.1.0" -edition = "2021" - -[dependencies] -error = { path = "../error" } -ftp = { path = "../ftp" } -thiserror = "1.0" diff --git a/src/system_downloader.cpp b/src/system_downloader.cpp index 97804681b..831f5ff2e 100644 --- a/src/system_downloader.cpp +++ b/src/system_downloader.cpp @@ -1,15 +1,6 @@ #include "system_downloader.hpp" #include "core.hpp" -extern "C" { - error *system_download( - const char *from, - const char *to, - bool explicit_decryption, - void (*status) (const char *, std::uint64_t, std::uint64_t, void *), - void *ud); -} - SystemDownloader::SystemDownloader(const QString &from, const QString &to, bool explicitDecryption) : m_from(from), m_to(to),