Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses process credential on main thread #805

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/kernel/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::arch::MachDep;
use crate::budget::{Budget, BudgetManager, ProcType};
use crate::dev::{DebugManager, DipswManager, TtyManager};
use crate::dmem::DmemManager;
use crate::dev::{
DebugManager, DebugManagerInitError, DipswInitError, DipswManager, TtyManager,
TtyManagerInitError,
};
use crate::dmem::{DmemManager, DmemManagerInitError};
use crate::ee::native::NativeEngine;
use crate::ee::EntryArg;
use crate::errno::EEXIST;
Expand All @@ -22,8 +25,6 @@ use crate::time::TimeManager;
use crate::ucred::{AuthAttrs, AuthCaps, AuthInfo, AuthPaid, Gid, Ucred, Uid};
use crate::umtx::UmtxManager;
use clap::Parser;
use dev::{DebugManagerInitError, DipswInitError, TtyManagerInitError};
use dmem::DmemManagerInitError;
use llt::{OsThread, SpawnError};
use macros::vpath;
use param::Param;
Expand Down Expand Up @@ -80,7 +81,7 @@ fn run() -> Result<(), KernelError> {

serde_yaml::from_reader(file).map_err(KernelError::FailedToParseDebugConfig)?
} else {
Args::try_parse()?
Args::try_parse().map_err(KernelError::FailedToParseArgs)?
};

// Initialize debug dump.
Expand Down Expand Up @@ -366,8 +367,6 @@ fn run() -> Result<(), KernelError> {
UmtxManager::new(&mut syscalls);

// Initialize runtime linker.
info!("Initializing runtime linker.");

let ee = NativeEngine::new();
let ld = RuntimeLinker::new(&fs, &ee, &mut syscalls);

Expand All @@ -391,18 +390,9 @@ fn run() -> Result<(), KernelError> {
proc.vm().stack().end()
);

// TODO: Check if this credential is actually correct for game main thread.
let cred = Arc::new(Ucred::new(
Uid::ROOT,
Uid::ROOT,
vec![Gid::ROOT],
AuthInfo::SYS_CORE.clone(),
));

let main = VThread::new(proc.clone(), &cred);

// Load eboot.bin.
let path = vpath!("/app0/eboot.bin");
let main = VThread::new(proc.clone());
let app = ld
.exec(path, &main)
.map_err(|e| KernelError::ExecFailed(path, e))?;
Expand Down Expand Up @@ -591,7 +581,7 @@ enum KernelError {
FailedToParseDebugConfig(#[source] serde_yaml::Error),

#[error("couldn't parse arguments")]
FailedToParseArgs(#[from] clap::Error),
FailedToParseArgs(#[source] clap::Error),

#[error("couldn't open param.sfo")]
FailedToOpenGameParam(#[source] std::io::Error),
Expand Down
6 changes: 3 additions & 3 deletions src/kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod thread;
pub struct VProc {
id: NonZeroI32, // p_pid
threads: Gutex<Vec<Arc<VThread>>>, // p_threads
cred: Ucred, // p_ucred
cred: Arc<Ucred>, // p_ucred
group: Gutex<Option<Arc<VProcGroup>>>, // p_pgrp
abi: OnceLock<ProcAbi>, // p_sysent
vm: Arc<Vm>, // p_vmspace
Expand Down Expand Up @@ -100,7 +100,7 @@ impl VProc {
let vp = Arc::new(Self {
id: Self::new_id(),
threads: gg.spawn(Vec::new()),
cred,
cred: Arc::new(cred),
group: gg.spawn(None),
abi: OnceLock::new(),
vm: Vm::new(&mut sys)?,
Expand Down Expand Up @@ -145,7 +145,7 @@ impl VProc {
self.id
}

pub fn cred(&self) -> &Ucred {
pub fn cred(&self) -> &Arc<Ucred> {
&self.cred
}

Expand Down
5 changes: 3 additions & 2 deletions src/kernel/src/process/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ pub struct VThread {
}

impl VThread {
pub fn new(proc: Arc<VProc>, cred: &Arc<Ucred>) -> Self {
pub fn new(proc: Arc<VProc>) -> Self {
// TODO: Check how the PS4 actually allocate the thread ID.
let gg = GutexGroup::new();
let cred = proc.cred().clone();

Self {
proc,
id: NonZeroI32::new(NEXT_ID.fetch_add(1, Ordering::Relaxed)).unwrap(),
cred: cred.clone(),
cred,
sigmask: gg.spawn(SignalSet::default()),
pri_class: 3, // TODO: Check the actual value on the PS4 when a thread is created.
base_user_pri: 700, // TODO: Same here.
Expand Down