mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[kernel] Add capabilities to handles
This change finally adds capabilities to handles. Included changes: - j6_handle_t is now again 64 bits, with the highest 8 bits being a type code, and the next highest 24 bits being the capability mask, so that programs can check type/caps without calling the kernel. - The definitions grammar now includes a `capabilities [ ]` section on objects, to list what capabilities are relevant. - j6/caps.h is auto-generated from object capability lists - init_libj6 again sets __handle_self and __handle_sys, this is a bit of a hack. - A new syscall, j6_handle_list, will return the list of existing handles owned by the calling process. - syscall_verify.cpp.cog now actually checks that the needed capabilities exist on handles before allowing the call.
This commit is contained in:
@@ -3,45 +3,47 @@
|
||||
#ifndef __j6kernel
|
||||
|
||||
#include <stdint.h>
|
||||
#include <j6/errors.h>
|
||||
#include <j6/init.h>
|
||||
#include <j6/syscalls.h>
|
||||
#include <j6/types.h>
|
||||
|
||||
static size_t __initc = 0;
|
||||
static struct j6_init_value *__initv = 0;
|
||||
|
||||
j6_handle_t __handle_sys = j6_handle_invalid;
|
||||
j6_handle_t __handle_self = j6_handle_invalid;
|
||||
|
||||
extern "C" void
|
||||
_get_init(size_t *initc, struct j6_init_value **initv)
|
||||
{
|
||||
if (!initc)
|
||||
return;
|
||||
namespace {
|
||||
constexpr size_t __static_arr_size = 4;
|
||||
j6_handle_t __handle_array[__static_arr_size];
|
||||
|
||||
*initc = __initc;
|
||||
if (initv)
|
||||
*initv = __initv;
|
||||
}
|
||||
static j6_status_t
|
||||
__load_handles()
|
||||
{
|
||||
size_t count = __static_arr_size;
|
||||
j6_handle_t *handles = __handle_array;
|
||||
j6_status_t s = j6_handle_list(handles, &count);
|
||||
|
||||
if (s != j6_err_insufficient && s != j6_status_ok)
|
||||
return s;
|
||||
|
||||
if (count > __static_arr_size)
|
||||
count = __static_arr_size;
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
uint8_t type = (handles[i] >> 56);
|
||||
if (type == j6_object_type_system && __handle_sys == j6_handle_invalid)
|
||||
__handle_sys = handles[i];
|
||||
else if (type == j6_object_type_process && __handle_self == j6_handle_invalid)
|
||||
__handle_self = handles[i];
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" void
|
||||
_init_libj6(uint64_t *rsp)
|
||||
{
|
||||
uint64_t argc = *rsp++;
|
||||
rsp += argc;
|
||||
|
||||
__initc = *rsp++;
|
||||
__initv = (struct j6_init_value *)rsp;
|
||||
|
||||
for (unsigned i = 0; i < __initc; ++i) {
|
||||
if (__initv[i].type == j6_init_handle_other &&
|
||||
__initv[i].handle.type == j6_object_type_system) {
|
||||
__handle_sys = __initv[i].handle.handle;
|
||||
}
|
||||
else if (__initv[i].type == j6_init_handle_self &&
|
||||
__initv[i].handle.type == j6_object_type_process) {
|
||||
__handle_self = __initv[i].handle.handle;
|
||||
}
|
||||
}
|
||||
__load_handles();
|
||||
}
|
||||
|
||||
#endif // __j6kernel
|
||||
|
||||
Reference in New Issue
Block a user