Changeset 9e87562 in mainline for kernel/generic/include/cap/cap.h


Ignore:
Timestamp:
2017-09-18T20:52:12Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6abfd250
Parents:
e5f5ce0
Message:

Make all accesses to capabilites exclusive

This commit makes sure that all accesses to the capabilities array and other
metadata are protected by a mutex. This is necessary for future resizing of the
capabilities array.

Group task's capabilities by type so that it is possible to visit all
capabilities of the given type effectively.

Provide cap_publish() and cap_unpublish() to automate steps that make the
capability visible/invisible to userspace and insert/remove the capability from
the respective type list.

File:
1 edited

Legend:

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

    re5f5ce0 r9e87562  
    3838#include <typedefs.h>
    3939#include <ipc/ipc.h>
     40#include <adt/list.h>
     41#include <synch/mutex.h>
    4042
    4143#define MAX_CAPS  64
    42 
    43 #define for_each_cap(task, cap, type) \
    44         for (int i = 0, l = 1; i < MAX_CAPS && l; i++) \
    45                 for (cap_t *(cap) = cap_get((task), i, (type)); \
    46                     (cap) && !(l = 0); (cap) = NULL, l = 1)
    47 
    48 #define for_each_cap_current(cap, type) \
    49         for_each_cap(TASK, (cap), (type))
    5044
    5145typedef enum {
     
    5347        CAP_TYPE_ALLOCATED,
    5448        CAP_TYPE_PHONE,
    55         CAP_TYPE_IRQ
     49        CAP_TYPE_IRQ,
     50        CAP_TYPE_MAX
    5651} cap_type_t;
    5752
     
    6257        bool (* can_reclaim)(struct cap *);
    6358
     59        /* Link to the task's capabilities of the same type. */
     60        link_t link;
     61
    6462        /* The underlying kernel object. */
    6563        void *kobject;
    6664} cap_t;
    6765
     66typedef struct cap_info {
     67        mutex_t lock;
     68
     69        list_t type_list[CAP_TYPE_MAX];
     70
     71        cap_t *caps;
     72} cap_info_t;
     73
    6874struct task;
    6975
    70 void caps_task_alloc(struct task *);
    71 void caps_task_free(struct task *);
    72 void caps_task_init(struct task *);
     76extern void caps_task_alloc(struct task *);
     77extern void caps_task_free(struct task *);
     78extern void caps_task_init(struct task *);
     79extern bool caps_apply_to_all(struct task *, cap_type_t,
     80    bool (*)(cap_t *, void *), void *);
     81extern void caps_lock(struct task *);
     82extern void caps_unlock(struct task *);
    7383
    7484extern void cap_initialize(cap_t *, int);
    7585extern cap_t *cap_get(struct task *, int, cap_type_t);
    76 extern cap_t *cap_get_current(int, cap_type_t);
    7786extern int cap_alloc(struct task *);
     87extern void cap_publish(struct task *, int, cap_type_t, void *);
     88extern cap_t *cap_unpublish(struct task *, int, cap_type_t);
    7889extern void cap_free(struct task *, int);
    7990
Note: See TracChangeset for help on using the changeset viewer.