From 4ee087fb3ca2b1e064422b73195a8ff7698721d9 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 17 Nov 2018 12:19:06 -0500 Subject: [PATCH] applet: Use std::queue instead of std::vector for storage stack --- src/core/hle/service/am/am.cpp | 36 ++++++++++++------- src/core/hle/service/am/applets/applets.cpp | 12 ++++++- src/core/hle/service/am/applets/applets.h | 7 ++-- .../service/am/applets/software_keyboard.cpp | 9 +++-- .../service/am/applets/software_keyboard.h | 2 +- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 5cbcb8d91..d92a46b00 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -567,12 +567,12 @@ public: private: void AppletStorageProxyOutData(IStorage storage) { - storage_stack.push_back(std::make_shared(storage)); + storage_stack.push(std::make_shared(storage)); pop_out_data_event->Signal(); } void AppletStorageProxyOutInteractiveData(IStorage storage) { - interactive_storage_stack.push_back(std::make_shared(storage)); + interactive_storage_stack.push(std::make_shared(storage)); pop_interactive_out_data_event->Signal(); } @@ -621,7 +621,7 @@ private: void PushInData(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - storage_stack.push_back(rp.PopIpcInterface()); + storage_stack.push(rp.PopIpcInterface()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -631,17 +631,23 @@ private: void PopOutData(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface(std::move(storage_stack.back())); - storage_stack.pop_back(); + if (storage_stack.empty()) { + rb.Push(ResultCode(-1)); + return; + } + + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface(std::move(storage_stack.front())); + + storage_stack.pop(); LOG_DEBUG(Service_AM, "called"); } void PushInteractiveInData(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - interactive_storage_stack.push_back(rp.PopIpcInterface()); + interactive_storage_stack.push(rp.PopIpcInterface()); ASSERT(applet->IsInitialized()); applet->ReceiveInteractiveData(interactive_storage_stack.back()); @@ -657,10 +663,16 @@ private: void PopInteractiveOutData(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface(std::move(interactive_storage_stack.back())); - interactive_storage_stack.pop_back(); + if (interactive_storage_stack.empty()) { + rb.Push(ResultCode(-1)); + return; + } + + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface(std::move(interactive_storage_stack.front())); + + interactive_storage_stack.pop(); LOG_DEBUG(Service_AM, "called"); } @@ -682,8 +694,8 @@ private: } std::shared_ptr applet; - std::vector> storage_stack; - std::vector> interactive_storage_stack; + std::queue> storage_stack; + std::queue> interactive_storage_stack; Kernel::SharedPtr state_changed_event; Kernel::SharedPtr pop_out_data_event; Kernel::SharedPtr pop_interactive_out_data_event; diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index 03b9d83e7..be950d320 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -2,7 +2,10 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include "common/assert.h" #include "core/frontend/applets/software_keyboard.h" +#include "core/hle/service/am/am.h" #include "core/hle/service/am/applets/applets.h" namespace Service::AM::Applets { @@ -11,8 +14,15 @@ Applet::Applet() = default; Applet::~Applet() = default; -void Applet::Initialize(std::vector> storage) { +void Applet::Initialize(std::queue> storage) { storage_stack = std::move(storage); + + const auto common_data = storage_stack.front()->GetData(); + storage_stack.pop(); + + ASSERT(common_data.size() >= sizeof(CommonArguments)); + std::memcpy(&common_args, common_data.data(), sizeof(CommonArguments)); + initialized = true; } diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index 1ffa09420..a6a9bf77b 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include "common/swap.h" union ResultCode; @@ -29,7 +29,7 @@ public: Applet(); virtual ~Applet(); - virtual void Initialize(std::vector> storage); + virtual void Initialize(std::queue> storage); virtual bool TransactionComplete() const = 0; virtual ResultCode GetStatus() const = 0; @@ -53,7 +53,8 @@ protected: }; static_assert(sizeof(CommonArguments) == 0x20, "CommonArguments has incorrect size."); - std::vector> storage_stack; + CommonArguments common_args; + std::queue> storage_stack; bool initialized = false; }; diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index 039bfcc0f..a5ffa1f31 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp @@ -42,7 +42,7 @@ SoftwareKeyboard::SoftwareKeyboard() = default; SoftwareKeyboard::~SoftwareKeyboard() = default; -void SoftwareKeyboard::Initialize(std::vector> storage_) { +void SoftwareKeyboard::Initialize(std::queue> storage_) { complete = false; initial_text.clear(); final_data.clear(); @@ -50,11 +50,14 @@ void SoftwareKeyboard::Initialize(std::vector> storage Applet::Initialize(std::move(storage_)); ASSERT(storage_stack.size() >= 2); - const auto& keyboard_config = storage_stack[1]->GetData(); + const auto& keyboard_config = storage_stack.front()->GetData(); + storage_stack.pop(); + ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); - const auto& work_buffer = storage_stack[2]->GetData(); + const auto& work_buffer = storage_stack.front()->GetData(); + storage_stack.pop(); if (config.initial_string_size == 0) return; diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h index 9629f6408..9544d6b1b 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h @@ -49,7 +49,7 @@ public: SoftwareKeyboard(); ~SoftwareKeyboard() override; - void Initialize(std::vector> storage) override; + void Initialize(std::queue> storage) override; bool TransactionComplete() const override; ResultCode GetStatus() const override;