From 11eef8d892a3e4db81c87bbf6ef58291ce919ef4 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sat, 15 Jan 2022 09:37:55 -0800 Subject: [PATCH] [kernel] Add process_give_handle syscall This syscall allows a process to give another process access to an object it has a handle to. The value of the handle as seen in the receiver process is returned to the caller, so that the caller may notify the recipient which handle was given. --- definitions/objects/process.def | 7 +++++++ src/kernel/syscalls/process.cpp | 14 ++++++++++++++ 2 files changed, 21 insertions(+) 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