[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

@@ -0,0 +1,40 @@
#pragma once
/// \file syscalls/helpers.h
/// Utility functions for use in syscall handler implementations
#include "j6/types.h"
#include "objects/process.h"
namespace syscalls {
template <typename T, typename... Args>
T * construct_handle(j6_handle_t *handle, Args... args)
{
process &p = process::current();
T *o = new T {args...};
*handle = p.add_handle(o);
return o;
}
template <typename T>
T * get_handle(j6_handle_t handle)
{
process &p = process::current();
kobject *o = p.lookup_handle(handle);
if (!o || o->get_type() != T::type)
return nullptr;
return static_cast<T*>(o);
}
template <typename T>
T * remove_handle(j6_handle_t handle)
{
T *o = get_handle<T>(handle);
if (o) {
process &p = process::current();
p.remove_handle(handle);
}
return o;
}
}