Changeset 3f74275 in mainline for kernel/generic/src/cap/cap.c


Ignore:
Timestamp:
2017-08-20T16:45:01Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e68765e
Parents:
e7ac23d0
Message:

Fix terminology around capabilities, capability handles and kernel objects

File:
1 moved

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/cap/cap.c

    re7ac23d0 r3f74275  
    3333 */
    3434
    35 #include <kobject/kobject.h>
     35#include <cap/cap.h>
    3636#include <proc/task.h>
    3737#include <synch/spinlock.h>
     
    3939#include <mm/slab.h>
    4040
    41 void kobject_initialize(kobject_t *kobj)
     41void cap_initialize(cap_t *cap)
    4242{
    43         kobj->type = KOBJECT_TYPE_INVALID;
    44         kobj->can_reclaim = NULL;
     43        cap->type = CAP_TYPE_INVALID;
     44        cap->can_reclaim = NULL;
    4545}
    4646
    47 void kobject_task_alloc(task_t *task)
     47void caps_task_alloc(task_t *task)
    4848{
    49         task->kobject = malloc(sizeof(kobject_t) * MAX_KERNEL_OBJECTS, 0);
     49        task->caps = malloc(sizeof(cap_t) * MAX_CAPS, 0);
    5050}
    5151
    52 void kobject_task_init(task_t *task)
     52void caps_task_init(task_t *task)
    5353{
    54         for (int cap = 0; cap < MAX_KERNEL_OBJECTS; cap++)
    55                 kobject_initialize(&task->kobject[cap]);
     54        for (int i = 0; i < MAX_CAPS; i++)
     55                cap_initialize(&task->caps[i]);
    5656}
    5757
    58 void kobject_task_free(task_t *task)
     58void caps_task_free(task_t *task)
    5959{
    60         free(task->kobject);
     60        free(task->caps);
    6161}
    6262
    63 kobject_t *kobject_get(task_t *task, int cap, kobject_type_t type)
     63cap_t *cap_get(task_t *task, int handle, cap_type_t type)
    6464{
    65         if ((cap < 0) || (cap >= MAX_KERNEL_OBJECTS))
     65        if ((handle < 0) || (handle >= MAX_CAPS))
    6666                return NULL;
    67         if (task->kobject[cap].type != type)
     67        if (task->caps[handle].type != type)
    6868                return NULL;
    69         return &task->kobject[cap];
     69        return &task->caps[handle];
    7070}
    7171
    72 kobject_t *kobject_get_current(int cap, kobject_type_t type)
     72cap_t *cap_get_current(int handle, cap_type_t type)
    7373{
    74         return kobject_get(TASK, cap, type);
     74        return cap_get(TASK, handle, type);
    7575}
    7676
    77 int kobject_alloc(task_t *task)
     77int cap_alloc(task_t *task)
    7878{
    79         int cap;
     79        int handle;
    8080
    8181        irq_spinlock_lock(&task->lock, true);
    82         for (cap = 0; cap < MAX_KERNEL_OBJECTS; cap++) {
    83                 kobject_t *kobj = &task->kobject[cap];
    84                 if (kobj->type > KOBJECT_TYPE_ALLOCATED) {
    85                         if (kobj->can_reclaim && kobj->can_reclaim(kobj))
    86                                 kobject_initialize(kobj);
     82        for (handle = 0; handle < MAX_CAPS; handle++) {
     83                cap_t *cap = &task->caps[handle];
     84                if (cap->type > CAP_TYPE_ALLOCATED) {
     85                        if (cap->can_reclaim && cap->can_reclaim(cap))
     86                                cap_initialize(cap);
    8787                }
    88                 if (kobj->type == KOBJECT_TYPE_INVALID) {
    89                         kobj->type = KOBJECT_TYPE_ALLOCATED;
     88                if (cap->type == CAP_TYPE_INVALID) {
     89                        cap->type = CAP_TYPE_ALLOCATED;
    9090                        irq_spinlock_unlock(&task->lock, true);
    91                         return cap;
     91                        return handle;
    9292                }
    9393        }
     
    9797}
    9898
    99 void kobject_free(task_t *task, int cap)
     99void cap_free(task_t *task, int handle)
    100100{
    101         assert(cap >= 0);
    102         assert(cap < MAX_KERNEL_OBJECTS);
    103         assert(task->kobject[cap].type != KOBJECT_TYPE_INVALID);
     101        assert(handle >= 0);
     102        assert(handle < MAX_CAPS);
     103        assert(task->caps[handle].type != CAP_TYPE_INVALID);
    104104
    105105        irq_spinlock_lock(&task->lock, true);
    106         kobject_initialize(&task->kobject[cap]);
     106        cap_initialize(&task->caps[handle]);
    107107        irq_spinlock_unlock(&task->lock, true);
    108108}
    109109
    110 int kobject_to_cap(task_t *task, kobject_t *kobj)
     110int cap_get_handle(task_t *task, cap_t *cap)
    111111{
    112         return kobj - task->kobject;
     112        return cap - task->caps;
    113113}
    114114
Note: See TracChangeset for help on using the changeset viewer.