From d73c22bf4d975379d0e379f4f03398f102e7836d Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 3 Jun 2018 14:19:24 -0400 Subject: [PATCH 1/4] am: Implement ILibraryAppletCreator::CreateStorage. --- src/core/hle/service/am/am.cpp | 54 +++++++++++++++++++++------------- src/core/hle/service/am/am.h | 1 + 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 6b1d6bf97..9434512d8 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -391,27 +391,6 @@ private: Kernel::SharedPtr state_changed_event; }; -ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") { - static const FunctionInfo functions[] = { - {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"}, - {1, nullptr, "TerminateAllLibraryApplets"}, - {2, nullptr, "AreAnyLibraryAppletsLeft"}, - {10, nullptr, "CreateStorage"}, - {11, nullptr, "CreateTransferMemoryStorage"}, - {12, nullptr, "CreateHandleStorage"}, - }; - RegisterHandlers(functions); -} - -void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) { - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - - rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface(); - - NGLOG_DEBUG(Service_AM, "called"); -} - class IStorageAccessor final : public ServiceFramework { public: explicit IStorageAccessor(std::vector buffer) @@ -479,6 +458,39 @@ private: } }; +ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") { + static const FunctionInfo functions[] = { + {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"}, + {1, nullptr, "TerminateAllLibraryApplets"}, + {2, nullptr, "AreAnyLibraryAppletsLeft"}, + {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"}, + {11, nullptr, "CreateTransferMemoryStorage"}, + {12, nullptr, "CreateHandleStorage"}, + }; + RegisterHandlers(functions); +} + +void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) { + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; + + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface(); + + NGLOG_DEBUG(Service_AM, "called"); +} + +void ILibraryAppletCreator::CreateStorage(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const u64 size{rp.Pop()}; + std::vector buffer(size); + + IPC::ResponseBuilder rb{rp.MakeBuilder(2, 0, 1)}; + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface(std::move(buffer)); + + NGLOG_DEBUG(Service_AM, "called, size={}", size); +} + IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationFunctions") { static const FunctionInfo functions[] = { {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index ff8eb14d7..301a6c798 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -121,6 +121,7 @@ public: private: void CreateLibraryApplet(Kernel::HLERequestContext& ctx); + void CreateStorage(Kernel::HLERequestContext& ctx); }; class IApplicationFunctions final : public ServiceFramework { From 9fedfbe141715f75719339724cc6a0aa7875145c Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 3 Jun 2018 14:21:05 -0400 Subject: [PATCH 2/4] am: Cleanup IStorageAccessor::Read. --- src/core/hle/service/am/am.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 9434512d8..26fd8c933 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -418,19 +418,17 @@ private: void Read(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - u64 offset = rp.Pop(); - + const u64 offset{rp.Pop()}; const size_t size{ctx.GetWriteBufferSize()}; ASSERT(offset + size <= buffer.size()); ctx.WriteBuffer(buffer.data() + offset, size); - IPC::ResponseBuilder rb{ctx, 2}; - + IPC::ResponseBuilder rb{rp.MakeBuilder(2, 0, 0)}; rb.Push(RESULT_SUCCESS); - NGLOG_DEBUG(Service_AM, "called"); + NGLOG_DEBUG(Service_AM, "called, offset={}", offset); } }; From 2dcb98226b6e8222d073d9ee1e247bb116ac1d2c Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 3 Jun 2018 14:21:45 -0400 Subject: [PATCH 3/4] am: Implement IStorageAccessor::Write. --- src/core/hle/service/am/am.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 26fd8c933..c47228935 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -397,7 +397,7 @@ public: : ServiceFramework("IStorageAccessor"), buffer(std::move(buffer)) { static const FunctionInfo functions[] = { {0, &IStorageAccessor::GetSize, "GetSize"}, - {10, nullptr, "Write"}, + {10, &IStorageAccessor::Write, "Write"}, {11, &IStorageAccessor::Read, "Read"}, }; RegisterHandlers(functions); @@ -415,6 +415,22 @@ private: NGLOG_DEBUG(Service_AM, "called"); } + void Write(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + const u64 offset{rp.Pop()}; + const std::vector data{ctx.ReadBuffer()}; + + ASSERT(offset + data.size() <= buffer.size()); + + std::memcpy(&buffer[offset], data.data(), data.size()); + + IPC::ResponseBuilder rb{rp.MakeBuilder(2, 0, 0)}; + rb.Push(RESULT_SUCCESS); + + NGLOG_DEBUG(Service_AM, "called, offset={}", offset); + } + void Read(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; From 876b805e50f77a837304baa6015e5c506bf2df22 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 3 Jun 2018 14:23:44 -0400 Subject: [PATCH 4/4] am: Implement ILibraryAppletAccessor::PushInData. --- src/core/hle/service/am/am.cpp | 98 +++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index c47228935..40922ec3a 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "core/file_sys/filesystem.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/event.h" @@ -348,49 +349,6 @@ void ICommonStateGetter::GetPerformanceMode(Kernel::HLERequestContext& ctx) { NGLOG_WARNING(Service_AM, "(STUBBED) called"); } -class ILibraryAppletAccessor final : public ServiceFramework { -public: - explicit ILibraryAppletAccessor() : ServiceFramework("ILibraryAppletAccessor") { - static const FunctionInfo functions[] = { - {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, - {1, nullptr, "IsCompleted"}, - {10, nullptr, "Start"}, - {20, nullptr, "RequestExit"}, - {25, nullptr, "Terminate"}, - {30, nullptr, "GetResult"}, - {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"}, - {100, nullptr, "PushInData"}, - {101, nullptr, "PopOutData"}, - {102, nullptr, "PushExtraStorage"}, - {103, nullptr, "PushInteractiveInData"}, - {104, nullptr, "PopInteractiveOutData"}, - {105, nullptr, "GetPopOutDataEvent"}, - {106, nullptr, "GetPopInteractiveOutDataEvent"}, - {110, nullptr, "NeedsToExitProcess"}, - {120, nullptr, "GetLibraryAppletInfo"}, - {150, nullptr, "RequestForAppletToGetForeground"}, - {160, nullptr, "GetIndirectLayerConsumerHandle"}, - }; - RegisterHandlers(functions); - - state_changed_event = Kernel::Event::Create(Kernel::ResetType::OneShot, - "ILibraryAppletAccessor:StateChangedEvent"); - } - -private: - void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { - state_changed_event->Signal(); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(RESULT_SUCCESS); - rb.PushCopyObjects(state_changed_event); - - NGLOG_WARNING(Service_AM, "(STUBBED) called"); - } - - Kernel::SharedPtr state_changed_event; -}; - class IStorageAccessor final : public ServiceFramework { public: explicit IStorageAccessor(std::vector buffer) @@ -472,6 +430,60 @@ private: } }; +class ILibraryAppletAccessor final : public ServiceFramework { +public: + explicit ILibraryAppletAccessor() : ServiceFramework("ILibraryAppletAccessor") { + static const FunctionInfo functions[] = { + {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, + {1, nullptr, "IsCompleted"}, + {10, nullptr, "Start"}, + {20, nullptr, "RequestExit"}, + {25, nullptr, "Terminate"}, + {30, nullptr, "GetResult"}, + {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"}, + {100, &ILibraryAppletAccessor::PushInData, "PushInData"}, + {101, nullptr, "PopOutData"}, + {102, nullptr, "PushExtraStorage"}, + {103, nullptr, "PushInteractiveInData"}, + {104, nullptr, "PopInteractiveOutData"}, + {105, nullptr, "GetPopOutDataEvent"}, + {106, nullptr, "GetPopInteractiveOutDataEvent"}, + {110, nullptr, "NeedsToExitProcess"}, + {120, nullptr, "GetLibraryAppletInfo"}, + {150, nullptr, "RequestForAppletToGetForeground"}, + {160, nullptr, "GetIndirectLayerConsumerHandle"}, + }; + RegisterHandlers(functions); + + state_changed_event = Kernel::Event::Create(Kernel::ResetType::OneShot, + "ILibraryAppletAccessor:StateChangedEvent"); + } + +private: + void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { + state_changed_event->Signal(); + + IPC::ResponseBuilder rb{ctx, 2, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushCopyObjects(state_changed_event); + + NGLOG_WARNING(Service_AM, "(STUBBED) called"); + } + + void PushInData(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + storage_stack.push(rp.PopIpcInterface()); + + IPC::ResponseBuilder rb{rp.MakeBuilder(2, 0, 0)}; + rb.Push(RESULT_SUCCESS); + + NGLOG_DEBUG(Service_AM, "called"); + } + + std::stack> storage_stack; + Kernel::SharedPtr state_changed_event; +}; + ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") { static const FunctionInfo functions[] = { {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"},