refactor(subsystems&ime): RAII lifecycle

This commit is contained in:
nmzik
2026-08-11 14:53:16 +02:00
parent 34cf130e4d
commit 4980efa9b7
43 changed files with 816 additions and 1256 deletions
+8 -6
View File
@@ -337,21 +337,23 @@ std::filesystem::path MountPoints::GetRealDirectory(const std::string& mounted_d
return mounted_directory;
}
KYTY_SUBSYSTEM_INIT(FileSystem) {
void Initialize() {
g_mount_points = new MountPoints;
g_files = new FileDescriptors;
}
KYTY_SUBSYSTEM_UNEXPECTED_SHUTDOWN(FileSystem) {
void EmergencyShutdown() {
if (g_files != nullptr) {
g_files->CloseAll();
}
}
KYTY_SUBSYSTEM_DESTROY(FileSystem) {
if (g_files != nullptr) {
g_files->CloseAll();
}
void Shutdown() {
EmergencyShutdown();
delete g_files;
delete g_mount_points;
g_files = nullptr;
g_mount_points = nullptr;
}
void Mount(const std::filesystem::path& folder, const std::string& point) {
+10 -2
View File
@@ -4,7 +4,6 @@
#include "common/abi.h"
#include "common/common.h"
#include "common/stringUtils.h"
#include "common/subsystems.h"
#include "kernel/pthread.h"
#include <filesystem>
@@ -33,7 +32,16 @@ struct FileStat {
unsigned int: (8 / 2) * (16 - static_cast<int>(sizeof(KernelTimespec)));
};
KYTY_SUBSYSTEM_DEFINE(FileSystem);
void Initialize();
void Shutdown();
void EmergencyShutdown();
struct Lifecycle {
static constexpr const char* name = "FileSystem";
static constexpr auto initialize = Libs::LibKernel::FileSystem::Initialize;
static constexpr auto shutdown = Libs::LibKernel::FileSystem::Shutdown;
static constexpr auto emergency_shutdown = Libs::LibKernel::FileSystem::EmergencyShutdown;
};
void Mount(const std::filesystem::path& folder, const std::string& point);
void Umount(const std::string& folder_or_point);
+2 -4
View File
@@ -976,7 +976,7 @@ static bool SelfTestSub64SharedPlaceholderAlias() {
static bool ReplaceFixedRangeWithReserved(uint64_t start, uint64_t size);
KYTY_SUBSYSTEM_INIT(Memory) {
void Initialize() {
g_flexible_memory_size_frozen = true;
VirtualMemory::Init();
g_guest_address_space = std::make_unique<GuestAddressSpace>(PhysicalMemory::TotalSize());
@@ -988,9 +988,7 @@ KYTY_SUBSYSTEM_INIT(Memory) {
EXIT_IF(!SelfTestSub64SharedPlaceholderAlias());
}
KYTY_SUBSYSTEM_UNEXPECTED_SHUTDOWN(Memory) {}
KYTY_SUBSYSTEM_DESTROY(Memory) {
void Shutdown() {
g_pooled_memory.reset();
g_flexible_memory.reset();
g_physical_memory.reset();
+8 -2
View File
@@ -3,7 +3,6 @@
#include "common/abi.h"
#include "common/common.h"
#include "common/subsystems.h"
#include "common/virtualMemory.h"
namespace Libs::Graphics {
@@ -13,7 +12,14 @@ enum class PageFaultAccess;
namespace Libs::LibKernel::Memory {
KYTY_SUBSYSTEM_DEFINE(Memory);
void Initialize();
void Shutdown();
struct Lifecycle {
static constexpr const char* name = "Memory";
static constexpr auto initialize = Libs::LibKernel::Memory::Initialize;
static constexpr auto shutdown = Libs::LibKernel::Memory::Shutdown;
};
using callback_func_t = void (*)(uintptr_t addr, size_t size);
+1 -5
View File
@@ -1124,7 +1124,7 @@ void* PthreadCreateMainGuestStack() {
return stack_top;
}
KYTY_SUBSYSTEM_INIT(Pthread) {
void Initialize() {
PRINT_NAME_ENABLE(false);
EXIT_IF(g_pthread_context != nullptr);
@@ -1157,10 +1157,6 @@ KYTY_SUBSYSTEM_INIT(Pthread) {
thread.Detach();
}
KYTY_SUBSYSTEM_UNEXPECTED_SHUTDOWN(Pthread) {}
KYTY_SUBSYSTEM_DESTROY(Pthread) {}
static int PthreadAttrCopy(PthreadAttr* dst, const PthreadAttr* src) {
if (dst == nullptr || *dst == nullptr || src == nullptr || *src == nullptr) {
return KERNEL_ERROR_EINVAL;
+6 -2
View File
@@ -3,7 +3,6 @@
#include "common/abi.h"
#include "common/common.h"
#include "common/subsystems.h"
// IWYU pragma: no_include <pthread.h>
@@ -19,7 +18,12 @@ namespace Libs {
namespace LibKernel {
KYTY_SUBSYSTEM_DEFINE(Pthread);
void Initialize();
struct PthreadLifecycle {
static constexpr const char* name = "Pthread";
static constexpr auto initialize = Libs::LibKernel::Initialize;
};
struct PthreadAttrPrivate;
struct PthreadPrivate;