2019-11-21 07:58:18 +00:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-11-21 07:58:18 +00: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>
|
|
|
|
#include "amsmitm_module_management.hpp"
|
|
|
|
#include "amsmitm_module.hpp"
|
|
|
|
|
|
|
|
#include "fs_mitm/fsmitm_module.hpp"
|
|
|
|
#include "set_mitm/setmitm_module.hpp"
|
|
|
|
#include "bpc_mitm/bpcmitm_module.hpp"
|
2020-04-23 00:22:14 +01:00
|
|
|
#include "bpc_mitm/bpc_ams_module.hpp"
|
2019-11-21 07:58:18 +00:00
|
|
|
#include "ns_mitm/nsmitm_module.hpp"
|
2021-01-30 21:11:39 +00:00
|
|
|
#include "dns_mitm/dnsmitm_module.hpp"
|
2020-06-26 05:59:59 +01:00
|
|
|
#include "sysupdater/sysupdater_module.hpp"
|
2019-11-21 07:58:18 +00:00
|
|
|
|
|
|
|
namespace ams::mitm {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum ModuleId : u32 {
|
|
|
|
ModuleId_FsMitm,
|
|
|
|
ModuleId_SetMitm,
|
|
|
|
ModuleId_BpcMitm,
|
2020-04-23 00:22:14 +01:00
|
|
|
ModuleId_BpcAms,
|
2019-11-21 07:58:18 +00:00
|
|
|
ModuleId_NsMitm,
|
2021-01-30 21:11:39 +00:00
|
|
|
ModuleId_DnsMitm,
|
2020-06-26 05:59:59 +01:00
|
|
|
ModuleId_Sysupdater,
|
2019-11-21 07:58:18 +00:00
|
|
|
|
|
|
|
ModuleId_Count,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ModuleDefinition {
|
|
|
|
ThreadFunc main;
|
|
|
|
void *stack_mem;
|
2020-04-08 10:21:35 +01:00
|
|
|
s32 priority;
|
2019-11-21 07:58:18 +00:00
|
|
|
u32 stack_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class M>
|
|
|
|
constexpr ModuleDefinition GetModuleDefinition() {
|
|
|
|
using Traits = ModuleTraits<M>;
|
|
|
|
|
|
|
|
return ModuleDefinition {
|
|
|
|
.main = Traits::ThreadFunction,
|
|
|
|
.stack_mem = Traits::Stack,
|
|
|
|
.priority = Traits::ThreadPriority,
|
2020-05-11 23:02:10 +01:00
|
|
|
.stack_size = static_cast<u32>(Traits::StackSize),
|
2019-11-21 07:58:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-08 10:21:35 +01:00
|
|
|
ams::os::ThreadType g_module_threads[ModuleId_Count];
|
2019-11-21 07:58:18 +00:00
|
|
|
|
|
|
|
constexpr ModuleDefinition g_module_definitions[ModuleId_Count] = {
|
|
|
|
GetModuleDefinition<fs::MitmModule>(),
|
2019-11-22 03:32:41 +00:00
|
|
|
GetModuleDefinition<settings::MitmModule>(),
|
2019-11-21 07:58:18 +00:00
|
|
|
GetModuleDefinition<bpc::MitmModule>(),
|
2020-04-23 00:22:14 +01:00
|
|
|
GetModuleDefinition<bpc_ams::MitmModule>(),
|
2019-11-21 07:58:18 +00:00
|
|
|
GetModuleDefinition<ns::MitmModule>(),
|
2021-01-30 21:11:39 +00:00
|
|
|
GetModuleDefinition<socket::resolver::MitmModule>(),
|
2020-06-26 05:59:59 +01:00
|
|
|
GetModuleDefinition<sysupdater::MitmModule>(),
|
2019-11-21 07:58:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchAllModules() {
|
|
|
|
/* Create thread for each module. */
|
|
|
|
for (u32 i = 0; i < static_cast<u32>(ModuleId_Count); i++) {
|
|
|
|
const ModuleDefinition &cur_module = g_module_definitions[i];
|
2020-04-08 10:21:35 +01:00
|
|
|
R_ABORT_UNLESS(os::CreateThread(g_module_threads + i, cur_module.main, nullptr, cur_module.stack_mem, cur_module.stack_size, cur_module.priority));
|
2019-11-21 07:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start thread for each module. */
|
|
|
|
for (u32 i = 0; i < static_cast<u32>(ModuleId_Count); i++) {
|
2020-04-08 10:21:35 +01:00
|
|
|
os::StartThread(g_module_threads + i);
|
2019-11-21 07:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitAllModules() {
|
|
|
|
/* Wait on thread for each module. */
|
|
|
|
for (u32 i = 0; i < static_cast<u32>(ModuleId_Count); i++) {
|
2020-04-08 10:21:35 +01:00
|
|
|
os::WaitThread(g_module_threads + i);
|
2019-11-21 07:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|