2019-06-26 23:46:19 +01:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) 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/>.
|
|
|
|
*/
|
2020-05-11 23:02:10 +01:00
|
|
|
#include <stratosphere.hpp>
|
2019-06-26 23:46:19 +01:00
|
|
|
#include "ldr_arguments.hpp"
|
|
|
|
|
2019-10-24 10:30:10 +01:00
|
|
|
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. */
|
2019-10-28 04:43:01 +00:00
|
|
|
ArgumentInfo *FindArgumentInfo(ncm::ProgramId program_id) {
|
2019-06-26 23:46:19 +01:00
|
|
|
for (size_t i = 0; i < MaxArgumentInfos; i++) {
|
2019-10-28 04:43:01 +00:00
|
|
|
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() {
|
2019-10-28 04:43:01 +00:00
|
|
|
return FindArgumentInfo(ncm::InvalidProgramId);
|
2019-06-26 23:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* API. */
|
2019-10-28 04:43:01 +00:00
|
|
|
const ArgumentInfo *Get(ncm::ProgramId program_id) {
|
|
|
|
return FindArgumentInfo(program_id);
|
2019-06-26 23:46:19 +01:00
|
|
|
}
|
|
|
|
|
2019-10-28 04:43:01 +00:00
|
|
|
Result Set(ncm::ProgramId program_id, const void *args, size_t args_size) {
|
2019-10-24 09:40:44 +01:00
|
|
|
R_UNLESS(args_size < ArgumentSizeMax, ldr::ResultTooLongArgument());
|
2019-06-26 23:46:19 +01:00
|
|
|
|
2019-10-28 04:43:01 +00: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
|
|
|
}
|
2019-10-24 09:40:44 +01:00
|
|
|
R_UNLESS(arg_info != nullptr, ldr::ResultTooManyArguments());
|
2019-06-26 23:46:19 +01:00
|
|
|
|
2019-10-28 04:43:01 +00: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);
|
2019-10-24 09:40:44 +01:00
|
|
|
return ResultSuccess();
|
2019-06-26 23:46:19 +01:00
|
|
|
}
|
|
|
|
|
2019-10-28 04:43:01 +00:00
|
|
|
Result Flush() {
|
2019-06-26 23:46:19 +01:00
|
|
|
for (size_t i = 0; i < MaxArgumentInfos; i++) {
|
2019-10-28 04:43:01 +00:00
|
|
|
g_argument_infos[i].program_id = ncm::InvalidProgramId;
|
2019-06-26 23:46:19 +01:00
|
|
|
}
|
2019-10-24 09:40:44 +01:00
|
|
|
return ResultSuccess();
|
2019-06-26 23:46:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|