Kernel: Add argc and argv to process entry

This commit is contained in:
Bananymous
2023-05-16 00:27:49 +03:00
parent e0a7e242f8
commit e0a72defa2
10 changed files with 165 additions and 92 deletions

View File

@@ -2,6 +2,7 @@
#include <BAN/NoCopyMove.h>
#include <BAN/RefPtr.h>
#include <kernel/Memory/Heap.h>
#include <sys/types.h>
@@ -27,11 +28,9 @@ namespace Kernel
public:
static BAN::ErrorOr<Thread*> create(entry_t, void*, Process*);
static BAN::ErrorOr<Thread*> create_userspace(uintptr_t, Process*);
static BAN::ErrorOr<Thread*> create_userspace(uintptr_t, Process*, int, char**);
~Thread();
void jump_userspace(uintptr_t rip);
pid_t tid() const { return m_tid; }
void set_rsp(uintptr_t rsp) { m_rsp = rsp; validate_stack(); }
@@ -44,7 +43,7 @@ namespace Kernel
void terminate() { m_state = State::Terminating; }
uintptr_t stack_base() const { return (uintptr_t)m_stack_base; }
size_t stack_size() const { return m_stack_size; }
size_t stack_size() const { return m_is_userspace ? m_userspace_stack_size : m_kernel_stack_size; }
uintptr_t interrupt_stack_base() const { return (uintptr_t)m_interrupt_stack; }
uintptr_t interrupt_stack_size() const { return m_interrupt_stack_size; }
@@ -57,23 +56,33 @@ namespace Kernel
private:
Thread(pid_t tid, Process*);
void validate_stack() const;
BAN::ErrorOr<void> initialize(entry_t, void*);
void on_exit();
void validate_stack() const;
private:
static constexpr size_t m_stack_size = 4096 * 1;
static constexpr size_t m_interrupt_stack_size = 4096;
void* m_interrupt_stack { nullptr };
void* m_stack_base { nullptr };
struct userspace_entry_t
{
uintptr_t entry;
int argc { 0 };
char** argv { 0 };
};
private:
static constexpr size_t m_kernel_stack_size = PAGE_SIZE * 1;
static constexpr size_t m_userspace_stack_size = PAGE_SIZE * 1;
static constexpr size_t m_interrupt_stack_size = PAGE_SIZE;
vaddr_t m_interrupt_stack { 0 };
vaddr_t m_stack_base { 0 };
uintptr_t m_rip { 0 };
uintptr_t m_rsp { 0 };
const pid_t m_tid { 0 };
State m_state { State::NotStarted };
Process* m_process { nullptr };
bool m_in_syscall { false };
bool m_is_userspace { false };
userspace_entry_t m_userspace_entry;
friend class Scheduler;
};