[orbis-kernel] Implement kfree

Incomplete implementation.
This commit is contained in:
Ivan Chikish 2023-07-06 22:10:15 +03:00
parent 5f6647540c
commit 9744c41ebb
3 changed files with 61 additions and 26 deletions

View file

@ -37,6 +37,8 @@ template <typename T> using kvector = std::vector<T, kallocator<T>>;
template <typename T> using kdeque = std::deque<T, kallocator<T>>;
template <typename K, typename T, typename Cmp = std::less<>>
using kmap = std::map<K, T, Cmp, kallocator<std::pair<const K, T>>>;
template <typename K, typename T, typename Cmp = std::less<>>
using kmultimap = std::multimap<K, T, Cmp, kallocator<std::pair<const K, T>>>;
template <typename K, typename T, typename Hash = std::hash<K>,
typename Pred = std::equal_to<K>>
using kunmap =

View file

@ -1,11 +1,12 @@
#pragma once
#include "evf.hpp"
#include "utils/LinkedNode.hpp"
#include "utils/SharedMutex.hpp"
#include "evf.hpp"
#include "orbis/thread/types.hpp"
#include "KernelAllocator.hpp"
#include "orbis/thread/types.hpp"
#include <algorithm>
#include <pthread.h>
#include <utility>
namespace orbis {
@ -20,13 +21,15 @@ public:
void deleteProcess(Process *proc);
Process *findProcessById(pid_t pid) const;
static void *kalloc(std::size_t size,
std::size_t align = __STDCPP_DEFAULT_NEW_ALIGNMENT__);
static void kfree(void *ptr, std::size_t size);
void *kalloc(std::size_t size,
std::size_t align = __STDCPP_DEFAULT_NEW_ALIGNMENT__);
void kfree(void *ptr, std::size_t size);
std::pair<EventFlag *, bool> createEventFlag(utils::kstring name, std::int32_t flags) {
auto [it, inserted] = m_event_flags.try_emplace(std::move(name), knew<EventFlag>(flags));
return { it->second.get(), inserted };
std::pair<EventFlag *, bool> createEventFlag(utils::kstring name,
std::int32_t flags) {
auto [it, inserted] =
m_event_flags.try_emplace(std::move(name), knew<EventFlag>(flags));
return {it->second.get(), inserted};
}
Ref<EventFlag> findEventFlag(std::string_view name) {
@ -34,22 +37,19 @@ public:
return it->second;
}
return{};
return {};
}
private:
mutable pthread_mutex_t m_heap_mtx;
void *m_heap_next = this + 1;
bool m_heap_is_freeing = false;
utils::kmultimap<std::size_t, void *> m_free_heap;
utils::kmultimap<std::size_t, void *> m_used_node;
mutable shared_mutex m_proc_mtx;
utils::LinkedNode<Process> *m_processes = nullptr;
utils::kmap<utils::kstring, Ref<EventFlag>> m_event_flags;
struct node {
std::size_t size;
node *next;
};
mutable shared_mutex m_heap_mtx;
void *m_heap_next = this + 1;
node *m_free_list = nullptr;
};
extern KernelContext &g_context;