From ad5ebae30435eea1a764bfc547c4ad2dea9794e1 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Thu, 3 Feb 2022 00:04:09 -0800 Subject: [PATCH] [kernel] Let process::add_handle take a handle argument The process::add_handle() method takes an id and an object. This change adds an overridden version that accecpts an actual handle object to copy. --- src/kernel/objects/process.cpp | 13 +++++++++++++ src/kernel/objects/process.h | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/kernel/objects/process.cpp b/src/kernel/objects/process.cpp index 6041255..3f55842 100644 --- a/src/kernel/objects/process.cpp +++ b/src/kernel/objects/process.cpp @@ -135,6 +135,19 @@ process::add_handle(kobject *obj, j6_cap_t caps) return id; } +j6_handle_t +process::add_handle(const handle &hnd) +{ + if (!hnd.object || hnd.id == j6_handle_invalid) + return j6_handle_invalid; + + handle h {m_next_handle++, hnd.object, hnd.caps()}; + j6_handle_t id = h.id; + + m_handles.insert(id, h); + return id; +} + bool process::remove_handle(j6_handle_t id) { diff --git a/src/kernel/objects/process.h b/src/kernel/objects/process.h index 1e19b45..89ad87e 100644 --- a/src/kernel/objects/process.h +++ b/src/kernel/objects/process.h @@ -62,9 +62,14 @@ public: /// Start tracking an object with a handle. /// \args obj The object this handle refers to /// \args caps The capabilities on this handle - /// \returns The new handle for this object + /// \returns The new handle id for this object j6_handle_t add_handle(kobject *obj, j6_cap_t caps); + /// Start tracking an object with a handle. + /// \args hnd An existing handle to copy into this process + /// \returns The new handle id for this object + j6_handle_t add_handle(const handle &hnd); + /// Stop tracking an object with a handle. /// \args handle The handle that refers to the object /// \returns True if the handle was removed