[kernel] Add capabilities to handles

This change finally adds capabilities to handles. Included changes:

- j6_handle_t is now again 64 bits, with the highest 8 bits being a type
  code, and the next highest 24 bits being the capability mask, so that
  programs can check type/caps without calling the kernel.
- The definitions grammar now includes a `capabilities [ ]` section on
  objects, to list what capabilities are relevant.
- j6/caps.h is auto-generated from object capability lists
- init_libj6 again sets __handle_self and __handle_sys, this is a bit
  of a hack.
- A new syscall, j6_handle_list, will return the list of existing
  handles owned by the calling process.
- syscall_verify.cpp.cog now actually checks that the needed
  capabilities exist on handles before allowing the call.
This commit is contained in:
Justin C. Miller
2022-01-28 01:49:26 -08:00
parent 9b75acf0b5
commit f1246f84e0
38 changed files with 290 additions and 177 deletions

View File

@@ -22,8 +22,7 @@ process::process() :
m_next_handle {1},
m_state {state::running}
{
j6_handle_t self = add_handle(this, process::self_caps);
kassert(self == self_handle(), "Process self-handle is not 1");
m_self_handle = add_handle(this, process::self_caps);
}
// The "kernel process"-only constructor
@@ -129,9 +128,10 @@ process::add_handle(kobject *obj, j6_cap_t caps)
if (!obj)
return j6_handle_invalid;
j6_handle_t id = m_next_handle++;
m_handles.insert(id, {id, obj, caps});
handle h {m_next_handle++, obj, caps};
j6_handle_t id = h.id;
m_handles.insert(id, h);
return id;
}
@@ -147,4 +147,16 @@ process::lookup_handle(j6_handle_t id)
return m_handles.find(id);
}
size_t
process::list_handles(j6_handle_t *handles, size_t len)
{
for (const auto &i : m_handles) {
if (len-- == 0)
break;
*handles++ = i.key;
}
return m_handles.count();
}
} // namespace obj