[kernel] Add syscall helpers

Added the syscalls/helpers.h file to templatize common kobject syscall
operations. Also moved most syscall implementations to using
process::current() and thread::current() instead of asking the
scheduler.
This commit is contained in:
2020-09-23 00:22:15 -07:00
parent 6780ab1b67
commit d4283731e4
12 changed files with 96 additions and 126 deletions

View File

@@ -3,6 +3,7 @@
#include "log.h"
#include "objects/process.h"
#include "objects/thread.h"
#include "scheduler.h"
namespace syscalls {
@@ -10,12 +11,10 @@ namespace syscalls {
j6_status_t
thread_koid(j6_koid_t *koid)
{
if (koid == nullptr) {
if (koid == nullptr)
return j6_err_invalid_arg;
}
TCB *tcb = scheduler::get().current();
*koid = thread::from_tcb(tcb)->koid();
*koid = thread::current().koid();
return j6_status_ok;
}
@@ -23,9 +22,8 @@ j6_status_t
thread_create(void *rip, j6_handle_t *handle)
{
scheduler &s = scheduler::get();
TCB *tcb = s.current();
thread *parent = thread::from_tcb(tcb);
process &p = parent->parent();
thread &parent = thread::current();
process &p = parent.parent();
thread *child = p.create_thread(scheduler::default_priority);
child->add_thunk_user(reinterpret_cast<uintptr_t>(rip));
@@ -33,7 +31,7 @@ thread_create(void *rip, j6_handle_t *handle)
s.add_thread(child->tcb());
log::debug(logs::syscall, "Thread %llx spawned new thread %llx, handle %d",
parent->koid(), child->koid(), *handle);
parent.koid(), child->koid(), *handle);
return j6_status_ok;
}
@@ -42,11 +40,9 @@ j6_status_t
thread_exit(int64_t status)
{
auto &s = scheduler::get();
TCB *tcb = s.current();
thread *th = thread::from_tcb(tcb);
log::debug(logs::syscall, "Thread %llx exiting with code %d", th->koid(), status);
th->exit(status);
thread &th = thread::current();
log::debug(logs::syscall, "Thread %llx exiting with code %d", th.koid(), status);
th.exit(status);
s.schedule();
log::error(logs::syscall, "returned to exit syscall");
@@ -57,9 +53,8 @@ j6_status_t
thread_pause()
{
auto &s = scheduler::get();
TCB *tcb = s.current();
thread *th = thread::from_tcb(tcb);
th->wait_on_signals(th, -1ull);
thread &th = thread::current();
th.wait_on_signals(&th, -1ull);
s.schedule();
return j6_status_ok;
}
@@ -68,11 +63,10 @@ j6_status_t
thread_sleep(uint64_t til)
{
auto &s = scheduler::get();
TCB *tcb = s.current();
thread *th = thread::from_tcb(tcb);
log::debug(logs::syscall, "Thread %llx sleeping until %llu", th->koid(), til);
thread &th = thread::current();
log::debug(logs::syscall, "Thread %llx sleeping until %llu", th.koid(), til);
th->wait_on_time(til);
th.wait_on_time(til);
s.schedule();
return j6_status_ok;
}