1
0
Fork 1
forked from suyu/suyu

am: rewrite IStorageAccessor, ITransferStorageAccessor

This commit is contained in:
Liam 2024-02-11 20:28:51 -05:00
parent 9e271f2017
commit 2e614ce08f
5 changed files with 82 additions and 103 deletions

View file

@ -475,14 +475,14 @@ add_library(core STATIC
hle/service/am/service/process_winding_controller.h hle/service/am/service/process_winding_controller.h
hle/service/am/service/self_controller.cpp hle/service/am/service/self_controller.cpp
hle/service/am/service/self_controller.h hle/service/am/service/self_controller.h
hle/service/am/service/storage_accessor.cpp
hle/service/am/service/storage_accessor.h
hle/service/am/service/system_applet_proxy.cpp hle/service/am/service/system_applet_proxy.cpp
hle/service/am/service/system_applet_proxy.h hle/service/am/service/system_applet_proxy.h
hle/service/am/system_buffer_manager.cpp hle/service/am/system_buffer_manager.cpp
hle/service/am/system_buffer_manager.h hle/service/am/system_buffer_manager.h
hle/service/am/spsm.cpp hle/service/am/spsm.cpp
hle/service/am/spsm.h hle/service/am/spsm.h
hle/service/am/storage_accessor.cpp
hle/service/am/storage_accessor.h
hle/service/am/storage.cpp hle/service/am/storage.cpp
hle/service/am/storage.h hle/service/am/storage.h
hle/service/am/window_controller.cpp hle/service/am/window_controller.cpp

View file

@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/service/am/library_applet_storage.h"
#include "core/hle/service/am/service/storage_accessor.h"
#include "core/hle/service/cmif_serialization.h"
namespace Service::AM {
IStorageAccessor::IStorageAccessor(Core::System& system_,
std::shared_ptr<LibraryAppletStorage> impl)
: ServiceFramework{system_, "IStorageAccessor"}, m_impl{std::move(impl)} {
static const FunctionInfo functions[] = {
{0, D<&IStorageAccessor::GetSize>, "GetSize"},
{10, D<&IStorageAccessor::Write>, "Write"},
{11, D<&IStorageAccessor::Read>, "Read"},
};
RegisterHandlers(functions);
}
IStorageAccessor::~IStorageAccessor() = default;
Result IStorageAccessor::GetSize(Out<s64> out_size) {
LOG_DEBUG(Service_AM, "called");
*out_size = m_impl->GetSize();
R_SUCCEED();
}
Result IStorageAccessor::Write(InBuffer<BufferAttr_HipcAutoSelect> buffer, s64 offset) {
LOG_DEBUG(Service_AM, "called, offset={} size={}", offset, buffer.size());
R_RETURN(m_impl->Write(offset, buffer.data(), buffer.size()));
}
Result IStorageAccessor::Read(OutBuffer<BufferAttr_HipcAutoSelect> out_buffer, s64 offset) {
LOG_DEBUG(Service_AM, "called, offset={} size={}", offset, out_buffer.size());
R_RETURN(m_impl->Read(offset, out_buffer.data(), out_buffer.size()));
}
ITransferStorageAccessor::ITransferStorageAccessor(Core::System& system_,
std::shared_ptr<LibraryAppletStorage> impl)
: ServiceFramework{system_, "ITransferStorageAccessor"}, m_impl{std::move(impl)} {
static const FunctionInfo functions[] = {
{0, D<&ITransferStorageAccessor::GetSize>, "GetSize"},
{1, D<&ITransferStorageAccessor::GetHandle>, "GetHandle"},
};
RegisterHandlers(functions);
}
ITransferStorageAccessor::~ITransferStorageAccessor() = default;
Result ITransferStorageAccessor::GetSize(Out<s64> out_size) {
LOG_DEBUG(Service_AM, "called");
*out_size = m_impl->GetSize();
R_SUCCEED();
}
Result ITransferStorageAccessor::GetHandle(Out<s64> out_size,
OutCopyHandle<Kernel::KTransferMemory> out_handle) {
LOG_INFO(Service_AM, "called");
*out_size = m_impl->GetSize();
*out_handle = m_impl->GetHandle();
R_SUCCEED();
}
} // namespace Service::AM

View file

@ -3,35 +3,36 @@
#pragma once #pragma once
#include "core/hle/service/am/storage.h" #include "core/hle/service/am/library_applet_storage.h"
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Service::AM { namespace Service::AM {
class IStorageAccessor final : public ServiceFramework<IStorageAccessor> { class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
public: public:
explicit IStorageAccessor(Core::System& system_, std::shared_ptr<LibraryAppletStorage> impl_); explicit IStorageAccessor(Core::System& system_, std::shared_ptr<LibraryAppletStorage> impl);
~IStorageAccessor() override; ~IStorageAccessor() override;
private: private:
void GetSize(HLERequestContext& ctx); Result GetSize(Out<s64> out_size);
void Write(HLERequestContext& ctx); Result Write(InBuffer<BufferAttr_HipcAutoSelect> buffer, s64 offset);
void Read(HLERequestContext& ctx); Result Read(OutBuffer<BufferAttr_HipcAutoSelect> out_buffer, s64 offset);
const std::shared_ptr<LibraryAppletStorage> impl; const std::shared_ptr<LibraryAppletStorage> m_impl;
}; };
class ITransferStorageAccessor final : public ServiceFramework<ITransferStorageAccessor> { class ITransferStorageAccessor final : public ServiceFramework<ITransferStorageAccessor> {
public: public:
explicit ITransferStorageAccessor(Core::System& system_, explicit ITransferStorageAccessor(Core::System& system_,
std::shared_ptr<LibraryAppletStorage> impl_); std::shared_ptr<LibraryAppletStorage> impl);
~ITransferStorageAccessor() override; ~ITransferStorageAccessor() override;
private: private:
void GetSize(HLERequestContext& ctx); Result GetSize(Out<s64> out_size);
void GetHandle(HLERequestContext& ctx); Result GetHandle(Out<s64> out_size, OutCopyHandle<Kernel::KTransferMemory> out_handle);
const std::shared_ptr<LibraryAppletStorage> impl; const std::shared_ptr<LibraryAppletStorage> m_impl;
}; };
} // namespace Service::AM } // namespace Service::AM

View file

@ -3,8 +3,8 @@
#include "core/hle/service/am/am_results.h" #include "core/hle/service/am/am_results.h"
#include "core/hle/service/am/library_applet_storage.h" #include "core/hle/service/am/library_applet_storage.h"
#include "core/hle/service/am/service/storage_accessor.h"
#include "core/hle/service/am/storage.h" #include "core/hle/service/am/storage.h"
#include "core/hle/service/am/storage_accessor.h"
#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ipc_helpers.h"
namespace Service::AM { namespace Service::AM {

View file

@ -1,90 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hle/kernel/k_transfer_memory.h"
#include "core/hle/service/am/am_results.h"
#include "core/hle/service/am/library_applet_storage.h"
#include "core/hle/service/am/storage_accessor.h"
#include "core/hle/service/ipc_helpers.h"
namespace Service::AM {
IStorageAccessor::IStorageAccessor(Core::System& system_,
std::shared_ptr<LibraryAppletStorage> impl_)
: ServiceFramework{system_, "IStorageAccessor"}, impl{std::move(impl_)} {
static const FunctionInfo functions[] = {
{0, &IStorageAccessor::GetSize, "GetSize"},
{10, &IStorageAccessor::Write, "Write"},
{11, &IStorageAccessor::Read, "Read"},
};
RegisterHandlers(functions);
}
IStorageAccessor::~IStorageAccessor() = default;
void IStorageAccessor::GetSize(HLERequestContext& ctx) {
LOG_DEBUG(Service_AM, "called");
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(ResultSuccess);
rb.Push(impl->GetSize());
}
void IStorageAccessor::Write(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const s64 offset{rp.Pop<s64>()};
const auto data{ctx.ReadBuffer()};
LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size());
const auto res{impl->Write(offset, data.data(), data.size())};
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(res);
}
void IStorageAccessor::Read(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const s64 offset{rp.Pop<s64>()};
std::vector<u8> data(ctx.GetWriteBufferSize());
LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size());
const auto res{impl->Read(offset, data.data(), data.size())};
ctx.WriteBuffer(data);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(res);
}
ITransferStorageAccessor::ITransferStorageAccessor(Core::System& system_,
std::shared_ptr<LibraryAppletStorage> impl_)
: ServiceFramework{system_, "ITransferStorageAccessor"}, impl{std::move(impl_)} {
static const FunctionInfo functions[] = {
{0, &ITransferStorageAccessor::GetSize, "GetSize"},
{1, &ITransferStorageAccessor::GetHandle, "GetHandle"},
};
RegisterHandlers(functions);
}
ITransferStorageAccessor::~ITransferStorageAccessor() = default;
void ITransferStorageAccessor::GetSize(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(ResultSuccess);
rb.Push(impl->GetSize());
}
void ITransferStorageAccessor::GetHandle(HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 4, 1};
rb.Push(ResultSuccess);
rb.Push(impl->GetSize());
rb.PushCopyObjects(impl->GetHandle());
}
} // namespace Service::AM