rpcsx/orbis-kernel/include/orbis/KernelContext.hpp

42 lines
940 B
C++
Raw Normal View History

2023-07-03 13:10:16 +02:00
#pragma once
#include "utils/LinkedNode.hpp"
#include "utils/SharedMutex.hpp"
2023-07-04 18:19:17 +02:00
#include "orbis/thread/types.hpp"
#include "KernelAllocator.hpp"
2023-07-03 13:10:16 +02:00
#include <algorithm>
#include <utility>
namespace orbis {
2023-07-04 18:19:17 +02:00
struct Process;
2023-07-03 13:10:16 +02:00
2023-07-04 18:19:17 +02:00
class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {
public:
KernelContext();
~KernelContext();
2023-07-03 13:10:16 +02:00
2023-07-04 18:19:17 +02:00
Process *createProcess(pid_t pid);
void deleteProcess(Process *proc);
Process *findProcessById(pid_t pid) const;
2023-07-03 13:10:16 +02:00
2023-07-04 18:19:17 +02:00
static void *kalloc(std::size_t size,
std::size_t align = __STDCPP_DEFAULT_NEW_ALIGNMENT__);
static void kfree(void *ptr, std::size_t size);
2023-07-03 13:10:16 +02:00
private:
mutable shared_mutex m_proc_mtx;
utils::LinkedNode<Process> *m_processes = nullptr;
2023-07-04 18:19:17 +02:00
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;
2023-07-03 13:10:16 +02:00
};
2023-07-04 18:19:17 +02:00
extern KernelContext &g_context;
} // namespace orbis