mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
This commit contains a couple large, interdependent changes: - In preparation for capability checking, the _syscall_verify_* functions now load most handles passed in, and verify that they exist and are of the correct type. Lists and out-handles are not converted to objects. - Also in preparation for capability checking, the internal representation of handles has changed. j6_handle_t is now 32 bits, and a new j6_cap_t (also 32 bits) is added. Handles of a process are now a util::map<j6_handle_t, handle> where handle is a new struct containing the id, capabilities, and object pointer. - The kernel object definition DSL gained a few changes to support auto generating the handle -> object conversion in the _syscall_verify_* functions, mostly knowing the object type, and an optional "cname" attribute on objects where their names differ from C++ code. (Specifically vma/vm_area) - Kernel object code and other code under kernel/objects is now in a new obj:: namespace, because fuck you <cstdlib> for putting "system" in the global namespace. Why even have that header then? - Kernel object types constructed with the construct_handle helper now have a creation_caps static member to declare what capabilities a newly created object's handle should have.
69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
#include <j6/errors.h>
|
|
#include <j6/types.h>
|
|
|
|
#include "logger.h"
|
|
#include "objects/endpoint.h"
|
|
#include "syscalls/helpers.h"
|
|
|
|
using namespace obj;
|
|
|
|
namespace syscalls {
|
|
|
|
j6_status_t
|
|
endpoint_create(j6_handle_t *self)
|
|
{
|
|
construct_handle<endpoint>(self);
|
|
return j6_status_ok;
|
|
}
|
|
|
|
j6_status_t
|
|
endpoint_send(endpoint *self, uint64_t tag, const void * data, size_t data_len)
|
|
{
|
|
if (tag & j6_tag_system_flag)
|
|
return j6_err_invalid_arg;
|
|
|
|
return self->send(tag, data, data_len);
|
|
}
|
|
|
|
j6_status_t
|
|
endpoint_receive(endpoint *self, uint64_t * tag, void * data, size_t * data_len, uint64_t timeout)
|
|
{
|
|
// Data is marked optional, but we need the length, and if length > 0,
|
|
// data is not optional.
|
|
if (!data_len || (*data_len && !data))
|
|
return j6_err_invalid_arg;
|
|
|
|
// Use local variables instead of the passed-in pointers, since
|
|
// they may get filled in when the sender is running, which means
|
|
// a different user VM space would be active.
|
|
j6_tag_t out_tag = j6_tag_invalid;
|
|
size_t out_len = *data_len;
|
|
j6_status_t s = self->receive(&out_tag, data, &out_len, timeout);
|
|
*tag = out_tag;
|
|
*data_len = out_len;
|
|
return s;
|
|
}
|
|
|
|
j6_status_t
|
|
endpoint_sendrecv(endpoint *self, uint64_t * tag, void * data, size_t * data_len, uint64_t timeout)
|
|
{
|
|
if (*tag & j6_tag_system_flag)
|
|
return j6_err_invalid_arg;
|
|
|
|
j6_status_t status = self->send(*tag, data, *data_len);
|
|
if (status != j6_status_ok)
|
|
return status;
|
|
|
|
// Use local variables instead of the passed-in pointers, since
|
|
// they may get filled in when the sender is running, which means
|
|
// a different user VM space would be active.
|
|
j6_tag_t out_tag = j6_tag_invalid;
|
|
size_t out_len = *data_len;
|
|
j6_status_t s = self->receive(&out_tag, data, &out_len, timeout);
|
|
*tag = out_tag;
|
|
*data_len = out_len;
|
|
return s;
|
|
}
|
|
|
|
} // namespace syscalls
|