diff --git a/orbis-kernel/include/orbis/KernelAllocator.hpp b/orbis-kernel/include/orbis/KernelAllocator.hpp index edf2aa9af..bc6a641c7 100644 --- a/orbis-kernel/include/orbis/KernelAllocator.hpp +++ b/orbis-kernel/include/orbis/KernelAllocator.hpp @@ -54,9 +54,16 @@ template T *knew(Args &&...args) { return res; } +// clang-format off template void kdelete(T *ptr) { + auto total_size = sizeof(T); + if constexpr (requires(T *t) { t->_total_size = sizeof(T); }) + total_size = ptr->_total_size; + else + static_assert(std::is_final_v, "Uncertain type size"); ptr->~T(); - utils::kfree(ptr, sizeof(T)); + utils::kfree(ptr, total_size); } +// clang-format on } // namespace orbis diff --git a/orbis-kernel/include/orbis/evf.hpp b/orbis-kernel/include/orbis/evf.hpp index f128b5aa7..5f88c1245 100644 --- a/orbis-kernel/include/orbis/evf.hpp +++ b/orbis-kernel/include/orbis/evf.hpp @@ -21,7 +21,7 @@ enum { kEvfWaitModeClearPat = 0x20, }; -struct EventFlag { +struct EventFlag final { char name[32]; bool isDeleted = false; diff --git a/orbis-kernel/include/orbis/file.hpp b/orbis-kernel/include/orbis/file.hpp index 98a0780a2..b58cf0428 100644 --- a/orbis-kernel/include/orbis/file.hpp +++ b/orbis-kernel/include/orbis/file.hpp @@ -40,7 +40,7 @@ struct FileOps { Thread *thread) = nullptr; }; -struct File { +struct File final { FileOps *ops; Ref device; std::atomic refs{0}; diff --git a/orbis-kernel/include/orbis/thread/Process.hpp b/orbis-kernel/include/orbis/thread/Process.hpp index 4882734f9..e3947b361 100644 --- a/orbis-kernel/include/orbis/thread/Process.hpp +++ b/orbis-kernel/include/orbis/thread/Process.hpp @@ -22,7 +22,7 @@ struct NamedObjInfo { uint16_t ty; }; -struct Process { +struct Process final { KernelContext *context = nullptr; pid_t pid = -1; sysentvec *sysent = nullptr; diff --git a/orbis-kernel/include/orbis/utils/LinkedNode.hpp b/orbis-kernel/include/orbis/utils/LinkedNode.hpp index 84f551749..f2c005f4b 100644 --- a/orbis-kernel/include/orbis/utils/LinkedNode.hpp +++ b/orbis-kernel/include/orbis/utils/LinkedNode.hpp @@ -2,7 +2,7 @@ namespace orbis { inline namespace utils { -template struct LinkedNode { +template struct LinkedNode final { T object; LinkedNode *next = nullptr; LinkedNode *prev = nullptr;