Skip to content

Commit

Permalink
[orbis-kernel] Improve kdelete safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotekina committed Jul 15, 2023
1 parent 9717128 commit 191a945
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion orbis-kernel/include/orbis/KernelAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@ template <typename T, typename... Args> T *knew(Args &&...args) {
return res;
}

// clang-format off
template <typename T> 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<T>, "Uncertain type size");
ptr->~T();
utils::kfree(ptr, sizeof(T));
utils::kfree(ptr, total_size);
}
// clang-format on

} // namespace orbis
2 changes: 1 addition & 1 deletion orbis-kernel/include/orbis/evf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum {
kEvfWaitModeClearPat = 0x20,
};

struct EventFlag {
struct EventFlag final {
char name[32];

bool isDeleted = false;
Expand Down
2 changes: 1 addition & 1 deletion orbis-kernel/include/orbis/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct FileOps {
Thread *thread) = nullptr;
};

struct File {
struct File final {
FileOps *ops;
Ref<RcBase> device;
std::atomic<unsigned> refs{0};
Expand Down
2 changes: 1 addition & 1 deletion orbis-kernel/include/orbis/thread/Process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct NamedObjInfo {
uint16_t ty;
};

struct Process {
struct Process final {
KernelContext *context = nullptr;
pid_t pid = -1;
sysentvec *sysent = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion orbis-kernel/include/orbis/utils/LinkedNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace orbis {
inline namespace utils {
template <typename T> struct LinkedNode {
template <typename T> struct LinkedNode final {
T object;
LinkedNode *next = nullptr;
LinkedNode *prev = nullptr;
Expand Down

0 comments on commit 191a945

Please sign in to comment.