Skip to content

Commit

Permalink
Implements syscall 466 (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Oct 11, 2023
1 parent 8a74390 commit 94cf76f
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ members = [
"param",
"pfs",
"pkg",
"system",
"tls"
]

Expand Down
7 changes: 7 additions & 0 deletions src/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 0 additions & 2 deletions src/system/src/lib.rs → src/core/src/fwdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions src/kernel/src/process/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct VThread {
id: NonZeroI32, // td_tid
cred: Ucred, // td_ucred
sigmask: GroupMutex<SignalSet>, // td_sigmask
pri_class: u16, // td_pri_class
base_user_pri: u16, // td_base_user_pri
}

impl VThread {
Expand All @@ -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.
}
}

Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/kernel/src/syscalls/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions src/kernel/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -461,6 +466,39 @@ impl Syscalls {
Ok(Output::ZERO)
}

unsafe fn rtprio_thread(
&self,
function: i32,
lwpid: i32,
rtp: *mut RtPrio,
) -> Result<Output, Error> {
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,
Expand Down
9 changes: 0 additions & 9 deletions src/system/Cargo.toml

This file was deleted.

9 changes: 0 additions & 9 deletions src/system_downloader.cpp
Original file line number Diff line number Diff line change
@@ -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),
Expand Down

0 comments on commit 94cf76f

Please sign in to comment.