summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-11-09 20:04:07 -0500
committerGravatar Zach Hilman2018-11-18 10:53:47 -0500
commitc7b6c9de9c4004399edf8a010b74fee1127c7682 (patch)
treee2dfda01fbe3391a592d10007c75842d4f3b5ab4 /src
parentam: Implement CreateTransferMemoryStorage (diff)
downloadyuzu-c7b6c9de9c4004399edf8a010b74fee1127c7682.tar.gz
yuzu-c7b6c9de9c4004399edf8a010b74fee1127c7682.tar.xz
yuzu-c7b6c9de9c4004399edf8a010b74fee1127c7682.zip
am: Move IStorageAccessor to header and update backing buffer
Writes to an AM::IStorage object through an IStorageAccessor will now be preserved once the accessor is destroyed.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/am/am.cpp100
-rw-r--r--src/core/hle/service/am/am.h26
2 files changed, 62 insertions, 64 deletions
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index a7716d80b..c7344608c 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -587,87 +587,59 @@ private:
587 } 587 }
588}; 588};
589 589
590class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> { 590IStorageAccessor::IStorageAccessor(IStorage& storage)
591public: 591 : ServiceFramework("IStorageAccessor"), backing(storage) {
592 explicit ILibraryAppletAccessor() : ServiceFramework("ILibraryAppletAccessor") { 592 // clang-format off
593 // clang-format off
594 static const FunctionInfo functions[] = { 593 static const FunctionInfo functions[] = {
595 {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, 594 {0, &IStorageAccessor::GetSize, "GetSize"},
596 {1, nullptr, "IsCompleted"}, 595 {10, &IStorageAccessor::Write, "Write"},
597 {10, &ILibraryAppletAccessor::Start, "Start"}, 596 {11, &IStorageAccessor::Read, "Read"},
598 {20, nullptr, "RequestExit"},
599 {25, nullptr, "Terminate"},
600 {30, &ILibraryAppletAccessor::GetResult, "GetResult"},
601 {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"},
602 {100, &ILibraryAppletAccessor::PushInData, "PushInData"},
603 {101, &ILibraryAppletAccessor::PopOutData, "PopOutData"},
604 {102, nullptr, "PushExtraStorage"},
605 {103, nullptr, "PushInteractiveInData"},
606 {104, nullptr, "PopInteractiveOutData"},
607 {105, nullptr, "GetPopOutDataEvent"},
608 {106, nullptr, "GetPopInteractiveOutDataEvent"},
609 {110, nullptr, "NeedsToExitProcess"},
610 {120, nullptr, "GetLibraryAppletInfo"},
611 {150, nullptr, "RequestForAppletToGetForeground"},
612 {160, nullptr, "GetIndirectLayerConsumerHandle"},
613 }; 597 };
614 // clang-format on 598 // clang-format on
615 599
616 RegisterHandlers(functions); 600 RegisterHandlers(functions);
601}
617 602
618 auto& kernel = Core::System::GetInstance().Kernel(); 603void IStorageAccessor::GetSize(Kernel::HLERequestContext& ctx) {
619 state_changed_event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, 604 IPC::ResponseBuilder rb{ctx, 4};
620 "ILibraryAppletAccessor:StateChangedEvent");
621 }
622 605
623private: 606 rb.Push(RESULT_SUCCESS);
624 void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) { 607 rb.Push(static_cast<u64>(backing.buffer.size()));
625 state_changed_event->Signal();
626 608
627 IPC::ResponseBuilder rb{ctx, 2, 1}; 609 LOG_DEBUG(Service_AM, "called");
628 rb.Push(RESULT_SUCCESS); 610}
629 rb.PushCopyObjects(state_changed_event);
630 611
631 LOG_WARNING(Service_AM, "(STUBBED) called"); 612void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) {
632 } 613 IPC::RequestParser rp{ctx};
633 614
634 void GetResult(Kernel::HLERequestContext& ctx) { 615 const u64 offset{rp.Pop<u64>()};
635 IPC::ResponseBuilder rb{ctx, 2}; 616 const std::vector<u8> data{ctx.ReadBuffer()};
636 rb.Push(RESULT_SUCCESS);
637 617
638 LOG_WARNING(Service_AM, "(STUBBED) called"); 618 const auto size = std::min<std::size_t>(data.size(), backing.buffer.size() - offset);
639 }
640 619
641 void Start(Kernel::HLERequestContext& ctx) { 620 std::memcpy(&backing.buffer[offset], data.data(), size);
642 IPC::ResponseBuilder rb{ctx, 2};
643 rb.Push(RESULT_SUCCESS);
644 621
645 LOG_WARNING(Service_AM, "(STUBBED) called"); 622 IPC::ResponseBuilder rb{ctx, 2};
646 } 623 rb.Push(RESULT_SUCCESS);
647 624
648 void PushInData(Kernel::HLERequestContext& ctx) { 625 LOG_DEBUG(Service_AM, "called, offset={}", offset);
649 IPC::RequestParser rp{ctx}; 626}
650 storage_stack.push(rp.PopIpcInterface<AM::IStorage>());
651 627
652 IPC::ResponseBuilder rb{ctx, 2}; 628void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) {
653 rb.Push(RESULT_SUCCESS); 629 IPC::RequestParser rp{ctx};
654 630
655 LOG_DEBUG(Service_AM, "called"); 631 const u64 offset{rp.Pop<u64>()};
656 } 632 std::size_t size{ctx.GetWriteBufferSize()};
657 633
658 void PopOutData(Kernel::HLERequestContext& ctx) { 634 size = std::min<std::size_t>(size, backing.buffer.size() - offset);
659 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
660 rb.Push(RESULT_SUCCESS);
661 rb.PushIpcInterface<AM::IStorage>(std::move(storage_stack.top()));
662 635
663 storage_stack.pop(); 636 ctx.WriteBuffer(backing.buffer.data() + offset, size);
664 637
665 LOG_DEBUG(Service_AM, "called"); 638 IPC::ResponseBuilder rb{ctx, 2};
666 } 639 rb.Push(RESULT_SUCCESS);
667 640
668 std::stack<std::shared_ptr<AM::IStorage>> storage_stack; 641 LOG_DEBUG(Service_AM, "called, offset={}", offset);
669 Kernel::SharedPtr<Kernel::Event> state_changed_event; 642}
670};
671 643
672ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") { 644ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") {
673 static const FunctionInfo functions[] = { 645 static const FunctionInfo functions[] = {
@@ -675,7 +647,7 @@ ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryApple
675 {1, nullptr, "TerminateAllLibraryApplets"}, 647 {1, nullptr, "TerminateAllLibraryApplets"},
676 {2, nullptr, "AreAnyLibraryAppletsLeft"}, 648 {2, nullptr, "AreAnyLibraryAppletsLeft"},
677 {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"}, 649 {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"},
678 {11, nullptr, "CreateTransferMemoryStorage"}, 650 {11, &ILibraryAppletCreator::CreateTransferMemoryStorage, "CreateTransferMemoryStorage"},
679 {12, nullptr, "CreateHandleStorage"}, 651 {12, nullptr, "CreateHandleStorage"},
680 }; 652 };
681 RegisterHandlers(functions); 653 RegisterHandlers(functions);
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index 50b2775ea..640901e4a 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -155,6 +155,32 @@ private:
155 std::shared_ptr<AppletMessageQueue> msg_queue; 155 std::shared_ptr<AppletMessageQueue> msg_queue;
156}; 156};
157 157
158class IStorage final : public ServiceFramework<IStorage> {
159public:
160 explicit IStorage(std::vector<u8> buffer);
161
162 const std::vector<u8>& GetData() const;
163
164private:
165 std::vector<u8> buffer;
166
167 void Open(Kernel::HLERequestContext& ctx);
168
169 friend class IStorageAccessor;
170};
171
172class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
173public:
174 explicit IStorageAccessor(IStorage& backing);
175
176private:
177 IStorage& backing;
178
179 void GetSize(Kernel::HLERequestContext& ctx);
180 void Write(Kernel::HLERequestContext& ctx);
181 void Read(Kernel::HLERequestContext& ctx);
182};
183
158class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> { 184class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> {
159public: 185public:
160 ILibraryAppletCreator(); 186 ILibraryAppletCreator();