mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
kern: devirtualize remaining vcall for class token/dyncast
This commit is contained in:
parent
36e4914be8
commit
71e4313d0c
10 changed files with 38 additions and 47 deletions
|
@ -22,13 +22,19 @@ namespace ams::kern {
|
|||
|
||||
class KProcess;
|
||||
|
||||
#if defined(MESOSPHERE_BUILD_FOR_DEBUGGING) || defined(MESOSPHERE_BUILD_FOR_AUDITING)
|
||||
#define MESOSPHERE_AUTO_OBJECT_TYPENAME_IMPL(CLASS) #CLASS
|
||||
#else
|
||||
#define MESOSPHERE_AUTO_OBJECT_TYPENAME_IMPL(CLASS) ""
|
||||
#endif
|
||||
|
||||
#define MESOSPHERE_AUTOOBJECT_TRAITS(CLASS, BASE_CLASS) \
|
||||
NON_COPYABLE(CLASS); \
|
||||
NON_MOVEABLE(CLASS); \
|
||||
private: \
|
||||
friend class ::ams::kern::KClassTokenGenerator; \
|
||||
static constexpr inline auto ObjectType = ::ams::kern::KClassTokenGenerator::ObjectType::CLASS; \
|
||||
static constexpr inline const char * const TypeName = #CLASS; \
|
||||
static constexpr inline const char * const TypeName = MESOSPHERE_AUTO_OBJECT_TYPENAME_IMPL(CLASS); \
|
||||
static constexpr inline ClassTokenType ClassToken() { return ::ams::kern::ClassToken<CLASS>; } \
|
||||
public: \
|
||||
using BaseClass = BASE_CLASS; \
|
||||
|
@ -118,8 +124,6 @@ namespace ams::kern {
|
|||
#if defined(MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST)
|
||||
ClassTokenType m_class_token;
|
||||
#endif
|
||||
public:
|
||||
static KAutoObject *Create(KAutoObject *ptr);
|
||||
public:
|
||||
constexpr ALWAYS_INLINE explicit KAutoObject(util::ConstantInitializeTag) : m_next_closed_object(nullptr), m_ref_count(0)
|
||||
#if defined(MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST)
|
||||
|
@ -204,6 +208,23 @@ namespace ams::kern {
|
|||
public:
|
||||
/* Getter, for KThread. */
|
||||
ALWAYS_INLINE KAutoObject *GetNextClosedObject() { return m_next_closed_object; }
|
||||
public:
|
||||
template<typename Derived> requires (std::derived_from<Derived, KAutoObject>)
|
||||
static ALWAYS_INLINE void Create(typename std::type_identity<Derived>::type *obj) {
|
||||
/* Get auto object pointer. */
|
||||
KAutoObject &auto_object = *static_cast<KAutoObject *>(obj);
|
||||
|
||||
/* If we should, set our class token. */
|
||||
#if defined(MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST)
|
||||
{
|
||||
constexpr auto Token = Derived::GetStaticTypeObj().GetClassToken();
|
||||
auto_object.m_class_token = Token;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize reference count to 1. */
|
||||
auto_object.m_ref_count = 1;
|
||||
}
|
||||
};
|
||||
|
||||
class KAutoObjectWithListContainer;
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace ams::kern {
|
|||
static KSessionRequest *Create() {
|
||||
KSessionRequest *req = KSessionRequest::Allocate();
|
||||
if (AMS_LIKELY(req != nullptr)) {
|
||||
KAutoObject::Create(req);
|
||||
KAutoObject::Create<KSessionRequest>(req);
|
||||
}
|
||||
return req;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ namespace ams::kern {
|
|||
static KSessionRequest *CreateFromUnusedSlabMemory() {
|
||||
KSessionRequest *req = KSessionRequest::AllocateFromUnusedSlabMemory();
|
||||
if (AMS_LIKELY(req != nullptr)) {
|
||||
KAutoObject::Create(req);
|
||||
KAutoObject::Create<KSessionRequest>(req);
|
||||
}
|
||||
return req;
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace ams::kern {
|
|||
static Derived *Create() {
|
||||
Derived *obj = Allocate();
|
||||
if (AMS_LIKELY(obj != nullptr)) {
|
||||
KAutoObject::Create(obj);
|
||||
KAutoObject::Create<Derived>(obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ namespace ams::kern {
|
|||
Derived * const obj = GetPointer<Derived>(AllocateUnusedSlabMemory(sizeof(Derived), alignof(Derived)));
|
||||
if (AMS_LIKELY(obj != nullptr)) {
|
||||
std::construct_at(obj);
|
||||
KAutoObject::Create(obj);
|
||||
KAutoObject::Create<Derived>(obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
|
|
@ -487,7 +487,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||
{
|
||||
/* Construct the resource limit object. */
|
||||
KResourceLimit &sys_res_limit = Kernel::GetSystemResourceLimit();
|
||||
KAutoObject::Create(std::addressof(sys_res_limit));
|
||||
KAutoObject::Create<KResourceLimit>(std::addressof(sys_res_limit));
|
||||
sys_res_limit.Initialize();
|
||||
|
||||
/* Set the initial limits. */
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 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 <mesosphere.hpp>
|
||||
|
||||
namespace ams::kern {
|
||||
|
||||
KAutoObject *KAutoObject::Create(KAutoObject *obj) {
|
||||
obj->m_ref_count = 1;
|
||||
|
||||
#if defined(MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST)
|
||||
obj->m_class_token = obj->GetTypeObj().GetClassToken();
|
||||
#endif
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ namespace ams::kern {
|
|||
MESOSPHERE_ASSERT_THIS();
|
||||
|
||||
/* Create our readable event. */
|
||||
KAutoObject::Create(std::addressof(m_readable_event));
|
||||
KAutoObject::Create<KReadableEvent>(std::addressof(m_readable_event));
|
||||
|
||||
/* Initialize our readable event. */
|
||||
m_readable_event.Initialize(this);
|
||||
|
|
|
@ -27,8 +27,8 @@ namespace ams::kern {
|
|||
this->Open();
|
||||
|
||||
/* Create our sub sessions. */
|
||||
KAutoObject::Create(std::addressof(m_server));
|
||||
KAutoObject::Create(std::addressof(m_client));
|
||||
KAutoObject::Create<KLightServerSession>(std::addressof(m_server));
|
||||
KAutoObject::Create<KLightClientSession>(std::addressof(m_client));
|
||||
|
||||
/* Initialize our sub sessions. */
|
||||
m_server.Initialize(this);
|
||||
|
|
|
@ -22,8 +22,8 @@ namespace ams::kern {
|
|||
this->Open();
|
||||
|
||||
/* Create and initialize our server/client pair. */
|
||||
KAutoObject::Create(std::addressof(m_server));
|
||||
KAutoObject::Create(std::addressof(m_client));
|
||||
KAutoObject::Create<KServerPort>(std::addressof(m_server));
|
||||
KAutoObject::Create<KClientPort>(std::addressof(m_client));
|
||||
m_server.Initialize(this);
|
||||
m_client.Initialize(this, max_sessions);
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ namespace ams::kern {
|
|||
this->Open();
|
||||
|
||||
/* Create our sub sessions. */
|
||||
KAutoObject::Create(std::addressof(m_server));
|
||||
KAutoObject::Create(std::addressof(m_client));
|
||||
KAutoObject::Create<KServerSession>(std::addressof(m_server));
|
||||
KAutoObject::Create<KClientSession>(std::addressof(m_client));
|
||||
|
||||
/* Initialize our sub sessions. */
|
||||
m_server.Initialize(this);
|
||||
|
|
|
@ -50,8 +50,8 @@ namespace ams::kern {
|
|||
void *main_thread_stack = GetVoidPointer(KMemoryLayout::GetMainStackTopAddress(core_id));
|
||||
KThread *idle_thread = std::addressof(Kernel::GetIdleThread(core_id));
|
||||
void *idle_thread_stack = GetVoidPointer(KMemoryLayout::GetIdleStackTopAddress(core_id));
|
||||
KAutoObject::Create(main_thread);
|
||||
KAutoObject::Create(idle_thread);
|
||||
KAutoObject::Create<KThread>(main_thread);
|
||||
KAutoObject::Create<KThread>(idle_thread);
|
||||
main_thread->Initialize(nullptr, 0, main_thread_stack, 0, KThread::MainThreadPriority, core_id, nullptr, KThread::ThreadType_Main);
|
||||
idle_thread->Initialize(nullptr, 0, idle_thread_stack, 0, KThread::IdleThreadPriority, core_id, nullptr, KThread::ThreadType_Main);
|
||||
|
||||
|
|
Loading…
Reference in a new issue