aboutsummaryrefslogtreecommitdiff
path: root/src/core/loader/nca.cpp
diff options
context:
space:
mode:
authorMrPurple666 <antoniosacramento666usa@gmail.com>2025-04-30 16:19:06 -0300
committerMrPurple666 <antoniosacramento666usa@gmail.com>2025-04-30 16:19:06 -0300
commit7bd606bece182715d877fe5bbfb73daaac6546b7 (patch)
tree9ac3698b78005301e4e69a28369a9d7afeb55e5e /src/core/loader/nca.cpp
parentbb2f527b162372d6b63bbd5cc768f3e82dac0c5c (diff)
parent4cf41673ba0a1861d7409f9bfe7c6cc3ff170564 (diff)
Merge https://git.eden-emu.dev/eden-emu/eden
Diffstat (limited to 'src/core/loader/nca.cpp')
-rw-r--r--src/core/loader/nca.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp
index de27ec49e2..4a87ab53e7 100644
--- a/src/core/loader/nca.cpp
+++ b/src/core/loader/nca.cpp
@@ -15,9 +15,20 @@
#include "core/loader/deconstructed_rom_directory.h"
#include "core/loader/nca.h"
#include "mbedtls/sha256.h"
+#include "common/literals.h"
namespace Loader {
+static u32 CalculatePointerBufferSize(size_t heap_size) {
+ if (heap_size > 1073741824) { // Games with 1 GiB
+ return 0x10000;
+ } else if (heap_size > 536870912) { // Games with 512 MiB
+ return 0xC000;
+ } else {
+ return 0x8000; // Default for all other games
+ }
+}
+
AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file_)
: AppLoader(std::move(file_)), nca(std::make_unique<FileSys::NCA>(file)) {}
@@ -52,8 +63,6 @@ AppLoader_NCA::LoadResult AppLoader_NCA::Load(Kernel::KProcess& process, Core::S
if (exefs == nullptr) {
LOG_INFO(Loader, "No ExeFS found in NCA, looking for ExeFS from update");
- // This NCA may be a sparse base of an installed title.
- // Try to fetch the ExeFS from the installed update.
const auto& installed = system.GetContentProvider();
const auto update_nca = installed.GetEntry(FileSys::GetUpdateTitleID(nca->GetTitleId()),
FileSys::ContentRecordType::Program);
@@ -69,11 +78,37 @@ AppLoader_NCA::LoadResult AppLoader_NCA::Load(Kernel::KProcess& process, Core::S
directory_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(exefs, true);
+ // Read heap size from main.npdm in ExeFS
+ u64 heap_size = 0;
+
+ if (exefs) {
+ const auto npdm_file = exefs->GetFile("main.npdm");
+ if (npdm_file) {
+ auto npdm_data = npdm_file->ReadAllBytes();
+ if (npdm_data.size() >= 0x30) {
+ heap_size = *reinterpret_cast<const u64*>(&npdm_data[0x28]);
+ LOG_INFO(Loader, "Read heap size {:#x} bytes from main.npdm", heap_size);
+ } else {
+ LOG_WARNING(Loader, "main.npdm too small to read heap size!");
+ }
+ } else {
+ LOG_WARNING(Loader, "No main.npdm found in ExeFS!");
+ }
+ }
+
+ // Set pointer buffer size based on heap size
+ process.SetPointerBufferSize(CalculatePointerBufferSize(heap_size));
+
+ // Load modules
const auto load_result = directory_loader->Load(process, system);
if (load_result.first != ResultStatus::Success) {
return load_result;
}
+ LOG_INFO(Loader, "Set pointer buffer size to {:#x} bytes for ProgramID {:#018x} (Heap size: {:#x})",
+ process.GetPointerBufferSize(), nca->GetTitleId(), heap_size);
+
+ // Register the process in the file system controller
system.GetFileSystemController().RegisterProcess(
process.GetProcessId(), nca->GetTitleId(),
std::make_shared<FileSys::RomFSFactory>(*this, system.GetContentProvider(),