diff --git a/definitions/objects/process.def b/definitions/objects/process.def index 8da379b..6113c45 100644 --- a/definitions/objects/process.def +++ b/definitions/objects/process.def @@ -24,4 +24,11 @@ object process : kobject { param entrypoint address # The address of the main thread entrypoint param handles object kobject [list] # A list of parent handles to send to the child process } + + # Give the given process a handle that points to the same + # object as the specified handle. + method give_handle { + param sender object kobject # A handle in the caller process to send + param receiver object kobject [out] # The handle as the recipient will see it + } } diff --git a/src/kernel/syscalls/process.cpp b/src/kernel/syscalls/process.cpp index bdc2437..d046e50 100644 --- a/src/kernel/syscalls/process.cpp +++ b/src/kernel/syscalls/process.cpp @@ -56,4 +56,18 @@ process_exit(int32_t status) return j6_err_unexpected; } +j6_status_t +process_give_handle(j6_handle_t handle, j6_handle_t sender, j6_handle_t *receiver) +{ + process *dest = get_handle(handle); + if (!dest) return j6_err_invalid_arg; + + kobject *o = get_handle(sender); + j6_handle_t out = dest->add_handle(o); + + if (receiver) + *receiver = out; + return j6_status_ok; +} + } // namespace syscalls