mirror of
https://github.com/justinian/jsix.git
synced 2025-12-11 08:54:31 -08:00
[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:
82
src/kernel/objects/handle.h
Normal file
82
src/kernel/objects/handle.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
/// \file handle.h
|
||||
/// Definition of kobject handles
|
||||
|
||||
#include <j6/types.h>
|
||||
#include "objects/kobject.h"
|
||||
|
||||
namespace obj {
|
||||
|
||||
struct handle
|
||||
{
|
||||
inline handle(j6_handle_t in_id, kobject *in_object, j6_cap_t in_caps) :
|
||||
id {in_id}, object {in_object}, caps {in_caps} {
|
||||
if (object) object->handle_retain();
|
||||
}
|
||||
|
||||
inline handle(const handle &other) :
|
||||
id {other.id}, object {other.object}, caps {other.caps} {
|
||||
if (object) object->handle_retain();
|
||||
}
|
||||
|
||||
inline handle(handle &&other) :
|
||||
id {other.id}, object {other.object}, caps {other.caps} {
|
||||
other.id = 0;
|
||||
other.caps = 0;
|
||||
other.object = nullptr;
|
||||
}
|
||||
|
||||
inline handle & operator=(const handle &other) {
|
||||
if (object) object->handle_release();
|
||||
id = other.id; caps = other.caps; object = other.object;
|
||||
if (object) object->handle_retain();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline handle & operator=(handle &&other) {
|
||||
if (object) object->handle_release();
|
||||
id = other.id; caps = other.caps; object = other.object;
|
||||
other.id = other.caps = 0; other.object = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline ~handle() {
|
||||
if (object) object->handle_release();
|
||||
}
|
||||
|
||||
inline bool has_cap(j6_cap_t test) const {
|
||||
return (caps & test) == test;
|
||||
}
|
||||
|
||||
inline kobject::type type() const {
|
||||
return object->get_type();
|
||||
}
|
||||
|
||||
inline int compare(const handle &o) {
|
||||
return id > o.id ? 1 : id < o.id ? -1 : 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T * as() {
|
||||
if (type() != T::type) return nullptr;
|
||||
return reinterpret_cast<T*>(object);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline const T * as() const {
|
||||
if (type() != T::type) return nullptr;
|
||||
return reinterpret_cast<const T*>(object);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline kobject * as<kobject>() { return object; }
|
||||
|
||||
template <>
|
||||
inline const kobject * as<kobject>() const { return object; }
|
||||
|
||||
j6_handle_t id;
|
||||
j6_cap_t caps;
|
||||
kobject *object;
|
||||
};
|
||||
|
||||
} // namespace obj
|
||||
Reference in New Issue
Block a user