Changeset f571ca49 in mainline for kernel/generic/src/cap/cap.c


Ignore:
Timestamp:
2017-11-24T19:00:00Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ac307b2
Parents:
503ffce
Message:

Add CAP_NIL

Sometimes it is useful to have a capability analogy of NULL.

File:
1 edited

Legend:

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

    r503ffce rf571ca49  
    7373
    7474#include <cap/cap.h>
     75#include <abi/cap.h>
    7576#include <proc/task.h>
    7677#include <synch/mutex.h>
     
    8182#include <stdint.h>
    8283
    83 #define MAX_CAPS        INT_MAX
     84#define CAPS_START      (CAP_NIL + 1)
     85#define CAPS_SIZE       (INT_MAX - CAPS_START)
     86#define CAPS_LAST       (CAPS_SIZE - 1)
    8487
    8588static slab_cache_t *cap_slab;
     
    129132        if (!task->cap_info->handles)
    130133                goto error_handles;
    131         if (!ra_span_add(task->cap_info->handles, 0, MAX_CAPS))
     134        if (!ra_span_add(task->cap_info->handles, CAPS_START, CAPS_SIZE))
    132135                goto error_span;
    133136        if (!hash_table_create(&task->cap_info->caps, 0, 0, &caps_ops))
     
    220223        assert(mutex_locked(&task->cap_info->lock));
    221224
    222         if ((handle < 0) || (handle >= MAX_CAPS))
     225        if ((handle < CAPS_START) || (handle > CAPS_LAST))
    223226                return NULL;
    224227        ht_link_t *link = hash_table_find(&task->cap_info->caps, &handle);
     
    357360void cap_free(task_t *task, cap_handle_t handle)
    358361{
    359         assert(handle >= 0);
    360         assert(handle < MAX_CAPS);
     362        assert(handle >= CAPS_START);
     363        assert(handle <= CAPS_LAST);
    361364
    362365        mutex_lock(&task->cap_info->lock);
Note: See TracChangeset for help on using the changeset viewer.