[kernel] Add handle_clone syscall

Added the handle_clone syscall which allows for cloning a handle with
a subset of the original handle's capabilities.

Related changes:

- srv.init now calls handle_clone on its system handle, and load_program
  was changed to allow this second system handle to be passed to loaded
  programs instead. However, as drv.uart is still a driver AND a log
  reader, this new handle is not actually passed yet.
- The definition parser was using a set for the cap list, which meant
  the order (and thus values) of caps was not static.
- Some code in objects/handle.h was made more explicit about what bits
  meant what.
This commit is contained in:
Justin C. Miller
2022-01-28 23:40:21 -08:00
parent f1246f84e0
commit bdae812274
7 changed files with 48 additions and 9 deletions

View File

@@ -9,11 +9,18 @@ namespace obj {
struct handle
{
constexpr static uint64_t id_mask = 0x00000000ffffffff;
constexpr static uint64_t cap_mask = 0x00ffffff00000000;
constexpr static uint64_t type_mask = 0xff00000000000000;
constexpr static unsigned cap_shift = 32;
constexpr static unsigned type_shift = 56;
// A j6_handle_t is an id in the low 32 bits, caps in bits 32-55, and type in 56-63
static inline j6_handle_t make_id(j6_handle_t id, j6_cap_t caps, kobject *obj) {
return (id & 0xffffffffull) |
static_cast<j6_handle_t>(caps) << 32 |
static_cast<j6_handle_t>(obj ? obj->get_type() : kobject::type::none) << 56;
((static_cast<j6_handle_t>(caps) << cap_shift) & cap_mask) |
static_cast<j6_handle_t>(obj ? obj->get_type() : kobject::type::none) << type_shift;
}
inline handle(j6_handle_t in_id, kobject *in_obj, j6_cap_t caps) :
@@ -50,7 +57,7 @@ struct handle
if (object) object->handle_release();
}
inline j6_cap_t caps() const { return id >> 32; }
inline j6_cap_t caps() const { return (id & cap_mask) >> cap_shift; }
inline bool has_cap(j6_cap_t test) const {
return (caps() & test) == test;