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