[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:
@@ -12,8 +12,8 @@
|
||||
using bootproto::module_flags;
|
||||
using bootproto::module_program;
|
||||
|
||||
extern j6_handle_t handle_self;
|
||||
extern j6_handle_t handle_system;
|
||||
extern j6_handle_t __handle_self;
|
||||
extern j6_handle_t __handle_sys;
|
||||
|
||||
constexpr uintptr_t load_addr_base = 0xf8000000;
|
||||
constexpr size_t stack_size = 0x10000;
|
||||
@@ -28,13 +28,13 @@ load_program(const module_program &prog, char *err_msg)
|
||||
}
|
||||
|
||||
j6_handle_t elf_vma = j6_handle_invalid;
|
||||
j6_status_t res = j6_system_map_phys(handle_system, &elf_vma, prog.base_address, prog.size, 0);
|
||||
j6_status_t res = j6_system_map_phys(__handle_sys, &elf_vma, prog.base_address, prog.size, 0);
|
||||
if (res != j6_status_ok) {
|
||||
sprintf(err_msg, " ** error loading program '%s': creating physical vma: %lx", prog.filename, res);
|
||||
return false;
|
||||
}
|
||||
|
||||
res = j6_vma_map(elf_vma, handle_self, prog.base_address);
|
||||
res = j6_vma_map(elf_vma, __handle_self, prog.base_address);
|
||||
if (res != j6_status_ok) {
|
||||
sprintf(err_msg, " ** error loading program '%s': mapping vma: %lx", prog.filename, res);
|
||||
return false;
|
||||
@@ -55,7 +55,7 @@ load_program(const module_program &prog, char *err_msg)
|
||||
return false;
|
||||
}
|
||||
|
||||
res = j6_process_give_handle(proc, handle_system, nullptr);
|
||||
res = j6_process_give_handle(proc, __handle_sys, nullptr);
|
||||
if (res != j6_status_ok) {
|
||||
sprintf(err_msg, " ** error loading program '%s': giving system handle: %lx", prog.filename, res);
|
||||
return false;
|
||||
@@ -90,7 +90,7 @@ load_program(const module_program &prog, char *err_msg)
|
||||
return false;
|
||||
}
|
||||
|
||||
res = j6_vma_unmap(sub_vma, handle_self);
|
||||
res = j6_vma_unmap(sub_vma, __handle_self);
|
||||
if (res != j6_status_ok) {
|
||||
sprintf(err_msg, " ** error loading program '%s': unmapping sub vma: %lx", prog.filename, res);
|
||||
return false;
|
||||
@@ -115,7 +115,7 @@ load_program(const module_program &prog, char *err_msg)
|
||||
return false;
|
||||
}
|
||||
|
||||
res = j6_vma_unmap(stack_vma, handle_self);
|
||||
res = j6_vma_unmap(stack_vma, __handle_self);
|
||||
if (res != j6_status_ok) {
|
||||
sprintf(err_msg, " ** error loading program '%s': unmapping stack vma: %lx", prog.filename, res);
|
||||
return false;
|
||||
@@ -128,7 +128,7 @@ load_program(const module_program &prog, char *err_msg)
|
||||
return false;
|
||||
}
|
||||
|
||||
res = j6_vma_unmap(elf_vma, handle_self);
|
||||
res = j6_vma_unmap(elf_vma, __handle_self);
|
||||
if (res != j6_status_ok) {
|
||||
sprintf(err_msg, " ** error loading program '%s': unmapping elf vma: %lx", prog.filename, res);
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <j6/errors.h>
|
||||
#include <j6/syscalls.h>
|
||||
#include <j6/types.h>
|
||||
#include <bootproto/init.h>
|
||||
|
||||
#include "loader.h"
|
||||
@@ -16,15 +19,15 @@ extern "C" {
|
||||
|
||||
uintptr_t _arg_modules_phys; // This gets filled in in _start
|
||||
|
||||
j6_handle_t handle_self = 1; // Self program handle is always 1
|
||||
j6_handle_t handle_system = 2; // boot protocol is that init gets the system as handle 2
|
||||
extern j6_handle_t __handle_self;
|
||||
extern j6_handle_t __handle_sys;
|
||||
|
||||
int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
j6_log("srv.init starting");
|
||||
|
||||
modules mods = modules::load_modules(_arg_modules_phys, handle_system, handle_self);
|
||||
modules mods = modules::load_modules(_arg_modules_phys, __handle_sys, __handle_self);
|
||||
|
||||
for (auto &mod : mods.of_type(module_type::program)) {
|
||||
auto &prog = static_cast<const module_program&>(mod);
|
||||
|
||||
Reference in New Issue
Block a user