Kernel: Add basic concept of Processes
We now create Shell as a process that has its own threads
This commit is contained in:
40
kernel/include/kernel/Process.h
Normal file
40
kernel/include/kernel/Process.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/String.h>
|
||||
#include <BAN/Vector.h>
|
||||
#include <kernel/Thread.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
class Process : BAN::RefCounted<Process>
|
||||
{
|
||||
BAN_NON_COPYABLE(Process);
|
||||
BAN_NON_MOVABLE(Process);
|
||||
|
||||
public:
|
||||
using entry_t = Thread::entry_t;
|
||||
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::RefPtr<Process>> create_kernel(entry_t, void*);
|
||||
~Process() {}
|
||||
|
||||
BAN::ErrorOr<void> add_thread(entry_t, void*);
|
||||
void on_thread_exit(Thread&);
|
||||
|
||||
pid_t pid() const { return m_pid; }
|
||||
|
||||
static BAN::RefPtr<Process> current() { return Thread::current()->process(); }
|
||||
|
||||
private:
|
||||
Process(pid_t pid) : m_pid(pid) {}
|
||||
|
||||
private:
|
||||
pid_t m_pid = 0;
|
||||
BAN::String m_working_directory;
|
||||
BAN::Vector<BAN::RefPtr<Thread>> m_threads;
|
||||
|
||||
friend class BAN::RefPtr<Process>;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -21,11 +21,11 @@ namespace Kernel
|
||||
void set_current_thread_sleeping(uint64_t);
|
||||
[[noreturn]] void set_current_thread_done();
|
||||
|
||||
BAN::RefPtr<Thread> current_thread();
|
||||
|
||||
private:
|
||||
Scheduler() = default;
|
||||
|
||||
BAN::RefPtr<Thread> current_thread();
|
||||
|
||||
void wake_threads();
|
||||
[[nodiscard]] bool save_current_thread();
|
||||
void remove_and_advance_current_thread();
|
||||
|
||||
@@ -3,19 +3,23 @@
|
||||
#include <BAN/Function.h>
|
||||
#include <BAN/NoCopyMove.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
class Process;
|
||||
|
||||
class Thread : public BAN::RefCounted<Thread>
|
||||
{
|
||||
public:
|
||||
using entry_t = void(*)(void*);
|
||||
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::RefPtr<Thread>> create(entry_t, void* = nullptr);
|
||||
static BAN::ErrorOr<BAN::RefPtr<Thread>> create(entry_t, void* = nullptr, BAN::RefPtr<Process> = nullptr);
|
||||
~Thread();
|
||||
|
||||
uint32_t tid() const { return m_tid; }
|
||||
pid_t tid() const { return m_tid; }
|
||||
|
||||
void set_rsp(uintptr_t rsp) { m_rsp = rsp; }
|
||||
void set_rip(uintptr_t rip) { m_rip = rip; }
|
||||
@@ -25,19 +29,24 @@ namespace Kernel
|
||||
void set_started() { m_started = true; }
|
||||
bool started() const { return m_started; }
|
||||
|
||||
static BAN::RefPtr<Thread> current() ;
|
||||
BAN::RefPtr<Process> process();
|
||||
|
||||
private:
|
||||
Thread();
|
||||
Thread(pid_t tid, BAN::RefPtr<Process>);
|
||||
|
||||
BAN::ErrorOr<void> initialize(entry_t, void*);
|
||||
void on_exit();
|
||||
|
||||
private:
|
||||
void* m_stack_base = nullptr;
|
||||
uintptr_t m_rip = 0;
|
||||
uintptr_t m_rsp = 0;
|
||||
const uint32_t m_tid = 0;
|
||||
bool m_started = false;
|
||||
void* m_stack_base = nullptr;
|
||||
uintptr_t m_rip = 0;
|
||||
uintptr_t m_rsp = 0;
|
||||
const pid_t m_tid = 0;
|
||||
bool m_started = false;
|
||||
BAN::RefPtr<Process> m_process;
|
||||
|
||||
friend class BAN::RefPtr<Thread>;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user