Changeset 48bcf49 in mainline for kernel/generic/include/cap/cap.h


Ignore:
Timestamp:
2017-09-28T22:08:15Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6636fb19
Parents:
dd20cbb
Message:

Introduce reference-counted kobjects

Capabilities are thus reduced to task-local names for references to kobjects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/cap/cap.h

    rdd20cbb r48bcf49  
    3737
    3838#include <typedefs.h>
    39 #include <ipc/ipc.h>
    4039#include <adt/list.h>
    4140#include <synch/mutex.h>
     41#include <atomic.h>
    4242
    4343#define MAX_CAPS  64
    4444
     45typedef int cap_handle_t;
     46
    4547typedef enum {
    46         CAP_TYPE_INVALID,
    47         CAP_TYPE_ALLOCATED,
    48         CAP_TYPE_PHONE,
    49         CAP_TYPE_IRQ,
    50         CAP_TYPE_MAX
    51 } cap_type_t;
     48        CAP_STATE_FREE,
     49        CAP_STATE_ALLOCATED,
     50        CAP_STATE_PUBLISHED
     51} cap_state_t;
     52
     53typedef enum {
     54        KOBJECT_TYPE_PHONE,
     55        KOBJECT_TYPE_IRQ,
     56        KOBJECT_TYPE_MAX
     57} kobject_type_t;
     58
     59struct task;
     60struct phone;
     61struct irq;
     62
     63struct kobject;
     64typedef struct kobject_ops {
     65        bool (*reclaim)(struct kobject *);
     66        void (*destroy)(void *);
     67} kobject_ops_t;
     68
     69typedef struct kobject {
     70        kobject_type_t type;
     71        atomic_t refcnt;
     72
     73        kobject_ops_t *ops;
     74
     75        union {
     76                void *raw;
     77                struct phone *phone;
     78                struct irq *irq;
     79        };
     80} kobject_t;
    5281
    5382typedef struct cap {
    54         cap_type_t type;
    55         int handle;
     83        cap_state_t state;
    5684
    57         bool (* can_reclaim)(struct cap *);
     85        cap_handle_t handle;
    5886
    59         /* Link to the task's capabilities of the same type. */
     87        /* Link to the task's capabilities of the same kobject type. */
    6088        link_t link;
    6189
    6290        /* The underlying kernel object. */
    63         void *kobject;
     91        kobject_t *kobject;
    6492} cap_t;
    6593
     
    6795        mutex_t lock;
    6896
    69         list_t type_list[CAP_TYPE_MAX];
     97        list_t type_list[KOBJECT_TYPE_MAX];
    7098
    7199        cap_t *caps;
    72100} cap_info_t;
    73101
    74 struct task;
    75 
    76102extern void caps_task_alloc(struct task *);
    77103extern void caps_task_free(struct task *);
    78104extern void caps_task_init(struct task *);
    79 extern bool caps_apply_to_type(struct task *, cap_type_t,
     105extern bool caps_apply_to_kobject_type(struct task *, kobject_type_t,
    80106    bool (*)(cap_t *, void *), void *);
    81 extern void caps_lock(struct task *);
    82 extern void caps_unlock(struct task *);
    83107
    84 extern void cap_initialize(cap_t *, int);
    85 extern cap_t *cap_get(struct task *, int, cap_type_t);
    86 extern int cap_alloc(struct task *);
    87 extern void cap_publish(struct task *, int, cap_type_t, void *);
    88 extern cap_t *cap_unpublish(struct task *, int, cap_type_t);
    89 extern void cap_free(struct task *, int);
     108extern void cap_initialize(cap_t *, cap_handle_t);
     109extern cap_handle_t cap_alloc(struct task *);
     110extern void cap_publish(struct task *, cap_handle_t, kobject_t *);
     111extern kobject_t *cap_unpublish(struct task *, cap_handle_t, kobject_type_t);
     112extern void cap_free(struct task *, cap_handle_t);
     113
     114extern void kobject_initialize(kobject_t *, kobject_type_t, void *,
     115    kobject_ops_t *);
     116extern kobject_t *kobject_get(struct task *, cap_handle_t, kobject_type_t);
     117extern void kobject_put(kobject_t *);
    90118
    91119#endif
Note: See TracChangeset for help on using the changeset viewer.