From f3f1fa46ed14e9f8d92c5ca530918804510d3479 Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Wed, 1 Apr 2026 20:17:52 +0200 Subject: [PATCH 1/7] Fix off by 1 bug --- .../libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp index e1e6cb7da..f9882515b 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp @@ -101,7 +101,7 @@ namespace ams::pgl::srv { R_TRY(this->SetExtensionType()); /* Copy in mount name. */ - R_UNLESS(strlen(mount) <= sizeof(m_mount_name) - 1, pgl::ResultBufferNotEnough()); + R_UNLESS(strlen(mount) <= sizeof(m_mount_name), pgl::ResultBufferNotEnough()); std::strcpy(m_mount_name, mount); /* Mount the package. */ From 2694f31eb3b4bb0b2dde4ec748be8da1a65cb71f Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Wed, 1 Apr 2026 20:31:47 +0200 Subject: [PATCH 2/7] Update pgl_srv_shell_host_utils.cpp --- .../source/pgl/srv/pgl_srv_shell_host_utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp index f9882515b..aed264b33 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp @@ -77,7 +77,7 @@ namespace ams::pgl::srv { private: char m_content_path[fs::EntryNameLengthMax] = {}; ExtensionType m_extension_type = ExtensionType::None; - char m_mount_name[fs::MountNameLengthMax] = {}; + char m_mount_name[fs::MountNameLengthMax+1] = {}; bool m_is_mounted = false; ncm::AutoBuffer m_content_meta_buffer; ncm::ProgramId m_program_id = ncm::InvalidProgramId; @@ -101,7 +101,7 @@ namespace ams::pgl::srv { R_TRY(this->SetExtensionType()); /* Copy in mount name. */ - R_UNLESS(strlen(mount) <= sizeof(m_mount_name), pgl::ResultBufferNotEnough()); + R_UNLESS(strlen(mount) <= sizeof(m_mount_name) - 1, pgl::ResultBufferNotEnough()); std::strcpy(m_mount_name, mount); /* Mount the package. */ From 3b9ee08c692a00966f496c457e0e1bb2e37b86d8 Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Wed, 1 Apr 2026 20:33:27 +0200 Subject: [PATCH 3/7] Update pgl_srv_shell_host_utils.cpp --- .../libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp index aed264b33..d2d88e89f 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp @@ -77,7 +77,7 @@ namespace ams::pgl::srv { private: char m_content_path[fs::EntryNameLengthMax] = {}; ExtensionType m_extension_type = ExtensionType::None; - char m_mount_name[fs::MountNameLengthMax+1] = {}; + char m_mount_name[fs::MountNameLengthMax+1] = {}; bool m_is_mounted = false; ncm::AutoBuffer m_content_meta_buffer; ncm::ProgramId m_program_id = ncm::InvalidProgramId; From 9d16ee6a74a7a350102029b40bc3b16934bd2f01 Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Wed, 1 Apr 2026 20:41:25 +0200 Subject: [PATCH 4/7] Update pgl_srv_shell_host_utils.cpp --- .../source/pgl/srv/pgl_srv_shell_host_utils.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp index d2d88e89f..f03120f2c 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp @@ -75,15 +75,15 @@ namespace ams::pgl::srv { NON_COPYABLE(HostPackageReader); NON_MOVEABLE(HostPackageReader); private: - char m_content_path[fs::EntryNameLengthMax] = {}; - ExtensionType m_extension_type = ExtensionType::None; - char m_mount_name[fs::MountNameLengthMax+1] = {}; - bool m_is_mounted = false; + char m_content_path[fs::EntryNameLengthMax + 1] = {}; + ExtensionType m_extension_type = ExtensionType::None; + char m_mount_name[fs::MountNameLengthMax + 1] = {}; + bool m_is_mounted = false; ncm::AutoBuffer m_content_meta_buffer; - ncm::ProgramId m_program_id = ncm::InvalidProgramId; - u32 m_program_version = 0; - ncm::ContentMetaType m_content_meta_type = static_cast(0); - u8 m_program_index = 0; + ncm::ProgramId m_program_id = ncm::InvalidProgramId; + u32 m_program_version = 0; + ncm::ContentMetaType m_content_meta_type = static_cast(0); + u8 m_program_index = 0; public: HostPackageReader() : m_content_meta_buffer() { /* ... */ } ~HostPackageReader() { From 4a8f7628c2a8d5fdacc52a89eedde7b26f4a43e8 Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Wed, 1 Apr 2026 20:44:08 +0200 Subject: [PATCH 5/7] Update pgl_srv_shell_host_utils.cpp --- .../source/pgl/srv/pgl_srv_shell_host_utils.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp index f03120f2c..c3ae7fe6c 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp @@ -75,15 +75,15 @@ namespace ams::pgl::srv { NON_COPYABLE(HostPackageReader); NON_MOVEABLE(HostPackageReader); private: - char m_content_path[fs::EntryNameLengthMax + 1] = {}; - ExtensionType m_extension_type = ExtensionType::None; - char m_mount_name[fs::MountNameLengthMax + 1] = {}; - bool m_is_mounted = false; + char m_content_path[fs::EntryNameLengthMax] = {}; + ExtensionType m_extension_type = ExtensionType::None; + char m_mount_name[fs::MountNameLengthMax + 1] = {}; + bool m_is_mounted = false; ncm::AutoBuffer m_content_meta_buffer; - ncm::ProgramId m_program_id = ncm::InvalidProgramId; - u32 m_program_version = 0; - ncm::ContentMetaType m_content_meta_type = static_cast(0); - u8 m_program_index = 0; + ncm::ProgramId m_program_id = ncm::InvalidProgramId; + u32 m_program_version = 0; + ncm::ContentMetaType m_content_meta_type = static_cast(0); + u8 m_program_index = 0; public: HostPackageReader() : m_content_meta_buffer() { /* ... */ } ~HostPackageReader() { From 174da786e4a8a235079ce7912cfdc1c25b1c69c0 Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Thu, 2 Apr 2026 20:45:30 +0200 Subject: [PATCH 6/7] Override new and delete operators --- stratosphere/pgl/source/pgl_main.cpp | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/stratosphere/pgl/source/pgl_main.cpp b/stratosphere/pgl/source/pgl_main.cpp index 50d5ca114..365dd3bf2 100644 --- a/stratosphere/pgl/source/pgl_main.cpp +++ b/stratosphere/pgl/source/pgl_main.cpp @@ -58,3 +58,36 @@ namespace ams { } } + +/* Override operator new. */ +void *operator new(size_t size) { + return ams::pgl::srv::Allocate(size); +} + +void *operator new(size_t size, const std::nothrow_t &) { + return ams::pgl::srv::Allocate(size); +} + +void operator delete(void *p) { + return ams::pgl::srv::Deallocate(p, 0); +} + +void operator delete(void *p, size_t size) { + return ams::pgl::srv::Deallocate(p, size); +} + +void *operator new[](size_t size) { + return ams::pgl::srv::Allocate(size); +} + +void *operator new[](size_t size, const std::nothrow_t &) { + return ams::pgl::srv::Allocate(size); +} + +void operator delete[](void *p) { + return ams::pgl::srv::Deallocate(p, 0); +} + +void operator delete[](void *p, size_t size) { + return ams::pgl::srv::Deallocate(p, size); +} From 31ca20f3b7c56eaac9a54aeabcb610bcd767ab5e Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Thu, 2 Apr 2026 21:09:15 +0200 Subject: [PATCH 7/7] Add missing libstratosphere lr::Initialize() --- stratosphere/pgl/source/pgl_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/stratosphere/pgl/source/pgl_main.cpp b/stratosphere/pgl/source/pgl_main.cpp index 365dd3bf2..a0408502e 100644 --- a/stratosphere/pgl/source/pgl_main.cpp +++ b/stratosphere/pgl/source/pgl_main.cpp @@ -37,6 +37,7 @@ namespace ams { R_ABORT_UNLESS(pmshellInitialize()); R_ABORT_UNLESS(ldrShellInitialize()); R_ABORT_UNLESS(lrInitialize()); + lr::Initialize(); /* Verify that we can sanely execute. */ ams::CheckApiVersion();