Files
jsix_import/src/kernel/syscalls/endpoint.cpp
Justin C. Miller cd9b85b555 [util] Replace kutil with util
Now that kutil has no kernel-specific code in it anymore, it can
actually be linked to by anything, so I'm renaming it 'util'.

Also, I've tried to unify the way that the system libraries from
src/libraries are #included using <> instead of "".

Other small change: util::bip_buffer got a spinlock to guard against
state corruption.
2022-01-03 00:03:29 -08:00

68 lines
1.6 KiB
C++

#include <j6/errors.h>
#include <j6/types.h>
#include "log.h"
#include "objects/endpoint.h"
#include "syscalls/helpers.h"
namespace syscalls {
j6_status_t
endpoint_create(j6_handle_t *handle)
{
construct_handle<endpoint>(handle);
return j6_status_ok;
}
j6_status_t
endpoint_send(j6_handle_t handle, uint64_t tag, const void * data, size_t data_len)
{
if (tag & j6_tag_system_flag)
return j6_err_invalid_arg;
endpoint *e = get_handle<endpoint>(handle);
if (!e) return j6_err_invalid_arg;
return e->send(tag, data, data_len);
}
j6_status_t
endpoint_receive(j6_handle_t handle, uint64_t * tag, void * data, size_t * data_len)
{
if (!tag || !data_len || (*data_len && !data))
return j6_err_invalid_arg;
endpoint *e = get_handle<endpoint>(handle);
if (!e) return j6_err_invalid_arg;
j6_tag_t out_tag = j6_tag_invalid;
size_t out_len = *data_len;
j6_status_t s = e->receive(&out_tag, data, &out_len);
*tag = out_tag;
*data_len = out_len;
return s;
}
j6_status_t
endpoint_sendrecv(j6_handle_t handle, uint64_t * tag, void * data, size_t * data_len)
{
if (!tag || (*tag & j6_tag_system_flag))
return j6_err_invalid_arg;
endpoint *e = get_handle<endpoint>(handle);
if (!e) return j6_err_invalid_arg;
j6_status_t status = e->send(*tag, data, *data_len);
if (status != j6_status_ok)
return status;
j6_tag_t out_tag = j6_tag_invalid;
size_t out_len = *data_len;
j6_status_t s = e->receive(&out_tag, data, &out_len);
*tag = out_tag;
*data_len = out_len;
return s;
}
} // namespace syscalls