diff --git a/libraries/libstratosphere/include/stratosphere/hos.hpp b/libraries/libstratosphere/include/stratosphere/hos.hpp index 312e7b303..f5e10d8b4 100644 --- a/libraries/libstratosphere/include/stratosphere/hos.hpp +++ b/libraries/libstratosphere/include/stratosphere/hos.hpp @@ -16,5 +16,6 @@ #pragma once -#include "hos/hos_types.hpp" -#include "hos/hos_version_api.hpp" +#include +#include +#include diff --git a/libraries/libstratosphere/include/stratosphere/hos/hos_stratosphere_api.hpp b/libraries/libstratosphere/include/stratosphere/hos/hos_stratosphere_api.hpp new file mode 100644 index 000000000..30e090e4c --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/hos/hos_stratosphere_api.hpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 . + */ + +#pragma once +#include + +namespace ams::hos { + + void InitializeForStratosphere(); + +} diff --git a/libraries/libstratosphere/include/stratosphere/hos/hos_version_api.hpp b/libraries/libstratosphere/include/stratosphere/hos/hos_version_api.hpp index 62f1a8d62..c4e97efa4 100644 --- a/libraries/libstratosphere/include/stratosphere/hos/hos_version_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/hos/hos_version_api.hpp @@ -15,11 +15,10 @@ */ #pragma once -#include "hos_types.hpp" +#include namespace ams::hos { ::ams::hos::Version GetVersion(); - void SetVersionForLibnx(); } diff --git a/libraries/libstratosphere/source/hos/hos_stratosphere_api.cpp b/libraries/libstratosphere/source/hos/hos_stratosphere_api.cpp new file mode 100644 index 000000000..f0a4a029c --- /dev/null +++ b/libraries/libstratosphere/source/hos/hos_stratosphere_api.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 . + */ +#include +#include "hos_version_api_private.hpp" + +namespace ams::os { + + void InitializeForStratosphereInternal(); + +} + +namespace ams::hos { + + void InitializeForStratosphere() { + /* Initialize the global os resource managers. This *must* be done before anything else in stratosphere. */ + os::InitializeForStratosphereInternal(); + + /* Initialize hos::Version API. */ + hos::SetVersionForLibnxInternal(); + } + +} diff --git a/libraries/libstratosphere/source/hos/hos_version_api.cpp b/libraries/libstratosphere/source/hos/hos_version_api.cpp index d295250af..b11d56c83 100644 --- a/libraries/libstratosphere/source/hos/hos_version_api.cpp +++ b/libraries/libstratosphere/source/hos/hos_version_api.cpp @@ -13,8 +13,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include +#include "hos_version_api_private.hpp" namespace ams::hos { @@ -86,7 +86,7 @@ namespace ams::hos { return g_hos_version; } - void SetVersionForLibnx() { + void SetVersionForLibnxInternal() { u32 major = 0, minor = 0, micro = 0; switch (hos::GetVersion()) { case hos::Version_1_0_0: diff --git a/libraries/libstratosphere/source/hos/hos_version_api_private.hpp b/libraries/libstratosphere/source/hos/hos_version_api_private.hpp new file mode 100644 index 000000000..ed0cb8953 --- /dev/null +++ b/libraries/libstratosphere/source/hos/hos_version_api_private.hpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 . + */ +#pragma once +#include + +namespace ams::hos { + + void SetVersionForLibnxInternal(); + +} diff --git a/libraries/libstratosphere/source/os/impl/os_resource_manager.cpp b/libraries/libstratosphere/source/os/impl/os_resource_manager.cpp index 539f9e178..6585ea6c4 100644 --- a/libraries/libstratosphere/source/os/impl/os_resource_manager.cpp +++ b/libraries/libstratosphere/source/os/impl/os_resource_manager.cpp @@ -19,6 +19,6 @@ namespace ams::os::impl { /* TODO: C++20 constinit */ - OsResourceManager ResourceManagerHolder::s_resource_manager = {}; + TYPED_STORAGE(OsResourceManager) ResourceManagerHolder::s_resource_manager_storage = {}; } diff --git a/libraries/libstratosphere/source/os/impl/os_resource_manager.hpp b/libraries/libstratosphere/source/os/impl/os_resource_manager.hpp index 11e5209b6..473b3ddb6 100644 --- a/libraries/libstratosphere/source/os/impl/os_resource_manager.hpp +++ b/libraries/libstratosphere/source/os/impl/os_resource_manager.hpp @@ -39,12 +39,17 @@ namespace ams::os::impl { class ResourceManagerHolder { private: - static /* TODO: C++20 constinit */ OsResourceManager s_resource_manager; + static TYPED_STORAGE(OsResourceManager) s_resource_manager_storage; private: constexpr ResourceManagerHolder() { /* ... */ } public: + static ALWAYS_INLINE void InitializeResourceManagerInstance() { + /* Construct the resource manager instance. */ + new (GetPointer(s_resource_manager_storage)) OsResourceManager; + } + static ALWAYS_INLINE OsResourceManager &GetResourceManagerInstance() { - return s_resource_manager; + return GetReference(s_resource_manager_storage); } }; diff --git a/libraries/libstratosphere/source/os/os_stratosphere_api.cpp b/libraries/libstratosphere/source/os/os_stratosphere_api.cpp new file mode 100644 index 000000000..f081fdbf1 --- /dev/null +++ b/libraries/libstratosphere/source/os/os_stratosphere_api.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 . + */ +#include +#include "impl/os_resource_manager.hpp" + +namespace ams::os { + + void InitializeForStratosphereInternal() { + /* Initialize the global os resource manager. */ + os::impl::ResourceManagerHolder::InitializeResourceManagerInstance(); + } + +} diff --git a/stratosphere/ams_mitm/source/amsmitm_main.cpp b/stratosphere/ams_mitm/source/amsmitm_main.cpp index e6e0f5a71..6f5994280 100644 --- a/stratosphere/ams_mitm/source/amsmitm_main.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_main.cpp @@ -74,7 +74,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); sm::DoWithSession([&]() { R_ABORT_UNLESS(fsInitialize()); diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index 857da11b1..268cb81db 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -86,7 +86,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); /* Initialize services we need (TODO: NCM) */ sm::DoWithSession([&]() { diff --git a/stratosphere/boot2/source/boot2_main.cpp b/stratosphere/boot2/source/boot2_main.cpp index 4b1fcff47..5c5114b8e 100644 --- a/stratosphere/boot2/source/boot2_main.cpp +++ b/stratosphere/boot2/source/boot2_main.cpp @@ -66,7 +66,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); /* Initialize services we need. */ sm::DoWithSession([&]() { diff --git a/stratosphere/creport/source/creport_main.cpp b/stratosphere/creport/source/creport_main.cpp index b7fd6e445..19b0355ae 100644 --- a/stratosphere/creport/source/creport_main.cpp +++ b/stratosphere/creport/source/creport_main.cpp @@ -68,7 +68,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); sm::DoWithSession([&]() { R_ABORT_UNLESS(fsInitialize()); diff --git a/stratosphere/dmnt/source/dmnt_main.cpp b/stratosphere/dmnt/source/dmnt_main.cpp index 5e3dc98b3..466a9682d 100644 --- a/stratosphere/dmnt/source/dmnt_main.cpp +++ b/stratosphere/dmnt/source/dmnt_main.cpp @@ -60,7 +60,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); sm::DoWithSession([&]() { R_ABORT_UNLESS(pmdmntInitialize()); diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index 7b2d3451b..1914354e5 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -66,7 +66,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); sm::DoWithSession([&]() { R_ABORT_UNLESS(setInitialize()); diff --git a/stratosphere/fatal/source/fatal_main.cpp b/stratosphere/fatal/source/fatal_main.cpp index 8fe75cbbc..40aa49ede 100644 --- a/stratosphere/fatal/source/fatal_main.cpp +++ b/stratosphere/fatal/source/fatal_main.cpp @@ -72,7 +72,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); sm::DoWithSession([&]() { R_ABORT_UNLESS(setInitialize()); diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index 036ba3ec8..a4e3a8918 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -68,7 +68,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); /* Initialize services we need. */ sm::DoWithSession([&]() { diff --git a/stratosphere/ncm/source/ncm_main.cpp b/stratosphere/ncm/source/ncm_main.cpp index dfd4df1d1..d36b78bf1 100644 --- a/stratosphere/ncm/source/ncm_main.cpp +++ b/stratosphere/ncm/source/ncm_main.cpp @@ -91,7 +91,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); fs::SetAllocator(Allocate, Deallocate); diff --git a/stratosphere/pgl/source/pgl_main.cpp b/stratosphere/pgl/source/pgl_main.cpp index 69b90ed27..a69920b3a 100644 --- a/stratosphere/pgl/source/pgl_main.cpp +++ b/stratosphere/pgl/source/pgl_main.cpp @@ -117,7 +117,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); fs::SetAllocator(pgl::Allocate, pgl::Deallocate); diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index 3b7866d31..3aa363278 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -128,7 +128,7 @@ namespace { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); sm::DoWithSession([&]() { R_ABORT_UNLESS(fsprInitialize()); diff --git a/stratosphere/ro/source/ro_main.cpp b/stratosphere/ro/source/ro_main.cpp index e6e2ef171..252bf516f 100644 --- a/stratosphere/ro/source/ro_main.cpp +++ b/stratosphere/ro/source/ro_main.cpp @@ -58,7 +58,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); sm::DoWithSession([&]() { R_ABORT_UNLESS(setsysInitialize()); diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index b588397ca..ad1082f8c 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -70,7 +70,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); /* We must do no service setup here, because we are sm. */ } diff --git a/stratosphere/spl/source/spl_main.cpp b/stratosphere/spl/source/spl_main.cpp index e7236bcc6..04d2d16a0 100644 --- a/stratosphere/spl/source/spl_main.cpp +++ b/stratosphere/spl/source/spl_main.cpp @@ -75,7 +75,7 @@ void __libnx_initheap(void) { } void __appInit(void) { - hos::SetVersionForLibnx(); + hos::InitializeForStratosphere(); /* SPL doesn't really access any services... */