Ignore:
File:
1 edited

Legend:

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

    rcde999a rc1f68b0  
    4141 * A kernel object (kobject_t) encapsulates one of the following raw objects:
    4242 *
    43  * - IPC call
    4443 * - IPC phone
    4544 * - IRQ object
     
    7473
    7574#include <cap/cap.h>
    76 #include <abi/cap.h>
    7775#include <proc/task.h>
    7876#include <synch/mutex.h>
     
    8381#include <stdint.h>
    8482
    85 #define CAPS_START      (CAP_NIL + 1)
    86 #define CAPS_SIZE       (INT_MAX - CAPS_START)
    87 #define CAPS_LAST       (CAPS_SIZE - 1)
    88 
    89 static slab_cache_t *cap_cache;
     83#define MAX_CAPS        INT_MAX
     84
     85static slab_cache_t *cap_slab;
    9086
    9187static size_t caps_hash(const ht_link_t *item)
     
    116112void caps_init(void)
    117113{
    118         cap_cache = slab_cache_create("cap_t", sizeof(cap_t), 0, NULL,
     114        cap_slab = slab_cache_create("cap_t", sizeof(cap_t), 0, NULL,
    119115            NULL, 0);
    120116}
     
    133129        if (!task->cap_info->handles)
    134130                goto error_handles;
    135         if (!ra_span_add(task->cap_info->handles, CAPS_START, CAPS_SIZE))
     131        if (!ra_span_add(task->cap_info->handles, 0, MAX_CAPS))
    136132                goto error_span;
    137133        if (!hash_table_create(&task->cap_info->caps, 0, 0, &caps_ops))
     
    224220        assert(mutex_locked(&task->cap_info->lock));
    225221
    226         if ((handle < CAPS_START) || (handle > CAPS_LAST))
     222        if ((handle < 0) || (handle >= MAX_CAPS))
    227223                return NULL;
    228224        ht_link_t *link = hash_table_find(&task->cap_info->caps, &handle);
     
    257253 * @param task  Task for which to allocate the new capability.
    258254 *
    259  * @param[out] handle  New capability handle on success.
    260  *
    261  * @return An error code in case of error.
    262  */
    263 int cap_alloc(task_t *task, cap_handle_t *handle)
     255 * @return New capability handle on success.
     256 * @return Negative error code in case of error.
     257 */
     258cap_handle_t cap_alloc(task_t *task)
    264259{
    265260        cap_t *cap = NULL;
     261        cap_handle_t handle;
    266262
    267263        /*
     
    277273         */
    278274        if (!cap) {
    279                 cap = slab_alloc(cap_cache, FRAME_ATOMIC);
     275                cap = slab_alloc(cap_slab, FRAME_ATOMIC);
    280276                if (!cap) {
    281277                        mutex_unlock(&task->cap_info->lock);
     
    284280                uintptr_t hbase;
    285281                if (!ra_alloc(task->cap_info->handles, 1, 1, &hbase)) {
    286                         slab_free(cap_cache, cap);
     282                        slab_free(cap_slab, cap);
    287283                        mutex_unlock(&task->cap_info->lock);
    288284                        return ENOMEM;
     
    293289
    294290        cap->state = CAP_STATE_ALLOCATED;
    295         *handle = cap->handle;
    296         mutex_unlock(&task->cap_info->lock);
    297 
    298         return EOK;
     291        handle = cap->handle;
     292        mutex_unlock(&task->cap_info->lock);
     293
     294        return handle;
    299295}
    300296
     
    361357void cap_free(task_t *task, cap_handle_t handle)
    362358{
    363         assert(handle >= CAPS_START);
    364         assert(handle <= CAPS_LAST);
     359        assert(handle >= 0);
     360        assert(handle < MAX_CAPS);
    365361
    366362        mutex_lock(&task->cap_info->lock);
     
    371367        hash_table_remove_item(&task->cap_info->caps, &cap->caps_link);
    372368        ra_free(task->cap_info->handles, handle, 1);
    373         slab_free(cap_cache, cap);
     369        slab_free(cap_slab, cap);
    374370        mutex_unlock(&task->cap_info->lock);
    375371}
Note: See TracChangeset for help on using the changeset viewer.