[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

@@ -5,14 +5,23 @@
#include <util/map.h>
#include <util/vector.h>
#include "objects/handle.h"
#include "objects/kobject.h"
#include "page_table.h"
#include "vm_space.h"
namespace obj {
class process :
public kobject
{
public:
/// Capabilities on a newly constructed process handle
constexpr static j6_cap_t creation_caps = 0;
/// Capabilities on a process to itself
constexpr static j6_cap_t self_caps = 0;
/// Top of memory area where thread stacks are allocated
constexpr static uintptr_t stacks_top = 0x0000800000000000;
@@ -51,8 +60,9 @@ public:
/// Start tracking an object with a handle.
/// \args obj The object this handle refers to
/// \args caps The capabilities on this handle
/// \returns The new handle for this object
j6_handle_t add_handle(kobject *obj);
j6_handle_t add_handle(kobject *obj, j6_cap_t caps);
/// Stop tracking an object with a handle.
/// \args handle The handle that refers to the object
@@ -61,8 +71,8 @@ public:
/// 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);
/// \returns Pointer to the handle struct, or null if not found
handle * lookup_handle(j6_handle_t handle);
/// Inform the process of an exited thread
/// \args th The thread which has exited
@@ -90,9 +100,12 @@ private:
vm_space m_space;
util::vector<thread*> m_threads;
util::map<j6_handle_t, kobject*> m_handles;
j6_handle_t m_next_handle;
util::map<j6_handle_t, handle> m_handles;
enum class state : uint8_t { running, exited };
state m_state;
};
} // namespace obj