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.
This commit is contained in:
Zach Hilman 2018-11-09 20:04:07 -05:00
parent 76d515327b
commit c7b6c9de9c
2 changed files with 62 additions and 64 deletions

View file

@ -587,87 +587,59 @@ private:
} }
}; };
class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> { IStorageAccessor::IStorageAccessor(IStorage& storage)
public: : ServiceFramework("IStorageAccessor"), backing(storage) {
explicit ILibraryAppletAccessor() : ServiceFramework("ILibraryAppletAccessor") {
// clang-format off // clang-format off
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"}, {0, &IStorageAccessor::GetSize, "GetSize"},
{1, nullptr, "IsCompleted"}, {10, &IStorageAccessor::Write, "Write"},
{10, &ILibraryAppletAccessor::Start, "Start"}, {11, &IStorageAccessor::Read, "Read"},
{20, nullptr, "RequestExit"},
{25, nullptr, "Terminate"},
{30, &ILibraryAppletAccessor::GetResult, "GetResult"},
{50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"},
{100, &ILibraryAppletAccessor::PushInData, "PushInData"},
{101, &ILibraryAppletAccessor::PopOutData, "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"},
}; };
// clang-format on // clang-format on
RegisterHandlers(functions); RegisterHandlers(functions);
}
auto& kernel = Core::System::GetInstance().Kernel(); void IStorageAccessor::GetSize(Kernel::HLERequestContext& ctx) {
state_changed_event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, IPC::ResponseBuilder rb{ctx, 4};
"ILibraryAppletAccessor:StateChangedEvent");
}
private:
void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
state_changed_event->Signal();
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(state_changed_event); rb.Push(static_cast<u64>(backing.buffer.size()));
LOG_WARNING(Service_AM, "(STUBBED) called"); LOG_DEBUG(Service_AM, "called");
} }
void GetResult(Kernel::HLERequestContext& ctx) { void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_AM, "(STUBBED) called");
}
void Start(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_AM, "(STUBBED) called");
}
void PushInData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
storage_stack.push(rp.PopIpcInterface<AM::IStorage>());
const u64 offset{rp.Pop<u64>()};
const std::vector<u8> data{ctx.ReadBuffer()};
const auto size = std::min<std::size_t>(data.size(), backing.buffer.size() - offset);
std::memcpy(&backing.buffer[offset], data.data(), size);
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
LOG_DEBUG(Service_AM, "called"); LOG_DEBUG(Service_AM, "called, offset={}", offset);
} }
void PopOutData(Kernel::HLERequestContext& ctx) { void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 2, 0, 1}; IPC::RequestParser rp{ctx};
const u64 offset{rp.Pop<u64>()};
std::size_t size{ctx.GetWriteBufferSize()};
size = std::min<std::size_t>(size, backing.buffer.size() - offset);
ctx.WriteBuffer(backing.buffer.data() + offset, size);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.PushIpcInterface<AM::IStorage>(std::move(storage_stack.top()));
storage_stack.pop(); LOG_DEBUG(Service_AM, "called, offset={}", offset);
}
LOG_DEBUG(Service_AM, "called");
}
std::stack<std::shared_ptr<AM::IStorage>> storage_stack;
Kernel::SharedPtr<Kernel::Event> state_changed_event;
};
ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") { ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
@ -675,7 +647,7 @@ ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryApple
{1, nullptr, "TerminateAllLibraryApplets"}, {1, nullptr, "TerminateAllLibraryApplets"},
{2, nullptr, "AreAnyLibraryAppletsLeft"}, {2, nullptr, "AreAnyLibraryAppletsLeft"},
{10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"}, {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"},
{11, nullptr, "CreateTransferMemoryStorage"}, {11, &ILibraryAppletCreator::CreateTransferMemoryStorage, "CreateTransferMemoryStorage"},
{12, nullptr, "CreateHandleStorage"}, {12, nullptr, "CreateHandleStorage"},
}; };
RegisterHandlers(functions); RegisterHandlers(functions);

View file

@ -155,6 +155,32 @@ private:
std::shared_ptr<AppletMessageQueue> msg_queue; std::shared_ptr<AppletMessageQueue> msg_queue;
}; };
class IStorage final : public ServiceFramework<IStorage> {
public:
explicit IStorage(std::vector<u8> buffer);
const std::vector<u8>& GetData() const;
private:
std::vector<u8> buffer;
void Open(Kernel::HLERequestContext& ctx);
friend class IStorageAccessor;
};
class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
public:
explicit IStorageAccessor(IStorage& backing);
private:
IStorage& backing;
void GetSize(Kernel::HLERequestContext& ctx);
void Write(Kernel::HLERequestContext& ctx);
void Read(Kernel::HLERequestContext& ctx);
};
class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> { class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> {
public: public:
ILibraryAppletCreator(); ILibraryAppletCreator();