mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-01 02:37:27 +01:00
hos: change initialization API
This was needed to make stratosphere buildable with debugging on. os:: assertions rely on GetCurrentThread() working, and this requires the global os resource manager to be constructed. However, __appInit executes before global constructors. We now require that hos::InitializeForStratosphere() be called before anything else is done. This initializes the os resource manager, sets the hos version for libnx, and may do more things in the future. TODO: Consider replacing __appInit/__appExit with ams:: namespace functions in general, and wrap them so that we guarantee hos::InitializeForStratosphere is called first, and generally ensure a consistent stratosphere environment.
This commit is contained in:
parent
332dbdd497
commit
94ec9ae41b
@ -16,5 +16,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "hos/hos_types.hpp"
|
#include <stratosphere/hos/hos_types.hpp>
|
||||||
#include "hos/hos_version_api.hpp"
|
#include <stratosphere/hos/hos_version_api.hpp>
|
||||||
|
#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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <stratosphere/hos/hos_types.hpp>
|
||||||
|
|
||||||
|
namespace ams::hos {
|
||||||
|
|
||||||
|
void InitializeForStratosphere();
|
||||||
|
|
||||||
|
}
|
@ -15,11 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "hos_types.hpp"
|
#include <stratosphere/hos/hos_types.hpp>
|
||||||
|
|
||||||
namespace ams::hos {
|
namespace ams::hos {
|
||||||
|
|
||||||
::ams::hos::Version GetVersion();
|
::ams::hos::Version GetVersion();
|
||||||
void SetVersionForLibnx();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
#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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,8 +13,8 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stratosphere.hpp>
|
#include <stratosphere.hpp>
|
||||||
|
#include "hos_version_api_private.hpp"
|
||||||
|
|
||||||
namespace ams::hos {
|
namespace ams::hos {
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ namespace ams::hos {
|
|||||||
return g_hos_version;
|
return g_hos_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetVersionForLibnx() {
|
void SetVersionForLibnxInternal() {
|
||||||
u32 major = 0, minor = 0, micro = 0;
|
u32 major = 0, minor = 0, micro = 0;
|
||||||
switch (hos::GetVersion()) {
|
switch (hos::GetVersion()) {
|
||||||
case hos::Version_1_0_0:
|
case hos::Version_1_0_0:
|
||||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
|
||||||
|
namespace ams::hos {
|
||||||
|
|
||||||
|
void SetVersionForLibnxInternal();
|
||||||
|
|
||||||
|
}
|
@ -19,6 +19,6 @@
|
|||||||
namespace ams::os::impl {
|
namespace ams::os::impl {
|
||||||
|
|
||||||
/* TODO: C++20 constinit */
|
/* TODO: C++20 constinit */
|
||||||
OsResourceManager ResourceManagerHolder::s_resource_manager = {};
|
TYPED_STORAGE(OsResourceManager) ResourceManagerHolder::s_resource_manager_storage = {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,17 @@ namespace ams::os::impl {
|
|||||||
|
|
||||||
class ResourceManagerHolder {
|
class ResourceManagerHolder {
|
||||||
private:
|
private:
|
||||||
static /* TODO: C++20 constinit */ OsResourceManager s_resource_manager;
|
static TYPED_STORAGE(OsResourceManager) s_resource_manager_storage;
|
||||||
private:
|
private:
|
||||||
constexpr ResourceManagerHolder() { /* ... */ }
|
constexpr ResourceManagerHolder() { /* ... */ }
|
||||||
public:
|
public:
|
||||||
|
static ALWAYS_INLINE void InitializeResourceManagerInstance() {
|
||||||
|
/* Construct the resource manager instance. */
|
||||||
|
new (GetPointer(s_resource_manager_storage)) OsResourceManager;
|
||||||
|
}
|
||||||
|
|
||||||
static ALWAYS_INLINE OsResourceManager &GetResourceManagerInstance() {
|
static ALWAYS_INLINE OsResourceManager &GetResourceManagerInstance() {
|
||||||
return s_resource_manager;
|
return GetReference(s_resource_manager_storage);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
26
libraries/libstratosphere/source/os/os_stratosphere_api.cpp
Normal file
26
libraries/libstratosphere/source/os/os_stratosphere_api.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
#include "impl/os_resource_manager.hpp"
|
||||||
|
|
||||||
|
namespace ams::os {
|
||||||
|
|
||||||
|
void InitializeForStratosphereInternal() {
|
||||||
|
/* Initialize the global os resource manager. */
|
||||||
|
os::impl::ResourceManagerHolder::InitializeResourceManagerInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -74,7 +74,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
R_ABORT_UNLESS(fsInitialize());
|
R_ABORT_UNLESS(fsInitialize());
|
||||||
|
@ -86,7 +86,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
/* Initialize services we need (TODO: NCM) */
|
/* Initialize services we need (TODO: NCM) */
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
|
@ -66,7 +66,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
/* Initialize services we need. */
|
/* Initialize services we need. */
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
|
@ -68,7 +68,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
R_ABORT_UNLESS(fsInitialize());
|
R_ABORT_UNLESS(fsInitialize());
|
||||||
|
@ -60,7 +60,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
R_ABORT_UNLESS(pmdmntInitialize());
|
R_ABORT_UNLESS(pmdmntInitialize());
|
||||||
|
@ -66,7 +66,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
R_ABORT_UNLESS(setInitialize());
|
R_ABORT_UNLESS(setInitialize());
|
||||||
|
@ -72,7 +72,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
R_ABORT_UNLESS(setInitialize());
|
R_ABORT_UNLESS(setInitialize());
|
||||||
|
@ -68,7 +68,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
/* Initialize services we need. */
|
/* Initialize services we need. */
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
|
@ -91,7 +91,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
fs::SetAllocator(Allocate, Deallocate);
|
fs::SetAllocator(Allocate, Deallocate);
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
fs::SetAllocator(pgl::Allocate, pgl::Deallocate);
|
fs::SetAllocator(pgl::Allocate, pgl::Deallocate);
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
R_ABORT_UNLESS(fsprInitialize());
|
R_ABORT_UNLESS(fsprInitialize());
|
||||||
|
@ -58,7 +58,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
sm::DoWithSession([&]() {
|
sm::DoWithSession([&]() {
|
||||||
R_ABORT_UNLESS(setsysInitialize());
|
R_ABORT_UNLESS(setsysInitialize());
|
||||||
|
@ -70,7 +70,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
/* We must do no service setup here, because we are sm. */
|
/* We must do no service setup here, because we are sm. */
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ void __libnx_initheap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appInit(void) {
|
void __appInit(void) {
|
||||||
hos::SetVersionForLibnx();
|
hos::InitializeForStratosphere();
|
||||||
|
|
||||||
/* SPL doesn't really access any services... */
|
/* SPL doesn't really access any services... */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user