Changeset 132ab5d1 in mainline for kernel/generic/src/cap/cap.c


Ignore:
Timestamp:
2018-01-30T03:20:45Z (8 years ago)
Author:
Jenda <jenda.jzqk73@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5a6cc679
Parents:
8bfb163 (diff), 6a5d05b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge commit '6a5d05bd2551e64111bea4f9332dd7448c26ce84' into forwardport

Separate return value from error code in gen_irq_code*().

File:
1 edited

Legend:

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

    r8bfb163 r132ab5d1  
    4141 * A kernel object (kobject_t) encapsulates one of the following raw objects:
    4242 *
     43 * - IPC call
    4344 * - IPC phone
    4445 * - IRQ object
     
    7374
    7475#include <cap/cap.h>
     76#include <abi/cap.h>
    7577#include <proc/task.h>
    7678#include <synch/mutex.h>
     
    8183#include <stdint.h>
    8284
    83 #define MAX_CAPS        INT_MAX
    84 
    85 static slab_cache_t *cap_slab;
     85#define CAPS_START      (CAP_NIL + 1)
     86#define CAPS_SIZE       (INT_MAX - CAPS_START)
     87#define CAPS_LAST       (CAPS_SIZE - 1)
     88
     89static slab_cache_t *cap_cache;
    8690
    8791static size_t caps_hash(const ht_link_t *item)
     
    112116void caps_init(void)
    113117{
    114         cap_slab = slab_cache_create("cap_t", sizeof(cap_t), 0, NULL,
     118        cap_cache = slab_cache_create("cap_t", sizeof(cap_t), 0, NULL,
    115119            NULL, 0);
    116120}
     
    129133        if (!task->cap_info->handles)
    130134                goto error_handles;
    131         if (!ra_span_add(task->cap_info->handles, 0, MAX_CAPS))
     135        if (!ra_span_add(task->cap_info->handles, CAPS_START, CAPS_SIZE))
    132136                goto error_span;
    133137        if (!hash_table_create(&task->cap_info->caps, 0, 0, &caps_ops))
     
    220224        assert(mutex_locked(&task->cap_info->lock));
    221225
    222         if ((handle < 0) || (handle >= MAX_CAPS))
     226        if ((handle < CAPS_START) || (handle > CAPS_LAST))
    223227                return NULL;
    224228        ht_link_t *link = hash_table_find(&task->cap_info->caps, &handle);
     
    253257 * @param task  Task for which to allocate the new capability.
    254258 *
    255  * @return New capability handle on success.
    256  * @return Negative error code in case of error.
    257  */
    258 cap_handle_t cap_alloc(task_t *task)
     259 * @param[out] handle  New capability handle on success.
     260 *
     261 * @return An error code in case of error.
     262 */
     263int cap_alloc(task_t *task, cap_handle_t *handle)
    259264{
    260265        cap_t *cap = NULL;
    261         cap_handle_t handle;
    262266
    263267        /*
     
    273277         */
    274278        if (!cap) {
    275                 cap = slab_alloc(cap_slab, FRAME_ATOMIC);
     279                cap = slab_alloc(cap_cache, FRAME_ATOMIC);
    276280                if (!cap) {
    277281                        mutex_unlock(&task->cap_info->lock);
     
    280284                uintptr_t hbase;
    281285                if (!ra_alloc(task->cap_info->handles, 1, 1, &hbase)) {
    282                         slab_free(cap_slab, cap);
     286                        slab_free(cap_cache, cap);
    283287                        mutex_unlock(&task->cap_info->lock);
    284288                        return ENOMEM;
     
    289293
    290294        cap->state = CAP_STATE_ALLOCATED;
    291         handle = cap->handle;
    292         mutex_unlock(&task->cap_info->lock);
    293 
    294         return handle;
     295        *handle = cap->handle;
     296        mutex_unlock(&task->cap_info->lock);
     297
     298        return EOK;
    295299}
    296300
     
    357361void cap_free(task_t *task, cap_handle_t handle)
    358362{
    359         assert(handle >= 0);
    360         assert(handle < MAX_CAPS);
     363        assert(handle >= CAPS_START);
     364        assert(handle <= CAPS_LAST);
    361365
    362366        mutex_lock(&task->cap_info->lock);
     
    367371        hash_table_remove_item(&task->cap_info->caps, &cap->caps_link);
    368372        ra_free(task->cap_info->handles, handle, 1);
    369         slab_free(cap_slab, cap);
     373        slab_free(cap_cache, cap);
    370374        mutex_unlock(&task->cap_info->lock);
    371375}
Note: See TracChangeset for help on using the changeset viewer.