[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

@@ -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)
{