mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24: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:
@@ -18,8 +18,8 @@ extern "C" {
|
||||
int main(int, const char **);
|
||||
}
|
||||
|
||||
constexpr j6_handle_t handle_self = 1;
|
||||
constexpr j6_handle_t handle_sys = 2;
|
||||
extern j6_handle_t __handle_self;
|
||||
extern j6_handle_t __handle_sys;
|
||||
|
||||
struct entry
|
||||
{
|
||||
@@ -76,13 +76,13 @@ log_pump_proc()
|
||||
void *message_buffer = nullptr;
|
||||
char stringbuf[300];
|
||||
|
||||
j6_status_t result = j6_system_request_iopl(handle_sys, 3);
|
||||
j6_status_t result = j6_system_request_iopl(__handle_sys, 3);
|
||||
if (result != j6_status_ok)
|
||||
return;
|
||||
|
||||
while (true) {
|
||||
size_t size = buffer_size;
|
||||
j6_status_t s = j6_system_get_log(handle_sys, message_buffer, &size);
|
||||
j6_status_t s = j6_system_get_log(__handle_sys, message_buffer, &size);
|
||||
|
||||
if (s == j6_err_insufficient) {
|
||||
free(message_buffer);
|
||||
@@ -96,7 +96,7 @@ log_pump_proc()
|
||||
|
||||
if (size == 0) {
|
||||
j6_signal_t sigs = 0;
|
||||
j6_kobject_wait(handle_sys, j6_signal_system_has_log, &sigs);
|
||||
j6_kobject_wait(__handle_sys, j6_signal_system_has_log, &sigs);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ main(int argc, const char **argv)
|
||||
j6_handle_t endp = j6_handle_invalid;
|
||||
j6_status_t result = j6_status_ok;
|
||||
|
||||
result = j6_system_request_iopl(handle_sys, 3);
|
||||
result = j6_system_request_iopl(__handle_sys, 3);
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
@@ -129,11 +129,11 @@ main(int argc, const char **argv)
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
result = j6_system_bind_irq(handle_sys, endp, 3);
|
||||
result = j6_system_bind_irq(__handle_sys, endp, 3);
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
result = j6_system_bind_irq(handle_sys, endp, 4);
|
||||
result = j6_system_bind_irq(__handle_sys, endp, 4);
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
@@ -153,7 +153,7 @@ main(int argc, const char **argv)
|
||||
sp[0] = sp[1] = 0;
|
||||
|
||||
j6_handle_t child = j6_handle_invalid;
|
||||
result = j6_thread_create(&child, handle_self, stack_top - 0x10, reinterpret_cast<uintptr_t>(&log_pump_proc));
|
||||
result = j6_thread_create(&child, __handle_self, stack_top - 0x10, reinterpret_cast<uintptr_t>(&log_pump_proc));
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ main(int argc, const char **argv)
|
||||
|
||||
size_t initc = 0;
|
||||
j6_init_value *initv = nullptr;
|
||||
_get_init(&initc, &initv);
|
||||
|
||||
j6_init_framebuffer *fb = nullptr;
|
||||
for (unsigned i = 0; i < initc; ++i) {
|
||||
|
||||
@@ -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