From 066c12efbd1764f011331ad23a4a5f72e3c0a233 Mon Sep 17 00:00:00 2001 From: SuchAFuriousDeath <48620541+SuchAFuriousDeath@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:37:33 +0100 Subject: [PATCH] Mounts /common/lib (#752) --- src/kernel/src/main.rs | 45 ++++++++++++++++++++++++++++++++++++-- src/kernel/src/rtld/mod.rs | 4 +++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/kernel/src/main.rs b/src/kernel/src/main.rs index 6aeec6fb0..14dbb0a1d 100644 --- a/src/kernel/src/main.rs +++ b/src/kernel/src/main.rs @@ -268,6 +268,39 @@ fn run() -> Result<(), KernelError> { return Err(KernelError::MountFailed(app, e)); } + let system_component = "QXuNNl0Zhn"; + + let system_path = root.join(system_component).unwrap(); + + if let Err(e) = fs.mkdir(&system_path, 0o555, None) { + return Err(KernelError::CreateDirectoryFailed(system_path, e)); + } + + // TODO: Check permission of /mnt/sandbox/CUSAXXXXX_000//common on the PS4. + let common_path = system_path.join("common").unwrap(); + + if let Err(e) = fs.mkdir(&common_path, 0o555, None) { + return Err(KernelError::CreateDirectoryFailed(common_path, e)); + } + + // TODO: Check permission of /mnt/sandbox/CUSAXXXXX_000//common/lib on the PS4. + let lib_path = system_path.join("lib").unwrap(); + + if let Err(e) = fs.mkdir(&lib_path, 0o555, None) { + return Err(KernelError::CreateDirectoryFailed(lib_path, e)); + } + + // TODO: Get mount options from the PS4. + let mut opts = MountOpts::new(); + + opts.insert("fstype", "nullfs"); + opts.insert("fspath", system_path); + opts.insert("target", vpath!("/system").to_owned()); + + if let Err(e) = fs.mount(opts, MountFlags::empty(), None) { + return Err(KernelError::MountFailed(app, e)); + } + // TODO: Check permission of /mnt/sandbox/pfsmnt/CUSAXXXXX-app0-patch0-union on the PS4. let path: VPathBuf = format!("/mnt/sandbox/pfsmnt/{}-app0-patch0-union", param.title_id()) .try_into() @@ -391,9 +424,17 @@ fn run() -> Result<(), KernelError> { writeln!(log, "Application : {}", app.path()).unwrap(); app.print(log); + let lib_path = VPathBuf::new() + .join(system_component) + .unwrap() + .join("common") + .unwrap() + .join("lib") + .unwrap(); + // Preload libkernel. let mut flags = LoadFlags::UNK1; - let path = vpath!("/system/common/lib/libkernel.sprx"); + let path = lib_path.join("libkernel.sprx").unwrap(); if proc.budget_ptype() == ProcType::BigApp { flags |= LoadFlags::BIG_APP; @@ -411,7 +452,7 @@ fn run() -> Result<(), KernelError> { ld.set_kernel(libkernel); // Preload libSceLibcInternal. - let path = vpath!("/system/common/lib/libSceLibcInternal.sprx"); + let path = lib_path.join("libSceLibcInternal.sprx").unwrap(); info!("Loading {path}."); diff --git a/src/kernel/src/rtld/mod.rs b/src/kernel/src/rtld/mod.rs index de3e6ea91..f5f9bbca4 100644 --- a/src/kernel/src/rtld/mod.rs +++ b/src/kernel/src/rtld/mod.rs @@ -184,12 +184,14 @@ impl RuntimeLinker { /// reference. pub fn load( &self, - path: &VPath, + path: impl AsRef, _: LoadFlags, force: bool, main: bool, td: &VThread, ) -> Result, LoadError> { + let path = path.as_ref(); + // Check if already loaded. let name = path.file_name().unwrap().to_owned(); let mut bin = td.proc().bin_mut();