HelenOS sources
#ifndef KERN_CAP_H_
#define KERN_CAP_H_
#include <abi/cap.h>
#include <typedefs.h>
#include <adt/list.h>
#include <adt/hash.h>
#include <adt/hash_table.h>
#include <lib/ra.h>
#include <synch/mutex.h>
#include <atomic.h>
typedef enum {
CAP_STATE_FREE,
CAP_STATE_ALLOCATED,
CAP_STATE_PUBLISHED
} cap_state_t;
typedef enum {
KOBJECT_TYPE_CALL,
KOBJECT_TYPE_IRQ,
KOBJECT_TYPE_PHONE,
KOBJECT_TYPE_WAITQ,
KOBJECT_TYPE_MAX
} kobject_type_t;
struct task;
struct call;
struct irq;
struct phone;
struct waitq;
typedef struct kobject_ops {
void (*destroy)(void *);
} kobject_ops_t;
extern kobject_ops_t *kobject_ops[];
#define KOBJECT_OP(k) kobject_ops[(k)->type]
typedef struct kobject {
kobject_type_t type;
atomic_size_t refcnt;
mutex_t caps_list_lock;
list_t caps_list;
union {
void *raw;
struct call *call;
struct irq *irq;
struct phone *phone;
struct waitq *waitq;
};
} kobject_t;
typedef struct cap {
cap_state_t state;
struct task *task;
cap_handle_t handle;
link_t kobj_link;
link_t type_link;
ht_link_t caps_link;
kobject_t *kobject;
} cap_t;
typedef struct cap_info {
mutex_t lock;
list_t type_list[KOBJECT_TYPE_MAX];
hash_table_t caps;
ra_arena_t *handles;
} cap_info_t;
extern void caps_init(void);
extern errno_t caps_task_alloc(struct task *);
extern void caps_task_free(struct task *);
extern void caps_task_init(struct task *);
extern bool caps_apply_to_kobject_type(struct task *, kobject_type_t,
bool (*)(cap_t *, void *), void *);
extern errno_t cap_alloc(struct task *, cap_handle_t *);
extern void cap_publish(struct task *, cap_handle_t, kobject_t *);
extern kobject_t *cap_unpublish(struct task *, cap_handle_t, kobject_type_t);
extern void cap_revoke(kobject_t *);
extern void cap_free(struct task *, cap_handle_t);
extern kobject_t *kobject_alloc(unsigned int);
extern void kobject_free(kobject_t *);
extern void kobject_initialize(kobject_t *, kobject_type_t, void *);
extern kobject_t *kobject_get(struct task *, cap_handle_t, kobject_type_t);
extern void kobject_add_ref(kobject_t *);
extern void kobject_put(kobject_t *);
#endif
HelenOS homepage, sources at GitHub