[kernel] Give processes and threads self handles

It was not consistent how processes got handles to themselves or their
threads, ending up with double entries. Now make such handles automatic
and expose them with new self_handle() methods.
This commit is contained in:
Justin C. Miller
2021-01-06 23:14:39 -08:00
parent 1325706c7c
commit 14ed6af433
6 changed files with 18 additions and 4 deletions

View File

@@ -21,13 +21,16 @@ process::process() :
m_state {state::running}
{
s_processes.append(this);
j6_handle_t self = add_handle(this);
kassert(self == self_handle(), "Process self-handle is not 0");
}
// The "kernel process"-only constructor
process::process(page_table *kpml4) :
kobject {kobject::type::process},
m_space {kpml4},
m_next_handle {0},
m_next_handle {self_handle()+1},
m_state {state::running}
{
}
@@ -120,6 +123,7 @@ process::thread_exited(thread *th)
kassert(&th->m_parent == this, "Process got thread_exited for non-child!");
uint32_t status = th->m_return_code;
m_threads.remove_swap(th);
remove_handle(th->self_handle());
delete th;
if (m_threads.count() == 0) {

View File

@@ -68,6 +68,9 @@ public:
/// \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 0; }
/// Get the process object that owns kernel threads and the
/// kernel address space
static process & kernel_process();

View File

@@ -26,6 +26,8 @@ thread::thread(process &parent, uint8_t pri, uintptr_t rsp0) :
setup_kernel_stack();
else
m_tcb.rsp0 = rsp0;
m_self_handle = parent.add_handle(this);
}
thread::~thread()

View File

@@ -141,6 +141,9 @@ public:
/// \arg rip The address to return to, must be user space
void add_thunk_user(uintptr_t rip);
/// Get the handle representing this thread to its process
j6_handle_t self_handle() const { return m_self_handle; }
/// Create the kernel idle thread
/// \arg kernel The process object that owns kernel tasks
/// \arg pri The idle thread priority value
@@ -175,4 +178,6 @@ private:
uint64_t m_wait_data;
j6_status_t m_wait_result;
j6_koid_t m_wait_obj;
j6_handle_t m_self_handle;
};