From 182d3b0a6a075f022e0f0c93e91f94ea0ee841e3 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Wed, 24 Apr 2024 15:48:00 -0700 Subject: [PATCH] [kernel] Add the handle_close syscallnnAdd a generic handle_close syscall and use it in j6::channel when failing to open --- definitions/syscalls.def | 5 +++++ src/kernel/syscalls/handle.cpp | 9 +++++++++ src/libraries/j6/channel.cpp | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/definitions/syscalls.def b/definitions/syscalls.def index b0728d0..4392a73 100644 --- a/definitions/syscalls.def +++ b/definitions/syscalls.def @@ -44,6 +44,11 @@ interface syscalls [syscall] { param mask uint32 # The capability bitmask } + # Close the handle to an object + function handle_close { + param hnd ref object [handle] # The handle to close + } + # Block waiting on a futex function futex_wait [static] { param address uint32* # Address of the futex value diff --git a/src/kernel/syscalls/handle.cpp b/src/kernel/syscalls/handle.cpp index bbb1a11..8a8301b 100644 --- a/src/kernel/syscalls/handle.cpp +++ b/src/kernel/syscalls/handle.cpp @@ -32,4 +32,13 @@ handle_clone(j6_handle_t orig, j6_handle_t *clone, uint32_t mask) return j6_status_ok; } + +j6_status_t +handle_close(j6_handle_t hnd) +{ + process &p = process::current(); + p.remove_handle(hnd); + return j6_status_ok; +} + } // namespace syscalls diff --git a/src/libraries/j6/channel.cpp b/src/libraries/j6/channel.cpp index 4f7e923..17e1174 100644 --- a/src/libraries/j6/channel.cpp +++ b/src/libraries/j6/channel.cpp @@ -79,7 +79,7 @@ channel::create(size_t tx_size, size_t rx_size) uintptr_t rx_addr = create_channel_vma(rx_vma, rx_size); if (!rx_addr) { j6_vma_unmap(tx_vma, 0); - // TODO: Close TX handle + j6_handle_close(tx_vma); return nullptr; } @@ -109,7 +109,7 @@ channel::open(const channel_def &def) result = j6_vma_map(def.rx, 0, &rx_addr, 0); if (result != j6_status_ok) { j6_vma_unmap(def.tx, 0); - // TODO: Close TX handle + j6_handle_close(def.tx); syslog(j6::logs::ipc, j6::log_level::error, "Failed to map channel VMA. Error: %lx", result); return nullptr; }