1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-05 01:52:19 +00:00
Atmosphere/stratosphere/ams_mitm/source/amsmitm_main.cpp

94 lines
2.9 KiB
C++
Raw Normal View History

2018-10-30 05:18:04 +00:00
/*
* Copyright (c) Atmosphère-NX
2018-10-30 05:18:04 +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>
2019-11-21 09:48:47 +00:00
#include "amsmitm_initialization.hpp"
2019-11-21 07:58:18 +00:00
#include "amsmitm_module_management.hpp"
#include "bpc_mitm/bpc_ams_power_utils.hpp"
2020-06-26 05:59:59 +01:00
#include "sysupdater/sysupdater_fs_utils.hpp"
2018-10-30 05:18:04 +00:00
2019-11-21 07:58:18 +00:00
namespace ams {
namespace {
2018-10-30 05:18:04 +00:00
/* TODO: we really shouldn't be using malloc just to avoid dealing with real allocator separation. */
constexpr size_t MallocBufferSize = 32_MB;
alignas(os::MemoryPageSize) constinit u8 g_malloc_buffer[MallocBufferSize];
2019-11-21 07:58:18 +00:00
}
2018-10-30 05:18:04 +00:00
namespace init {
2018-10-30 05:18:04 +00:00
void InitializeSystemModule() {
/* Initialize our connection to sm. */
R_ABORT_UNLESS(sm::Initialize());
2018-10-30 05:18:04 +00:00
/* Initialize fs. */
fs::InitializeForSystem();
fs::SetEnabledAutoAbort(false);
2018-10-30 05:18:04 +00:00
/* Initialize other services. */
R_ABORT_UNLESS(pmdmntInitialize());
R_ABORT_UNLESS(pminfoInitialize());
ncm::Initialize();
2019-06-20 12:04:33 +01:00
/* Verify that we can sanely execute. */
ams::CheckApiVersion();
}
void FinalizeSystemModule() { /* ... */ }
2019-06-20 12:04:33 +01:00
void Startup() {
/* Initialize the global malloc allocator. */
init::InitializeAllocator(g_malloc_buffer, sizeof(g_malloc_buffer));
}
}
2020-06-26 05:59:59 +01:00
void ExceptionHandler(FatalErrorContext *ctx) {
/* We're bpc-mitm (or ams_mitm, anyway), so manually reboot to fatal error. */
mitm::bpc::RebootForFatalError(ctx);
}
2018-10-30 05:18:04 +00:00
void NORETURN Exit(int rc) {
AMS_UNUSED(rc);
AMS_ABORT("Exit called by immortal process");
}
2018-10-30 05:18:04 +00:00
void Main() {
/* Register "ams" port, use up its session. */
{
svc::Handle ams_port;
R_ABORT_UNLESS(svc::ManageNamedPort(std::addressof(ams_port), "ams", 1));
2021-01-19 10:34:02 +00:00
svc::Handle ams_session;
R_ABORT_UNLESS(svc::ConnectToNamedPort(std::addressof(ams_session), "ams"));
}
/* Initialize fssystem library. */
fssystem::InitializeForAtmosphereMitm();
2021-01-19 10:34:02 +00:00
/* Configure ncm to use fssystem library to mount content from the sd card. */
ncm::SetMountContentMetaFunction(mitm::sysupdater::MountSdCardContentMeta);
/* Launch all mitm modules in sequence. */
mitm::LaunchAllModules();
2021-01-27 22:20:30 +00:00
/* Wait for all mitm modules to end. */
mitm::WaitAllModules();
2021-01-27 22:20:30 +00:00
}
2018-10-30 05:18:04 +00:00
}