1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 16:32:05 +00:00
Atmosphere/stratosphere/loader/source/ldr_arguments.cpp

73 lines
2.2 KiB
C++
Raw Permalink Normal View History

2019-06-26 23:46:19 +01:00
/*
* Copyright (c) 2018-2020 Atmosphère-NX
2019-06-26 23:46:19 +01:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
2019-06-26 23:46:19 +01:00
#include "ldr_arguments.hpp"
namespace ams::ldr::args {
2019-06-26 23:46:19 +01:00
namespace {
/* Convenience definitions. */
constexpr size_t MaxArgumentInfos = 10;
/* Global storage. */
ArgumentInfo g_argument_infos[MaxArgumentInfos];
/* Helpers. */
ArgumentInfo *FindArgumentInfo(ncm::ProgramId program_id) {
2019-06-26 23:46:19 +01:00
for (size_t i = 0; i < MaxArgumentInfos; i++) {
if (g_argument_infos[i].program_id == program_id) {
2019-06-26 23:46:19 +01:00
return &g_argument_infos[i];
}
}
return nullptr;
}
2019-06-28 01:37:33 +01:00
ArgumentInfo *FindFreeArgumentInfo() {
return FindArgumentInfo(ncm::InvalidProgramId);
2019-06-26 23:46:19 +01:00
}
}
/* API. */
const ArgumentInfo *Get(ncm::ProgramId program_id) {
return FindArgumentInfo(program_id);
2019-06-26 23:46:19 +01:00
}
Result Set(ncm::ProgramId program_id, const void *args, size_t args_size) {
R_UNLESS(args_size < ArgumentSizeMax, ldr::ResultTooLongArgument());
2019-06-26 23:46:19 +01:00
ArgumentInfo *arg_info = FindArgumentInfo(program_id);
2019-06-26 23:46:19 +01:00
if (arg_info == nullptr) {
2019-06-28 01:37:33 +01:00
arg_info = FindFreeArgumentInfo();
2019-06-26 23:46:19 +01:00
}
R_UNLESS(arg_info != nullptr, ldr::ResultTooManyArguments());
2019-06-26 23:46:19 +01:00
arg_info->program_id = program_id;
2019-06-26 23:46:19 +01:00
arg_info->args_size = args_size;
std::memcpy(arg_info->args, args, args_size);
return ResultSuccess();
2019-06-26 23:46:19 +01:00
}
Result Flush() {
2019-06-26 23:46:19 +01:00
for (size_t i = 0; i < MaxArgumentInfos; i++) {
g_argument_infos[i].program_id = ncm::InvalidProgramId;
2019-06-26 23:46:19 +01:00
}
return ResultSuccess();
2019-06-26 23:46:19 +01:00
}
}