diff --git a/kernel/orbis/include/orbis/KernelAllocator.hpp b/kernel/orbis/include/orbis/KernelAllocator.hpp index 0d21459c6..726fabb89 100644 --- a/kernel/orbis/include/orbis/KernelAllocator.hpp +++ b/kernel/orbis/include/orbis/KernelAllocator.hpp @@ -3,6 +3,7 @@ #include "rx/Rc.hpp" #include #include +#include #include #include #include @@ -78,12 +79,28 @@ T *knew(Args &&...args) { // clang-format off template void kdelete(T *ptr) { - static_assert(std::is_final_v, "Uncertain type size"); - ptr->~T(); - kfree(ptr, sizeof(T)); + static_assert(!std::is_void_v); + static_assert(sizeof(T) > 0); + + if constexpr (std::is_base_of_v) { + delete ptr; + } else { + static_assert(!std::is_polymorphic_v, + "Polymorphic type should be derived from rx::RcBase"); + ptr->~T(); + kfree(ptr, sizeof(T)); + } } // clang-format on +template struct KDelete { + void operator()(T *ptr) const { + kdelete(ptr); + } +}; + +template using kunique_ptr = std::unique_ptr>; + void initializeAllocator(); void deinitializeAllocator(); } // namespace orbis