[kernel] Consolodate koid and close syscalls

A number of object types had _close or _koid syscalls. Moved those to be
generic for kobject.
This commit is contained in:
2020-10-05 21:51:42 -07:00
parent 1904e240cf
commit 97ea77bd27
18 changed files with 79 additions and 94 deletions

View File

@@ -78,8 +78,8 @@ channel::dequeue(size_t *len, void *data)
void
channel::close()
{
kobject::close();
g_kernel_buffers.return_buffer(m_data);
assert_signal(j6_signal_channel_closed);
}
void

View File

@@ -37,10 +37,7 @@ public:
/// Mark this channel as closed, all future calls to enqueue or
/// dequeue messages will fail with j6_status_closed.
void close();
/// Check if this channel has been closed
inline bool closed() { return check_signal(j6_signal_channel_closed); }
virtual void close() override;
protected:
virtual void on_no_handles() override;

View File

@@ -10,14 +10,15 @@ endpoint::endpoint() :
endpoint::~endpoint()
{
if (!check_signal(j6_signal_endpoint_closed))
if (!check_signal(j6_signal_closed))
close();
}
void
endpoint::close()
{
assert_signal(j6_signal_endpoint_closed);
kobject::close();
for (auto &data : m_blocked) {
if (data.th)
data.th->wake_on_result(this, j6_status_closed);

View File

@@ -16,7 +16,7 @@ public:
static constexpr kobject::type type = kobject::type::endpoint;
/// Close the endpoint, waking all waiting processes with an error
void close();
virtual void close() override;
/// Check if the endpoint has space for a message to be sent
inline bool can_send() const { return check_signal(j6_signal_endpoint_can_send); }

View File

@@ -61,6 +61,12 @@ kobject::notify_signal_observers()
}
}
void
kobject::close()
{
assert_signal(j6_signal_closed);
}
void
kobject::on_no_handles()
{

View File

@@ -3,6 +3,7 @@
/// Definition of base type for user-interactable kernel objects
#include "j6/errors.h"
#include "j6/signals.h"
#include "j6/types.h"
#include "kutil/vector.h"
@@ -76,6 +77,12 @@ public:
/// Remove the given thread from the list of threads waiting on this object.
inline void remove_blocked_thread(thread *t) { m_blocked_threads.remove_swap(t); }
/// Perform any cleanup actions necessary to mark this object closed
virtual void close();
/// Check if this object has been closed
inline bool closed() const { return check_signal(j6_signal_closed); }
protected:
/// Interface for subclasses to handle when all handles are closed. Subclasses
/// should either call the base version, or assert j6_signal_no_handles.

View File

@@ -1,4 +1,3 @@
#include "j6/signals.h"
#include "kutil/assert.h"
#include "kutil/no_construct.h"
#include "cpu.h"
@@ -62,7 +61,7 @@ process::exit(unsigned code)
thread->exit(code);
}
m_return_code = code;
assert_signal(j6_signal_process_exit);
close();
if (this == bsp_cpu_data.p)
scheduler::get().schedule();

View File

@@ -139,7 +139,7 @@ thread::exit(uint32_t code)
m_return_code = code;
set_state(state::exited);
clear_state(state::ready);
assert_signal(j6_signal_thread_exit);
close();
schedule_if_current(this);
}

View File

@@ -13,15 +13,6 @@ channel_create(j6_handle_t *handle)
return j6_status_ok;
}
j6_status_t
channel_close(j6_handle_t handle)
{
channel *c = remove_handle<channel>(handle);
if (!c) return j6_err_invalid_arg;
c->close();
return j6_status_ok;
}
j6_status_t
channel_send(j6_handle_t handle, size_t *len, void *data)
{

View File

@@ -15,15 +15,6 @@ endpoint_create(j6_handle_t *handle)
return j6_status_ok;
}
j6_status_t
endpoint_close(j6_handle_t handle)
{
endpoint *e = remove_handle<endpoint>(handle);
if (!e) return j6_err_invalid_arg;
e->close();
return j6_status_ok;
}
j6_status_t
endpoint_send(j6_handle_t handle, j6_tag_t tag, size_t len, void *data)
{

View File

@@ -3,6 +3,7 @@
/// Utility functions for use in syscall handler implementations
#include "j6/types.h"
#include "objects/kobject.h"
#include "objects/process.h"
namespace syscalls {
@@ -26,6 +27,13 @@ T * get_handle(j6_handle_t handle)
return static_cast<T*>(o);
}
template <>
inline kobject * get_handle<kobject>(j6_handle_t handle)
{
process &p = process::current();
return p.lookup_handle(handle);
}
template <typename T>
T * remove_handle(j6_handle_t handle)
{

View File

@@ -3,18 +3,29 @@
#include "j6/types.h"
#include "log.h"
#include "objects/process.h"
#include "objects/thread.h"
#include "syscalls/helpers.h"
namespace syscalls {
j6_status_t
object_koid(j6_handle_t handle, j6_koid_t *koid)
{
if (koid == nullptr)
return j6_err_invalid_arg;
kobject *obj = get_handle<kobject>(handle);
if (!obj)
return j6_err_invalid_arg;
*koid = obj->koid();
return j6_status_ok;
}
j6_status_t
object_wait(j6_handle_t handle, j6_signal_t mask, j6_signal_t *sigs)
{
thread &th = thread::current();
process &p = process::current();
kobject *obj = p.lookup_handle(handle);
kobject *obj = get_handle<kobject>(handle);
if (!obj)
return j6_err_invalid_arg;
@@ -24,6 +35,7 @@ object_wait(j6_handle_t handle, j6_signal_t mask, j6_signal_t *sigs)
return j6_status_ok;
}
thread &th = thread::current();
obj->add_blocked_thread(&th);
th.wait_on_signals(obj, mask);
@@ -40,8 +52,7 @@ object_signal(j6_handle_t handle, j6_signal_t signals)
if ((signals & j6_signal_user_mask) != signals)
return j6_err_invalid_arg;
process &p = process::current();
kobject *obj = p.lookup_handle(handle);
kobject *obj = get_handle<kobject>(handle);
if (!obj)
return j6_err_invalid_arg;
@@ -49,4 +60,15 @@ object_signal(j6_handle_t handle, j6_signal_t signals)
return j6_status_ok;
}
j6_status_t
object_close(j6_handle_t handle)
{
kobject *obj = get_handle<kobject>(handle);
if (!obj)
return j6_err_invalid_arg;
obj->close();
return j6_status_ok;
}
} // namespace syscalls

View File

@@ -6,16 +6,6 @@
namespace syscalls {
j6_status_t
process_koid(j6_koid_t *koid)
{
if (koid == nullptr)
return j6_err_invalid_arg;
*koid = process::current().koid();
return j6_status_ok;
}
j6_status_t
process_exit(int64_t status)
{

View File

@@ -7,16 +7,6 @@
namespace syscalls {
j6_status_t
thread_koid(j6_koid_t *koid)
{
if (koid == nullptr)
return j6_err_invalid_arg;
*koid = thread::current().koid();
return j6_status_ok;
}
j6_status_t
thread_create(void *rip, j6_handle_t *handle)
{

View File

@@ -47,17 +47,6 @@ vma_unmap(j6_handle_t handle)
return j6_status_ok;
}
j6_status_t
vma_close(j6_handle_t handle)
{
j6_status_t status = vma_unmap(handle);
if (status != j6_status_ok)
return status;
remove_handle<vm_area>(handle);
return j6_status_ok;
}
j6_status_t
vma_resize(j6_handle_t handle, size_t *size)
{