diff --git a/definitions/objects/system.def b/definitions/objects/system.def index b77492d..33f716b 100644 --- a/definitions/objects/system.def +++ b/definitions/objects/system.def @@ -15,7 +15,7 @@ object system : object { # Get a log line from the kernel log method get_log [cap:get_log] { - param buffer buffer [out optional] # Buffer for the log message data structure + param buffer buffer [out zero_ok] # Buffer for the log message data structure } # Ask the kernel to send this process messages whenever diff --git a/definitions/syscalls.def b/definitions/syscalls.def index 00befdb..42dbfde 100644 --- a/definitions/syscalls.def +++ b/definitions/syscalls.def @@ -32,7 +32,7 @@ interface syscalls [syscall] { # supplied list is not big enough, will set the size # needed in `size` and return j6_err_insufficient function handle_list { - param handles ref object [list inout optional] # A list of handles to be filled + param handles ref object [list inout zero_ok] # A list of handles to be filled } # Create a clone of an existing handle, possibly with diff --git a/scripts/definitions/types/function.py b/scripts/definitions/types/function.py index eb3b0e7..66f4354 100644 --- a/scripts/definitions/types/function.py +++ b/scripts/definitions/types/function.py @@ -62,7 +62,7 @@ class Param: @property def optional(self): - if "zero_ok" in self.options: return "zero_ok" - elif "optional" in self.options: return "optional" + if "optional" in self.options: return "optional" + elif "zero_ok" in self.options: return "zero_ok" else: return "required" diff --git a/src/kernel/syscall_verify.cpp.cog b/src/kernel/syscall_verify.cpp.cog index 529f43e..d5357bd 100644 --- a/src/kernel/syscall_verify.cpp.cog +++ b/src/kernel/syscall_verify.cpp.cog @@ -98,11 +98,12 @@ for id, scope, method in syscalls.methods: args.append("self_obj") type = f"obj::{scope.cname} *" - handles.append((type, "self", get_caps(method.options, scope))) + handles.append((scope.cname, "self", get_caps(method.options, scope))) objparams.append((type, "self")) for param in method.params: needs_obj = param.type.needs_object(param.options) + needs_handle = ("handle" in param.options) or needs_obj for type, suffix in param.type.c_names(param.options): arg = f"{param.name}{suffix}" @@ -110,17 +111,22 @@ for id, scope, method in syscalls.methods: for type, suffix in param.type.cxx_names(param.options): arg = f"{param.name}{suffix}" - cxxargdefs.append(f"{type} {arg}") - if needs_obj: - handles.append((type, arg, get_caps(param.options, param.type.object))) - objparams.append((type, arg)) - args.append(f"{arg}_obj") + if needs_handle: + handles.append((param.type.object.cname, arg, get_caps(param.options, param.type.object))) + if needs_obj: + objparams.append((type, arg)) + args.append(f"{arg}_obj") + cxxargdefs.append(f"{type} {arg}") + else: + args.append(f"{arg}_handle") + cxxargdefs.append(f"obj::handle *{arg}_handle") break else: + cxxargdefs.append(f"{type} {arg}") args.append(arg) - if not needs_obj and param.caps: + if not needs_handle and param.caps: handles.append(( f"obj::{param.type.object.cname}", arg, get_caps(param.options, param.type.object))) @@ -152,10 +158,7 @@ for id, scope, method in syscalls.methods: cog.outl() for type, arg, caps in handles: - if type.endswith('*'): - type = type[:-1].strip() - - cog.outl(f" obj::handle *{arg}_handle = get_handle({arg});") + cog.outl(f" obj::handle *{arg}_handle = get_handle({arg});") cog.outl(f" if (!{arg}_handle) return j6_err_invalid_arg;") if caps: diff --git a/src/kernel/syscalls/endpoint.cpp b/src/kernel/syscalls/endpoint.cpp index 9882da7..036def9 100644 --- a/src/kernel/syscalls/endpoint.cpp +++ b/src/kernel/syscalls/endpoint.cpp @@ -28,11 +28,6 @@ endpoint_send(endpoint *self, uint64_t tag, const void * data, size_t data_len) j6_status_t endpoint_receive(endpoint *self, uint64_t * tag, void * data, size_t * data_len, uint64_t timeout) { - // Data is marked optional, but we need the length, and if length > 0, - // data is not optional. - if (!data_len || (*data_len && !data)) - return j6_err_invalid_arg; - // Use local variables instead of the passed-in pointers, since // they may get filled in when the sender is running, which means // a different user VM space would be active. diff --git a/src/kernel/syscalls/handle.cpp b/src/kernel/syscalls/handle.cpp index 31639c5..1c9e9ca 100644 --- a/src/kernel/syscalls/handle.cpp +++ b/src/kernel/syscalls/handle.cpp @@ -11,9 +11,6 @@ namespace syscalls { j6_status_t handle_list(j6_handle_t *handles, size_t *handles_len) { - if (!handles_len || (*handles_len && !handles)) - return j6_err_invalid_arg; - process &p = process::current(); size_t requested = *handles_len; @@ -26,16 +23,12 @@ handle_list(j6_handle_t *handles, size_t *handles_len) } j6_status_t -handle_clone(j6_handle_t orig, j6_handle_t *clone, uint32_t mask) +handle_clone(handle *orig, j6_handle_t *clone, uint32_t mask) { - handle *orig_handle = get_handle(orig); - if (!orig_handle) - return j6_err_invalid_arg; - process &p = process::current(); *clone = p.add_handle( - orig_handle->object, - orig_handle->caps() & mask); + orig->object, + orig->caps() & mask); return j6_status_ok; } diff --git a/src/kernel/syscalls/process.cpp b/src/kernel/syscalls/process.cpp index 221b3ad..c3bfb17 100644 --- a/src/kernel/syscalls/process.cpp +++ b/src/kernel/syscalls/process.cpp @@ -13,7 +13,7 @@ j6_status_t process_create(j6_handle_t *self) { process *p = construct_handle(self); - log::debug(logs::task, "Process %llx created", p->koid()); + log::info(logs::task, "Process %llx created", p->koid()); return j6_status_ok; } @@ -22,7 +22,7 @@ process_kill(process *self) { process &p = process::current(); - log::debug(logs::task, "Process %llx killed by process %llx", self->koid(), p.koid()); + log::info(logs::task, "Process %llx killed by process %llx", self->koid(), p.koid()); self->exit(-1u); return j6_status_ok; @@ -32,7 +32,7 @@ j6_status_t process_exit(int32_t status) { process &p = process::current(); - log::debug(logs::task, "Process %llx exiting with code %d", p.koid(), status); + log::info(logs::task, "Process %llx exiting with code %d", p.koid(), status); p.exit(status); @@ -41,13 +41,12 @@ process_exit(int32_t status) } j6_status_t -process_give_handle(process *self, j6_handle_t target, j6_handle_t *received) +process_give_handle(process *self, handle *target, j6_handle_t *received) { - handle *target_handle = get_handle(target); - j6_handle_t out = self->add_handle(target_handle->object, target_handle->caps()); - + j6_handle_t out = self->add_handle(target->object, target->caps()); if (received) *received = out; + return j6_status_ok; } diff --git a/src/kernel/syscalls/system.cpp b/src/kernel/syscalls/system.cpp index ed4afa3..b22df5b 100644 --- a/src/kernel/syscalls/system.cpp +++ b/src/kernel/syscalls/system.cpp @@ -39,11 +39,6 @@ noop() j6_status_t system_get_log(system *self, void *buffer, size_t *buffer_len) { - // 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 = *buffer_len; *buffer_len = g_logger.get_entry(buffer, *buffer_len); if (!g_logger.has_log())