|
@@ -1,21 +1,22 @@
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
// 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/am_results.h"
|
|
|
|
|
+#include "core/hle/service/am/library_applet_storage.h"
|
|
|
#include "core/hle/service/am/storage_accessor.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 {
|
|
|
|
|
|
|
|
-IStorageAccessor::IStorageAccessor(Core::System& system_, IStorage& backing_)
|
|
|
|
|
- : ServiceFramework{system_, "IStorageAccessor"}, backing{backing_} {
|
|
|
|
|
- // clang-format off
|
|
|
|
|
- static const FunctionInfo functions[] = {
|
|
|
|
|
- {0, &IStorageAccessor::GetSize, "GetSize"},
|
|
|
|
|
- {10, &IStorageAccessor::Write, "Write"},
|
|
|
|
|
- {11, &IStorageAccessor::Read, "Read"},
|
|
|
|
|
- };
|
|
|
|
|
- // clang-format on
|
|
|
|
|
|
|
+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);
|
|
RegisterHandlers(functions);
|
|
|
}
|
|
}
|
|
@@ -28,55 +29,62 @@ void IStorageAccessor::GetSize(HLERequestContext& ctx) {
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
|
|
|
|
|
|
|
rb.Push(ResultSuccess);
|
|
rb.Push(ResultSuccess);
|
|
|
- rb.Push(static_cast<u64>(backing.GetSize()));
|
|
|
|
|
|
|
+ rb.Push(impl->GetSize());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void IStorageAccessor::Write(HLERequestContext& ctx) {
|
|
void IStorageAccessor::Write(HLERequestContext& ctx) {
|
|
|
IPC::RequestParser rp{ctx};
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
|
|
|
- const u64 offset{rp.Pop<u64>()};
|
|
|
|
|
|
|
+ const s64 offset{rp.Pop<s64>()};
|
|
|
const auto data{ctx.ReadBuffer()};
|
|
const auto data{ctx.ReadBuffer()};
|
|
|
- const std::size_t size{std::min<u64>(data.size(), backing.GetSize() - offset)};
|
|
|
|
|
|
|
+ LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size());
|
|
|
|
|
|
|
|
- LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
|
|
|
|
|
-
|
|
|
|
|
- if (offset > backing.GetSize()) {
|
|
|
|
|
- LOG_ERROR(Service_AM,
|
|
|
|
|
- "offset is out of bounds, backing_buffer_sz={}, data_size={}, offset={}",
|
|
|
|
|
- backing.GetSize(), size, offset);
|
|
|
|
|
-
|
|
|
|
|
- IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
- rb.Push(AM::ResultInvalidOffset);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- std::memcpy(backing.GetData().data() + offset, data.data(), size);
|
|
|
|
|
|
|
+ const auto res{impl->Write(offset, data.data(), data.size())};
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
- rb.Push(ResultSuccess);
|
|
|
|
|
|
|
+ rb.Push(res);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void IStorageAccessor::Read(HLERequestContext& ctx) {
|
|
void IStorageAccessor::Read(HLERequestContext& ctx) {
|
|
|
IPC::RequestParser rp{ctx};
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
|
|
|
- const u64 offset{rp.Pop<u64>()};
|
|
|
|
|
- const std::size_t size{std::min<u64>(ctx.GetWriteBufferSize(), backing.GetSize() - offset)};
|
|
|
|
|
|
|
+ const s64 offset{rp.Pop<s64>()};
|
|
|
|
|
+ std::vector<u8> data(ctx.GetWriteBufferSize());
|
|
|
|
|
|
|
|
- LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
|
|
|
|
|
|
|
+ LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size());
|
|
|
|
|
|
|
|
- if (offset > backing.GetSize()) {
|
|
|
|
|
- LOG_ERROR(Service_AM, "offset is out of bounds, backing_buffer_sz={}, size={}, offset={}",
|
|
|
|
|
- backing.GetSize(), size, offset);
|
|
|
|
|
|
|
+ const auto res{impl->Read(offset, data.data(), data.size())};
|
|
|
|
|
|
|
|
- IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
- rb.Push(AM::ResultInvalidOffset);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- ctx.WriteBuffer(backing.GetData().data() + offset, size);
|
|
|
|
|
|
|
+ ctx.WriteBuffer(data);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
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(ResultSuccess);
|
|
|
|
|
+ rb.Push(impl->GetSize());
|
|
|
|
|
+ rb.PushCopyObjects(impl->GetHandle());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::AM
|
|
} // namespace Service::AM
|