[kernel] Add automatic verification to syscalls
Since we have a DSL for specifying syscalls, we can create a verificaton method for each syscall that can cover most argument (and eventually capability) verification instead of doing it piecemeal in each syscall implementation, which can be more error-prone. Now a new _syscall_verify_* function exists for every syscall, which calls the real implementation. The syscall table for the syscall handler now maps to these verify functions. Other changes: - Updated the definition grammar to allow options to have a "key:value" style, to eventually support capabilities. - Added an "optional" option for parameters that says a syscall will accept a null value. - Some bonnibel fixes, as definition file changes weren't always properly causing updates in the build dep graph. - The syscall implementation function signatures are no longer exposed in syscall.h. Also, the unused syscall enum has been removed.
This commit is contained in:
@@ -19,9 +19,6 @@ namespace syscalls {
|
||||
j6_status_t
|
||||
log(const char *message)
|
||||
{
|
||||
if (message == nullptr)
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
thread &th = thread::current();
|
||||
log::info(logs::syscall, "Message[%llx]: %s", th.koid(), message);
|
||||
return j6_status_ok;
|
||||
@@ -36,23 +33,24 @@ noop()
|
||||
}
|
||||
|
||||
j6_status_t
|
||||
system_get_log(j6_handle_t sys, void *buffer, size_t *size)
|
||||
system_get_log(j6_handle_t sys, void *buffer, size_t *buffer_len)
|
||||
{
|
||||
if (!size || (*size && !buffer))
|
||||
// Buffer is marked optional, but we need the length, and if length > 0,
|
||||
// buffer is not optional.
|
||||
if (!buffer_len || (*buffer_len && !buffer))
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
size_t orig_size = *size;
|
||||
*size = g_logger.get_entry(buffer, *size);
|
||||
size_t orig_size = *buffer_len;
|
||||
*buffer_len = g_logger.get_entry(buffer, *buffer_len);
|
||||
if (!g_logger.has_log())
|
||||
system::get().deassert_signal(j6_signal_system_has_log);
|
||||
|
||||
return (*size > orig_size) ? j6_err_insufficient : j6_status_ok;
|
||||
return (*buffer_len > orig_size) ? j6_err_insufficient : j6_status_ok;
|
||||
}
|
||||
|
||||
j6_status_t
|
||||
system_bind_irq(j6_handle_t sys, j6_handle_t endp, unsigned irq)
|
||||
{
|
||||
// TODO: check capabilities on sys handle
|
||||
endpoint *e = get_handle<endpoint>(endp);
|
||||
if (!e) return j6_err_invalid_arg;
|
||||
|
||||
@@ -65,9 +63,6 @@ system_bind_irq(j6_handle_t sys, j6_handle_t endp, unsigned irq)
|
||||
j6_status_t
|
||||
system_map_phys(j6_handle_t handle, j6_handle_t * area, uintptr_t phys, size_t size, uint32_t flags)
|
||||
{
|
||||
// TODO: check capabilities on sys handle
|
||||
if (!area) return j6_err_invalid_arg;
|
||||
|
||||
// TODO: check to see if frames are already used? How would that collide with
|
||||
// the bootloader's allocated pages already being marked used?
|
||||
if (!(flags & vm_flags::mmio))
|
||||
@@ -82,7 +77,6 @@ system_map_phys(j6_handle_t handle, j6_handle_t * area, uintptr_t phys, size_t s
|
||||
j6_status_t
|
||||
system_request_iopl(j6_handle_t handle, unsigned iopl)
|
||||
{
|
||||
// TODO: check capabilities on sys handle
|
||||
if (iopl != 0 && iopl != 3)
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user