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