Files
jsix_import/src/kernel/syscalls/mailbox.cpp
Justin C. Miller 9fa588566f [kernel] First steps at removing channel objects
This commit does a number of things to start the transition of channels
from kernel to user space:

- Remove channel objects / syscalls from the kernel
- Add mutex type in libj6
- Add condition type in libj6
- Add a `ring` type flag for VMA syscalls to create ring buffers
- Implement a rudimentary shared memory channel using all of the above
2023-03-16 19:56:14 -07:00

88 lines
1.6 KiB
C++

#include <j6/errors.h>
#include <j6/flags.h>
#include <util/util.h>
#include "objects/mailbox.h"
#include "objects/thread.h"
#include "syscalls/helpers.h"
using namespace obj;
namespace syscalls {
j6_status_t
mailbox_create(j6_handle_t *self)
{
construct_handle<mailbox>(self);
return j6_status_ok;
}
j6_status_t
mailbox_close(mailbox *self)
{
if (self->closed())
return j6_status_closed;
self->close();
return j6_status_ok;
}
j6_status_t
mailbox_call(
mailbox *self,
uint64_t *tag,
uint64_t *subtag,
j6_handle_t *handle)
{
thread::message_data &data =
thread::current().get_message_data();
data.tag = *tag;
data.subtag = *subtag;
data.handle = *handle;
j6_status_t s = self->call();
if (s != j6_status_ok)
return s;
*tag = data.tag;
*subtag = data.subtag;
*handle = data.handle;
process::current().add_handle(*handle);
return j6_status_ok;
}
j6_status_t
mailbox_respond(
mailbox *self,
uint64_t *tag,
uint64_t *subtag,
j6_handle_t *handle,
uint64_t *reply_tag,
uint64_t flags)
{
thread::message_data data { *tag, *subtag, *handle };
if (*reply_tag) {
j6_status_t s = self->reply(*reply_tag, data);
if (s != j6_status_ok)
return s;
}
bool block = flags & j6_flag_block;
j6_status_t s = self->receive(data, *reply_tag, block);
if (s != j6_status_ok)
return s;
*tag = data.tag;
*subtag = data.subtag;
*handle = data.handle;
process::current().add_handle(*handle);
return j6_status_ok;
}
} // namespace syscalls