mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-24 10:23:01 -06:00
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:
parent
76d515327b
commit
c7b6c9de9c
2 changed files with 62 additions and 64 deletions
|
@ -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:
|
rb.Push(RESULT_SUCCESS);
|
||||||
void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
|
rb.Push(static_cast<u64>(backing.buffer.size()));
|
||||||
state_changed_event->Signal();
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 1};
|
LOG_DEBUG(Service_AM, "called");
|
||||||
rb.Push(RESULT_SUCCESS);
|
}
|
||||||
rb.PushCopyObjects(state_changed_event);
|
|
||||||
|
|
||||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) {
|
||||||
}
|
IPC::RequestParser rp{ctx};
|
||||||
|
|
||||||
void GetResult(Kernel::HLERequestContext& ctx) {
|
const u64 offset{rp.Pop<u64>()};
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
const std::vector<u8> data{ctx.ReadBuffer()};
|
||||||
rb.Push(RESULT_SUCCESS);
|
|
||||||
|
|
||||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
const auto size = std::min<std::size_t>(data.size(), backing.buffer.size() - offset);
|
||||||
}
|
|
||||||
|
|
||||||
void Start(Kernel::HLERequestContext& ctx) {
|
std::memcpy(&backing.buffer[offset], data.data(), size);
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
|
||||||
|
|
||||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
}
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
|
||||||
void PushInData(Kernel::HLERequestContext& ctx) {
|
LOG_DEBUG(Service_AM, "called, offset={}", offset);
|
||||||
IPC::RequestParser rp{ctx};
|
}
|
||||||
storage_stack.push(rp.PopIpcInterface<AM::IStorage>());
|
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) {
|
||||||
rb.Push(RESULT_SUCCESS);
|
IPC::RequestParser rp{ctx};
|
||||||
|
|
||||||
LOG_DEBUG(Service_AM, "called");
|
const u64 offset{rp.Pop<u64>()};
|
||||||
}
|
std::size_t size{ctx.GetWriteBufferSize()};
|
||||||
|
|
||||||
void PopOutData(Kernel::HLERequestContext& ctx) {
|
size = std::min<std::size_t>(size, backing.buffer.size() - offset);
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
|
||||||
rb.PushIpcInterface<AM::IStorage>(std::move(storage_stack.top()));
|
|
||||||
|
|
||||||
storage_stack.pop();
|
ctx.WriteBuffer(backing.buffer.data() + offset, size);
|
||||||
|
|
||||||
LOG_DEBUG(Service_AM, "called");
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
}
|
rb.Push(RESULT_SUCCESS);
|
||||||
|
|
||||||
std::stack<std::shared_ptr<AM::IStorage>> storage_stack;
|
LOG_DEBUG(Service_AM, "called, offset={}", offset);
|
||||||
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);
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue