mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 16:34:31 -08:00
[kernel] Add syscall helpers
Added the syscalls/helpers.h file to templatize common kobject syscall operations. Also moved most syscall implementations to using process::current() and thread::current() instead of asking the scheduler.
This commit is contained in:
@@ -2,60 +2,39 @@
|
||||
#include "j6/types.h"
|
||||
|
||||
#include "objects/channel.h"
|
||||
#include "objects/process.h"
|
||||
#include "syscalls/helpers.h"
|
||||
|
||||
namespace syscalls {
|
||||
|
||||
j6_status_t
|
||||
channel_create(j6_handle_t *handle)
|
||||
{
|
||||
process &p = process::current();
|
||||
|
||||
channel *c = new channel;
|
||||
*handle = p.add_handle(c);
|
||||
|
||||
construct_handle<channel>(handle);
|
||||
return j6_status_ok;
|
||||
}
|
||||
|
||||
j6_status_t
|
||||
channel_close(j6_handle_t handle)
|
||||
{
|
||||
process &p = process::current();
|
||||
|
||||
kobject *o = p.lookup_handle(handle);
|
||||
if (!o || o->get_type() != kobject::type::channel)
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
p.remove_handle(handle);
|
||||
channel *c = static_cast<channel*>(o);
|
||||
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)
|
||||
{
|
||||
process &p = process::current();
|
||||
|
||||
kobject *o = p.lookup_handle(handle);
|
||||
if (!o || o->get_type() != kobject::type::channel)
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
channel *c = static_cast<channel*>(o);
|
||||
channel *c = get_handle<channel>(handle);
|
||||
if (!c) return j6_err_invalid_arg;
|
||||
return c->enqueue(len, data);
|
||||
}
|
||||
|
||||
j6_status_t
|
||||
channel_receive(j6_handle_t handle, size_t *len, void *data)
|
||||
{
|
||||
process &p = process::current();
|
||||
|
||||
kobject *o = p.lookup_handle(handle);
|
||||
if (!o || o->get_type() != kobject::type::channel)
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
channel *c = static_cast<channel*>(o);
|
||||
channel *c = get_handle<channel>(handle);
|
||||
if (!c) return j6_err_invalid_arg;
|
||||
return c->dequeue(len, data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user