Files
jsix/src/kernel/objects/process.h
Justin C. Miller cd9b85b555 [util] Replace kutil with util
Now that kutil has no kernel-specific code in it anymore, it can
actually be linked to by anything, so I'm renaming it 'util'.

Also, I've tried to unify the way that the system libraries from
src/libraries are #included using <> instead of "".

Other small change: util::bip_buffer got a spinlock to guard against
state corruption.
2022-01-03 00:03:29 -08:00

99 lines
2.9 KiB
C++

#pragma once
/// \file process.h
/// Definition of process kobject types
#include <util/map.h>
#include <util/vector.h>
#include "objects/kobject.h"
#include "page_table.h"
#include "vm_space.h"
class process :
public kobject
{
public:
/// Top of memory area where thread stacks are allocated
constexpr static uintptr_t stacks_top = 0x0000800000000000;
/// Size of userspace thread stacks
constexpr static size_t stack_size = 0x4000000; // 64MiB
/// Value that represents default priority
constexpr static uint8_t default_priority = 0xff;
/// Constructor.
process();
/// Destructor.
virtual ~process();
static constexpr kobject::type type = kobject::type::process;
/// Get the currently executing process.
static process & current();
/// Terminate this process.
/// \arg code The return code to exit with.
void exit(int32_t code);
/// Update internal bookkeeping about threads.
void update();
/// Get the process' virtual memory space
vm_space & space() { return m_space; }
/// Create a new thread in this process
/// \args rsp3 If non-zero, sets the ring3 stack pointer to this value
/// \args priority The new thread's scheduling priority
/// \returns The newly created thread object
thread * create_thread(uintptr_t rsp3 = 0, uint8_t priorty = default_priority);
/// Start tracking an object with a handle.
/// \args obj The object this handle refers to
/// \returns The new handle for this object
j6_handle_t add_handle(kobject *obj);
/// Stop tracking an object with a handle.
/// \args handle The handle that refers to the object
/// \returns True if the handle was removed
bool remove_handle(j6_handle_t handle);
/// Lookup an object for a handle
/// \args handle The handle to the object
/// \returns Pointer to the object, or null if not found
kobject * lookup_handle(j6_handle_t handle);
/// Inform the process of an exited thread
/// \args th The thread which has exited
/// \returns True if this thread ending has ended the process
bool thread_exited(thread *th);
/// Get the handle for this process to refer to itself
inline j6_handle_t self_handle() const { return 1; }
/// Get the process object that owns kernel threads and the
/// kernel address space
static process & kernel_process();
/// Create the special kernel process that owns kernel tasks
/// \arg pml4 The kernel-only pml4
/// \returns The kernel process object
static process * create_kernel_process(page_table *pml4);
private:
// This constructor is called by create_kernel_process
process(page_table *kpml4);
int32_t m_return_code;
vm_space m_space;
util::vector<thread*> m_threads;
util::map<j6_handle_t, kobject*> m_handles;
j6_handle_t m_next_handle;
enum class state : uint8_t { running, exited };
state m_state;
};