Progress on capabilities

Capabilities will be shared among collection of threads. A pager
will have a right to share its own capabilities with its space,
its thread group and its container.

Currently sharing is possible with only all of the caps. Next,
it will be support for cap splitting, granting, and partial sharing
and granting.
This commit is contained in:
Bahadir Balban
2009-10-22 14:04:25 +03:00
parent c6bdd65e48
commit 0f9ea9674c
14 changed files with 298 additions and 47 deletions

View File

@@ -8,6 +8,11 @@
/* Capability syscall request types */
#define CAP_CONTROL_NCAPS 0
#define CAP_CONTROL_READ_CAPS 1
#define CAP_CONTROL_READ 1
#define CAP_CONTROL_SHARE 2
#define CAP_SHARE_WITH_SPACE 1
#define CAP_SHARE_WITH_CONTAINER 2
#define CAP_SHARE_WITH_TGROUP 4
#endif /* __API_CAPABILITY_H__ */

View File

@@ -8,6 +8,16 @@
#include <l4/lib/list.h>
/*
* Some resources that capabilities possess don't
* have unique ids or need ids at all.
*
* E.g. a threadpool does not need a resource id.
* A virtual memory capability does not require
* a resource id, its capid is sufficient.
*/
#define CAP_RESID_NONE -1
/*
* A capability is a unique representation of security
* qualifiers on a particular resource.
@@ -65,6 +75,7 @@ struct capability {
};
struct cap_list {
int ktcb_refs;
int ncaps;
struct link caps;
};
@@ -87,12 +98,43 @@ static inline void cap_list_insert(struct capability *cap,
clist->ncaps++;
}
/* Detach a whole list of capabilities from list head */
static inline struct capability *
cap_list_detach(struct cap_list *clist)
{
struct link *list = list_detach(&clist->caps);
clist->ncaps = 0;
return link_to_struct(list, struct capability, list);
}
/* Attach a whole list of capabilities to list head */
static inline void cap_list_attach(struct capability *cap,
struct cap_list *clist)
{
/* Attach as if cap is the list and clist is the element */
list_insert(&clist->caps, &cap->list);
/* Count the number of caps attached */
list_foreach_struct(cap, &clist->caps, list)
clist->ncaps++;
}
static inline void cap_list_move(struct cap_list *to,
struct cap_list *from)
{
struct capability *cap_head = cap_list_detach(from);
cap_list_attach(cap_head, to);
}
struct ktcb;
/* Capability checking for quantitative capabilities */
int capability_consume(struct capability *cap, int quantity);
int capability_free(struct capability *cap, int quantity);
struct capability *capability_find_by_rtype(struct cap_list *clist,
struct capability *capability_find_by_rtype(struct ktcb *task,
unsigned int rtype);
struct capability *cap_list_find_by_rtype(struct cap_list *clist,
unsigned int rtype);
#if 0
/* Virtual memory space allocated to container */
struct capability cap_virtmap = {

View File

@@ -48,6 +48,7 @@ struct container {
struct id_pool *space_id_pool;
struct mutex_queue_head mutex_queue_head; /* Userspace mutex list */
struct cap_list cap_list; /* Capabilities shared by whole container */
/*
* Capabilities that apply to this container

View File

@@ -24,6 +24,7 @@
#include <l4/lib/list.h>
#include <l4/lib/mutex.h>
#include <l4/lib/idpool.h>
#include <l4/generic/capability.h>
#include INC_SUBARCH(mm.h)
/* A simple page table with a reference count */
@@ -32,6 +33,9 @@ struct address_space {
struct link list;
struct mutex lock;
pgd_table_t *pgd;
/* Capabilities shared by threads in same space */
struct cap_list cap_list;
int ktcb_refs;
};

View File

@@ -102,9 +102,9 @@ struct ktcb {
struct container *container;
struct pager *pager;
/* Capability list */
struct cap_list *cap_list_ptr;
/* Capability lists */
struct cap_list cap_list;
struct cap_list tgr_cap_list;
/* Fields for ipc rendezvous */
struct waitqueue_head wqh_recv;

View File

@@ -73,6 +73,18 @@ static inline void list_remove_init(struct link *link)
link->prev = link;
}
/* Cuts the whole list from head and returns it */
static inline struct link *list_detach(struct link *head)
{
struct link *next = head->next;
/* Detach head from rest of the list */
list_remove_init(head);
/* Return detached list */
return next;
}
static inline int list_empty(struct link *list)
{
return list->prev == list && list->next == list;