Files
jsix_import/src/kernel/syscall.cpp.cog
Justin C. Miller 1d30322820 [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.
2022-01-17 23:23:04 -08:00

84 lines
1.9 KiB
C++

// vim: ft=cpp
#include <stddef.h>
#include <string.h>
#include "debug.h"
#include "logger.h"
#include "syscall.h"
extern "C" {
void syscall_invalid(uint64_t call);
}
size_t __counter_syscall_enter = 0;
size_t __counter_syscall_sysret = 0;
/*[[[cog code generation
from definitions.context import Context
ctx = Context(definitions_path)
ctx.parse("syscalls.def")
syscalls = ctx.interfaces['syscalls']
]]]*/
/// [[[end]]]
namespace syscalls
{
/*[[[cog code generation
last_scope = None
for id, scope, method in syscalls.methods:
if scope != last_scope:
cog.outl()
last_scope = scope
if scope:
name = f"{scope.name}_{method.name}"
else:
name = method.name
args = []
if method.constructor:
args.append("j6_handle_t *self")
elif not method.static:
args.append("j6_handle_t self")
for param in method.params:
for type, suffix in param.type.c_names(param.options):
args.append(f"{type} {param.name}{suffix}")
cog.outl(f"""j6_status_t _syscall_verify_{name} ({", ".join(args)});""")
]]]*/
//[[[end]]]
}
uintptr_t syscall_registry[num_syscalls] __attribute__((section(".syscall_registry")));
void
syscall_invalid(uint64_t call)
{
log::warn(logs::syscall, "Received unknown syscall: %02x\n", call);
}
void
syscall_initialize()
{
memset(&syscall_registry, 0, sizeof(syscall_registry));
/*[[[cog code generation
for id, scope, method in syscalls.methods:
if scope:
name = f"{scope.name}_{method.name}"
else:
name = method.name
cog.outl(f"syscall_registry[{id}] = reinterpret_cast<uintptr_t>(syscalls::_syscall_verify_{name});")
cog.outl(f"""log::debug(logs::syscall, "Enabling syscall {id:02x} as {name}");""")
cog.outl("")
]]]*/
//[[[end]]]
}