mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-23 19:26:55 -04:00
loader: completely rewrite.
This commit is contained in:
parent
9217e4c5f9
commit
61fcf5e0f4
49 changed files with 2523 additions and 5817 deletions
77
stratosphere/loader/source/ldr_arguments.cpp
Normal file
77
stratosphere/loader/source/ldr_arguments.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
||||
*
|
||||
* 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 "ldr_arguments.hpp"
|
||||
|
||||
namespace sts::ldr::args {
|
||||
|
||||
namespace {
|
||||
|
||||
/* Convenience definitions. */
|
||||
constexpr ncm::TitleId FreeTitleId = {};
|
||||
constexpr size_t MaxArgumentInfos = 10;
|
||||
|
||||
/* Global storage. */
|
||||
ArgumentInfo g_argument_infos[MaxArgumentInfos];
|
||||
|
||||
/* Helpers. */
|
||||
ArgumentInfo *GetArgumentInfo(ncm::TitleId title_id) {
|
||||
for (size_t i = 0; i < MaxArgumentInfos; i++) {
|
||||
if (g_argument_infos[i].title_id == title_id) {
|
||||
return &g_argument_infos[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ArgumentInfo *GetFreeArgumentInfo() {
|
||||
return GetArgumentInfo(FreeTitleId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* API. */
|
||||
const ArgumentInfo *Get(ncm::TitleId title_id) {
|
||||
return GetArgumentInfo(title_id);
|
||||
}
|
||||
|
||||
Result Set(ncm::TitleId title_id, const void *args, size_t args_size) {
|
||||
if (args_size >= ArgumentSizeMax) {
|
||||
return ResultLoaderTooLongArgument;
|
||||
}
|
||||
|
||||
ArgumentInfo *arg_info = GetArgumentInfo(title_id);
|
||||
if (arg_info == nullptr) {
|
||||
arg_info = GetFreeArgumentInfo();
|
||||
}
|
||||
if (arg_info == nullptr) {
|
||||
return ResultLoaderTooManyArguments;
|
||||
}
|
||||
|
||||
arg_info->title_id = title_id;
|
||||
arg_info->args_size = args_size;
|
||||
std::memcpy(arg_info->args, args, args_size);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result Clear() {
|
||||
for (size_t i = 0; i < MaxArgumentInfos; i++) {
|
||||
g_argument_infos[i].title_id = FreeTitleId;
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue