From 878da3b474f19a976b9afc52011a547cb192458c Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 2 Apr 2021 20:39:47 +0300 Subject: [PATCH] Implement get_cellos_appname() Identifying vsh.self and possibly other operating system executables in the future. --- rpcs3/Emu/Cell/PPUModule.cpp | 19 +++++++++++++++++-- rpcs3/Emu/Cell/lv2/sys_process.cpp | 11 +++++++++++ rpcs3/Emu/Cell/lv2/sys_process.h | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 287461e302..68ed215102 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -1546,6 +1546,12 @@ bool ppu_load_exec(const ppu_exec_object& elf) load_libs.emplace("libsysmodule.sprx"); } + if (g_ps3_process_info.get_cellos_appname() == "vsh.self"sv) + { + // Cannot be used with vsh.self (it self-manages itself) + load_libs.clear(); + } + const std::string lle_dir = vfs::get("/dev_flash/sys/external/"); if (!fs::is_file(lle_dir + "liblv2.sprx")) @@ -1686,7 +1692,6 @@ bool ppu_load_exec(const ppu_exec_object& elf) } // Initialize memory stats (according to sdk version) - // TODO: This is probably wrong with vsh.self u32 mem_size; if (sdk_version > 0x0021FFFF) { @@ -1719,11 +1724,18 @@ bool ppu_load_exec(const ppu_exec_object& elf) mem_size += 0xC000000; } + if (g_ps3_process_info.get_cellos_appname() == "vsh.self"sv) + { + // Because vsh.self comes before any generic application, more memory is available to it + // This is an estimation though (TODO) + mem_size += 0x800000; + } + g_fxo->init(mem_size)->used += primary_stacksize; ppu->cmd_push({ppu_cmd::initialize, 0}); - if (!entry) + if (!entry && g_ps3_process_info.get_cellos_appname() != "vsh.self"sv) { // Set TLS args, call sys_initialize_tls ppu->cmd_list @@ -1731,7 +1743,10 @@ bool ppu_load_exec(const ppu_exec_object& elf) { ppu_cmd::set_args, 4 }, u64{ppu->id}, u64{tls_vaddr}, u64{tls_fsize}, u64{tls_vsize}, { ppu_cmd::hle_call, FIND_FUNC(sys_initialize_tls) }, }); + } + if (!entry) + { entry = static_cast(elf.header.e_entry); // Run entry from elf } diff --git a/rpcs3/Emu/Cell/lv2/sys_process.cpp b/rpcs3/Emu/Cell/lv2/sys_process.cpp index 152ed7e8de..c8f4dbbea5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_process.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_process.cpp @@ -45,6 +45,17 @@ bool ps3_process_info_t::has_debug_perm() const return (ctrl_flags1 & (0xa << 28)) != 0; } +// If a SELF file is of CellOS return its filename, otheriwse return an empty string +std::string_view ps3_process_info_t::get_cellos_appname() const +{ + if (!has_root_perm() || !Emu.GetTitleID().empty()) + { + return {}; + } + + return std::string_view(Emu.GetBoot()).substr(Emu.GetBoot().find_last_of('/') + 1); +} + LOG_CHANNEL(sys_process); ps3_process_info_t g_ps3_process_info; diff --git a/rpcs3/Emu/Cell/lv2/sys_process.h b/rpcs3/Emu/Cell/lv2/sys_process.h index 3ce1714a5d..1bc732d207 100644 --- a/rpcs3/Emu/Cell/lv2/sys_process.h +++ b/rpcs3/Emu/Cell/lv2/sys_process.h @@ -48,6 +48,7 @@ struct ps3_process_info_t bool has_root_perm() const; bool has_debug_perm() const; bool debug_or_root() const; + std::string_view get_cellos_appname() const; }; extern ps3_process_info_t g_ps3_process_info;