From 90c43aa2e7108f0f20bb503083b05ca415b994e5 Mon Sep 17 00:00:00 2001 From: Leystryku Date: Sat, 17 Feb 2024 22:26:03 +0100 Subject: [PATCH 1/6] service: Add GetCacheStorageMax stub to IApplicationFunctions --- .../hle/service/am/service/application_functions.cpp | 12 +++++++++++- .../hle/service/am/service/application_functions.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index b788fddd47..ac3b0066e0 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -40,7 +40,7 @@ IApplicationFunctions::IApplicationFunctions(Core::System& system_, std::shared_ {26, D<&IApplicationFunctions::GetSaveDataSize>, "GetSaveDataSize"}, {27, D<&IApplicationFunctions::CreateCacheStorage>, "CreateCacheStorage"}, {28, D<&IApplicationFunctions::GetSaveDataSizeMax>, "GetSaveDataSizeMax"}, - {29, nullptr, "GetCacheStorageMax"}, + {29, D<&IApplicationFunctions::GetCacheStorageMax>, "GetCacheStorageMax"}, {30, D<&IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed>, "BeginBlockingHomeButtonShortAndLongPressed"}, {31, D<&IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed>, "EndBlockingHomeButtonShortAndLongPressed"}, {32, D<&IApplicationFunctions::BeginBlockingHomeButton>, "BeginBlockingHomeButton"}, @@ -267,6 +267,16 @@ Result IApplicationFunctions::GetSaveDataSizeMax(Out out_max_normal_size, R_SUCCEED(); } +Result IApplicationFunctions::GetCacheStorageMax(Out out_max_normal_size, + Out out_max_journal_size) { + LOG_WARNING(Service_AM, "(STUBBED) called"); + + *out_max_normal_size = 0xFFFFFF; + *out_max_journal_size = 0xFFFFFF; + + R_SUCCEED(); +} + Result IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(s64 unused) { LOG_WARNING(Service_AM, "(STUBBED) called"); diff --git a/src/core/hle/service/am/service/application_functions.h b/src/core/hle/service/am/service/application_functions.h index 3548202f87..c86f0d8aca 100644 --- a/src/core/hle/service/am/service/application_functions.h +++ b/src/core/hle/service/am/service/application_functions.h @@ -40,6 +40,7 @@ private: Result CreateCacheStorage(Out out_target_media, Out out_required_size, u16 index, u64 normal_size, u64 journal_size); Result GetSaveDataSizeMax(Out out_max_normal_size, Out out_max_journal_size); + Result GetCacheStorageMax(Out out_max_normal_size, Out out_max_journal_size); Result BeginBlockingHomeButtonShortAndLongPressed(s64 unused); Result EndBlockingHomeButtonShortAndLongPressed(); Result BeginBlockingHomeButton(s64 timeout_ns); From 82949085c0e14bbddbc9b39ae077cfd3338a230f Mon Sep 17 00:00:00 2001 From: Leystryku Date: Sun, 18 Feb 2024 00:52:22 +0100 Subject: [PATCH 2/6] fsp: Add FlushAccessLogOnSdCard stub --- src/core/hle/service/filesystem/fsp/fsp_srv.cpp | 11 +++++++++-- src/core/hle/service/filesystem/fsp/fsp_srv.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/filesystem/fsp/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp/fsp_srv.cpp index 63c2d3a58f..e1238527e8 100644 --- a/src/core/hle/service/filesystem/fsp/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp/fsp_srv.cpp @@ -336,7 +336,7 @@ FSP_SRV::FSP_SRV(Core::System& system_) {1012, nullptr, "GetFsStackUsage"}, {1013, nullptr, "UnsetSaveDataRootPath"}, {1014, nullptr, "OutputMultiProgramTagAccessLog"}, - {1016, nullptr, "FlushAccessLogOnSdCard"}, + {1016, &FSP_SRV::FlushAccessLogOnSdCard, "FlushAccessLogOnSdCard"}, {1017, nullptr, "OutputApplicationInfoAccessLog"}, {1018, nullptr, "SetDebugOption"}, {1019, nullptr, "UnsetDebugOption"}, @@ -706,6 +706,13 @@ void FSP_SRV::GetProgramIndexForAccessLog(HLERequestContext& ctx) { rb.Push(access_log_program_index); } +void FSP_SRV::FlushAccessLogOnSdCard(HLERequestContext& ctx) { + LOG_DEBUG(Service_FS, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + void FSP_SRV::GetCacheStorageSize(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto index{rp.Pop()}; @@ -755,4 +762,4 @@ void FSP_SRV::OpenMultiCommitManager(HLERequestContext& ctx) { rb.PushIpcInterface(std::make_shared(system)); } -} // namespace Service::FileSystem +} // namespace Service::FileSystem \ No newline at end of file diff --git a/src/core/hle/service/filesystem/fsp/fsp_srv.h b/src/core/hle/service/filesystem/fsp/fsp_srv.h index 26980af99c..59406e6f95 100644 --- a/src/core/hle/service/filesystem/fsp/fsp_srv.h +++ b/src/core/hle/service/filesystem/fsp/fsp_srv.h @@ -58,6 +58,7 @@ private: void SetGlobalAccessLogMode(HLERequestContext& ctx); void GetGlobalAccessLogMode(HLERequestContext& ctx); void OutputAccessLogToSdCard(HLERequestContext& ctx); + void FlushAccessLogOnSdCard(HLERequestContext& ctx); void GetProgramIndexForAccessLog(HLERequestContext& ctx); void OpenMultiCommitManager(HLERequestContext& ctx); void GetCacheStorageSize(HLERequestContext& ctx); From d93fdc8a6ca246928fde7b76b41fc9aae487e31a Mon Sep 17 00:00:00 2001 From: Leystryku Date: Sun, 18 Feb 2024 05:02:35 +0100 Subject: [PATCH 3/6] service: Add proper GetCacheStorageMax implementation to IApplicationFunctions --- .../am/service/application_functions.cpp | 20 ++++++++++++++----- .../am/service/application_functions.h | 2 +- .../hle/service/filesystem/fsp/fsp_srv.cpp | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index ac3b0066e0..eee9428ce7 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -17,6 +17,7 @@ #include "core/hle/service/filesystem/save_data_controller.h" #include "core/hle/service/ns/ns.h" #include "core/hle/service/sm/sm.h" +#include "core/hle/service/glue/glue_manager.h" namespace Service::AM { @@ -267,14 +268,23 @@ Result IApplicationFunctions::GetSaveDataSizeMax(Out out_max_normal_size, R_SUCCEED(); } -Result IApplicationFunctions::GetCacheStorageMax(Out out_max_normal_size, +Result IApplicationFunctions::GetCacheStorageMax(Out out_cache_storage_index_max, Out out_max_journal_size) { - LOG_WARNING(Service_AM, "(STUBBED) called"); + LOG_DEBUG(Service_AM, "called"); - *out_max_normal_size = 0xFFFFFF; - *out_max_journal_size = 0xFFFFFF; + const auto title_id = m_applet->program_id; - R_SUCCEED(); + std::vector nacp; + const auto result = system.GetARPManager().GetControlProperty(&nacp, title_id); + + if (R_SUCCEEDED(result)) { + const auto rawnacp = reinterpret_cast(nacp.data()); + + *out_cache_storage_index_max = static_cast(rawnacp->cache_storage_max_index); + *out_max_journal_size = static_cast(rawnacp->cache_storage_data_and_journal_max_size); + } + + R_SUCCEED(); } Result IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(s64 unused) { diff --git a/src/core/hle/service/am/service/application_functions.h b/src/core/hle/service/am/service/application_functions.h index c86f0d8aca..10025a152b 100644 --- a/src/core/hle/service/am/service/application_functions.h +++ b/src/core/hle/service/am/service/application_functions.h @@ -40,7 +40,7 @@ private: Result CreateCacheStorage(Out out_target_media, Out out_required_size, u16 index, u64 normal_size, u64 journal_size); Result GetSaveDataSizeMax(Out out_max_normal_size, Out out_max_journal_size); - Result GetCacheStorageMax(Out out_max_normal_size, Out out_max_journal_size); + Result GetCacheStorageMax(Out out_cache_storage_index_max, Out out_max_journal_size); Result BeginBlockingHomeButtonShortAndLongPressed(s64 unused); Result EndBlockingHomeButtonShortAndLongPressed(); Result BeginBlockingHomeButton(s64 timeout_ns); diff --git a/src/core/hle/service/filesystem/fsp/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp/fsp_srv.cpp index e1238527e8..2d49f30c86 100644 --- a/src/core/hle/service/filesystem/fsp/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp/fsp_srv.cpp @@ -762,4 +762,4 @@ void FSP_SRV::OpenMultiCommitManager(HLERequestContext& ctx) { rb.PushIpcInterface(std::make_shared(system)); } -} // namespace Service::FileSystem \ No newline at end of file +} // namespace Service::FileSystem From 4f387b0b74138e033b88fbe4e137d6ab8c7130ac Mon Sep 17 00:00:00 2001 From: Leystryku Date: Sun, 18 Feb 2024 06:00:42 +0100 Subject: [PATCH 4/6] file_sys: Fix nacp field cache_storage_max_index datatype --- src/core/file_sys/control_metadata.h | 4 ++-- .../service/am/service/application_functions.cpp | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/core/file_sys/control_metadata.h b/src/core/file_sys/control_metadata.h index 555b9d8f74..667efbbab4 100644 --- a/src/core/file_sys/control_metadata.h +++ b/src/core/file_sys/control_metadata.h @@ -64,8 +64,8 @@ struct RawNACP { u64_le cache_storage_size; u64_le cache_storage_journal_size; u64_le cache_storage_data_and_journal_max_size; - u64_le cache_storage_max_index; - INSERT_PADDING_BYTES(0xE70); + u16_le cache_storage_max_index; + INSERT_PADDING_BYTES(0xE76); }; static_assert(sizeof(RawNACP) == 0x4000, "RawNACP has incorrect size."); diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index eee9428ce7..fe37083f3a 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -272,17 +272,14 @@ Result IApplicationFunctions::GetCacheStorageMax(Out out_cache_storage_inde Out out_max_journal_size) { LOG_DEBUG(Service_AM, "called"); - const auto title_id = m_applet->program_id; - std::vector nacp; - const auto result = system.GetARPManager().GetControlProperty(&nacp, title_id); + R_TRY(system.GetARPManager().GetControlProperty(&nacp, m_applet->program_id)); - if (R_SUCCEEDED(result)) { - const auto rawnacp = reinterpret_cast(nacp.data()); + FileSys::RawNACP raw_nacp{}; + std::memcpy(&raw_nacp, nacp.data(), std::min(sizeof(raw_nacp), nacp.size())); - *out_cache_storage_index_max = static_cast(rawnacp->cache_storage_max_index); - *out_max_journal_size = static_cast(rawnacp->cache_storage_data_and_journal_max_size); - } + *out_cache_storage_index_max = static_cast(raw_nacp.cache_storage_max_index); + *out_max_journal_size = static_cast(raw_nacp.cache_storage_data_and_journal_max_size); R_SUCCEED(); } From bc5ae04ea080dff5609fb9833799b1618d715555 Mon Sep 17 00:00:00 2001 From: Leystryku Date: Sun, 18 Feb 2024 06:17:35 +0100 Subject: [PATCH 5/6] file_sys: Formatting changes and use unique_ptr in GetCacheStorageMax --- .../hle/service/am/service/application_functions.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index fe37083f3a..7507263b21 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -15,9 +15,9 @@ #include "core/hle/service/cmif_serialization.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/save_data_controller.h" +#include "core/hle/service/glue/glue_manager.h" #include "core/hle/service/ns/ns.h" #include "core/hle/service/sm/sm.h" -#include "core/hle/service/glue/glue_manager.h" namespace Service::AM { @@ -275,13 +275,13 @@ Result IApplicationFunctions::GetCacheStorageMax(Out out_cache_storage_inde std::vector nacp; R_TRY(system.GetARPManager().GetControlProperty(&nacp, m_applet->program_id)); - FileSys::RawNACP raw_nacp{}; - std::memcpy(&raw_nacp, nacp.data(), std::min(sizeof(raw_nacp), nacp.size())); + std::unique_ptr raw_nacp(new FileSys::RawNACP{}); + std::memcpy(raw_nacp.get(), nacp.data(), std::min(sizeof(*raw_nacp), nacp.size())); - *out_cache_storage_index_max = static_cast(raw_nacp.cache_storage_max_index); - *out_max_journal_size = static_cast(raw_nacp.cache_storage_data_and_journal_max_size); + *out_cache_storage_index_max = static_cast(raw_nacp->cache_storage_max_index); + *out_max_journal_size = static_cast(raw_nacp->cache_storage_data_and_journal_max_size); - R_SUCCEED(); + R_SUCCEED(); } Result IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(s64 unused) { From 8bbb44a74e74134084475174a96649323fd73123 Mon Sep 17 00:00:00 2001 From: Leystryku Date: Sun, 18 Feb 2024 07:03:50 +0100 Subject: [PATCH 6/6] service: Change unique_ptr to make_unique in GetCacheStorageMax --- src/core/hle/service/am/service/application_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index 7507263b21..63dd12a475 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -275,7 +275,7 @@ Result IApplicationFunctions::GetCacheStorageMax(Out out_cache_storage_inde std::vector nacp; R_TRY(system.GetARPManager().GetControlProperty(&nacp, m_applet->program_id)); - std::unique_ptr raw_nacp(new FileSys::RawNACP{}); + auto raw_nacp = std::make_unique(); std::memcpy(raw_nacp.get(), nacp.data(), std::min(sizeof(*raw_nacp), nacp.size())); *out_cache_storage_index_max = static_cast(raw_nacp->cache_storage_max_index);