2020-04-17 05:57:01 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-04-17 05:57:01 +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>
|
2021-05-02 17:33:15 +00:00
|
|
|
#include "../os/impl/os_rng_manager.hpp"
|
2020-04-17 05:57:01 +00:00
|
|
|
|
|
|
|
namespace ams::os {
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
void Initialize();
|
2020-04-17 05:57:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
#if defined(ATMOSPHERE_OS_HORIZON)
|
2021-05-02 17:33:15 +00:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
/* Provide libnx address space allocation shim. */
|
|
|
|
uintptr_t __libnx_virtmem_rng(void) {
|
|
|
|
return static_cast<uintptr_t>(::ams::os::impl::GetRngManager().GenerateRandomU64());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-03-06 20:08:20 +00:00
|
|
|
#endif
|
2021-05-02 17:33:15 +00:00
|
|
|
|
2020-04-17 05:57:01 +00:00
|
|
|
namespace ams::hos {
|
|
|
|
|
2021-10-11 07:54:17 +00:00
|
|
|
namespace {
|
2020-04-17 05:57:01 +00:00
|
|
|
|
2021-10-11 07:54:17 +00:00
|
|
|
bool CanAllowTemporaryApproximateVersion() {
|
|
|
|
/* Check if we're a program that can use a temporary approximate version. */
|
|
|
|
const auto program_id = os::GetCurrentProgramId();
|
|
|
|
|
|
|
|
return program_id == ncm::SystemProgramId::Pm || /* Needed so that boot has permissions to use fsp-srv. */
|
|
|
|
program_id == ncm::SystemProgramId::Sm || /* Needed so that boot can acquire fsp-srv. */
|
|
|
|
program_id == ncm::SystemProgramId::Boot || /* Needed so that boot can set the true target firmware. */
|
|
|
|
program_id == ncm::SystemProgramId::Spl || /* Needed so that FS can complete initialization. */
|
|
|
|
program_id == ncm::SystemProgramId::Ncm; /* Needed so that FS can determine where SystemVersion is located. */
|
|
|
|
}
|
2021-09-05 17:08:30 +00:00
|
|
|
|
2020-04-17 05:57:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 16:40:18 +00:00
|
|
|
bool IsUnitTestProgramForSetVersion();
|
2021-10-11 07:54:17 +00:00
|
|
|
void InitializeVersionInternal(bool allow_approximate);
|
|
|
|
|
|
|
|
void InitializeForStratosphere() {
|
2020-05-11 22:04:51 +00:00
|
|
|
/* Initialize the global os resource managers. This *must* be done before anything else in stratosphere. */
|
2022-03-06 20:08:20 +00:00
|
|
|
os::Initialize();
|
2020-05-11 22:04:51 +00:00
|
|
|
|
|
|
|
/* Initialize hos::Version API. */
|
2021-10-11 07:54:17 +00:00
|
|
|
hos::InitializeVersionInternal(CanAllowTemporaryApproximateVersion());
|
2021-09-05 17:08:30 +00:00
|
|
|
|
2022-03-06 20:08:20 +00:00
|
|
|
#if defined(ATMOSPHERE_OS_HORIZON)
|
2021-09-05 17:08:30 +00:00
|
|
|
/* Check that we're running under mesosphere. */
|
2021-10-22 16:40:18 +00:00
|
|
|
AMS_ABORT_UNLESS(IsUnitTestProgramForSetVersion() || svc::IsKernelMesosphere());
|
2022-03-06 20:08:20 +00:00
|
|
|
#endif
|
2020-05-11 22:04:51 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 05:57:01 +00:00
|
|
|
}
|