[kernel] Pass objects not handles to syscall impls

This commit contains a couple large, interdependent changes:

- In preparation for capability checking, the _syscall_verify_*
  functions now load most handles passed in, and verify that they exist
  and are of the correct type. Lists and out-handles are not converted
  to objects.
- Also in preparation for capability checking, the internal
  representation of handles has changed. j6_handle_t is now 32 bits, and
  a new j6_cap_t (also 32 bits) is added. Handles of a process are now a
  util::map<j6_handle_t, handle> where handle is a new struct containing
  the id, capabilities, and object pointer.
- The kernel object definition DSL gained a few changes to support auto
  generating the handle -> object conversion in the _syscall_verify_*
  functions, mostly knowing the object type, and an optional "cname"
  attribute on objects where their names differ from C++ code.
  (Specifically vma/vm_area)
- Kernel object code and other code under kernel/objects is now in a new
  obj:: namespace, because fuck you <cstdlib> for putting "system" in
  the global namespace. Why even have that header then?
- Kernel object types constructed with the construct_handle helper now
  have a creation_caps static member to declare what capabilities a
  newly created object's handle should have.
This commit is contained in:
Justin C. Miller
2022-01-17 23:23:04 -08:00
parent e0246df26b
commit 1d30322820
50 changed files with 492 additions and 300 deletions

View File

@@ -10,38 +10,41 @@
namespace syscalls {
template <typename T, typename... Args>
T * construct_handle(j6_handle_t *handle, Args... args)
T * construct_handle(j6_handle_t *id, Args... args)
{
process &p = process::current();
obj::process &p = obj::process::current();
T *o = new T {args...};
*handle = p.add_handle(o);
*id = p.add_handle(o, T::creation_caps);
return o;
}
template <typename T>
T * get_handle(j6_handle_t handle)
obj::handle * get_handle(j6_handle_t id)
{
process &p = process::current();
kobject *o = p.lookup_handle(handle);
if (!o || o->get_type() != T::type)
obj::process &p = obj::process::current();
obj::handle *h = p.lookup_handle(id);
if (!h || h->type() != T::type)
return nullptr;
return static_cast<T*>(o);
return h;
}
template <>
inline kobject * get_handle<kobject>(j6_handle_t handle)
inline obj::handle * get_handle<obj::kobject>(j6_handle_t id)
{
process &p = process::current();
return p.lookup_handle(handle);
obj::process &p = obj::process::current();
return p.lookup_handle(id);
}
template <typename T>
T * remove_handle(j6_handle_t handle)
T * remove_handle(j6_handle_t id)
{
T *o = get_handle<T>(handle);
if (o) {
process &p = process::current();
p.remove_handle(handle);
obj::handle *h = get_handle<T>(id);
T *o = nullptr;
if (h) {
o = h->object;
obj::process &p = obj::process::current();
p.remove_handle(id);
}
return o;
}