Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset ce732e74 in mainline


Ignore:
Timestamp:
2017-10-12T17:59:31Z (3 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
d51838f
Parents:
d29ae35
Message:

Allocate capabilities from a dedicated slab cache

Location:
kernel/generic
Files:
3 edited

Legend:

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

    rd29ae35 rce732e74  
    111111} cap_info_t;
    112112
     113extern void caps_init(void);
    113114extern int caps_task_alloc(struct task *);
    114115extern void caps_task_free(struct task *);
  • kernel/generic/src/cap/cap.c

    rd29ae35 rce732e74  
    8383#define MAX_CAPS        INT_MAX
    8484
     85static slab_cache_t *cap_slab;
     86
    8587static kobject_t *cap_unpublish_locked(task_t *, cap_handle_t, kobject_type_t);
    8688
     
    109111        .key_equal = caps_key_equal
    110112};
     113
     114void caps_init(void)
     115{
     116        cap_slab = slab_cache_create("cap_t", sizeof(cap_t), 0, NULL,
     117            NULL, 0);
     118}
    111119
    112120/** Allocate the capability info structure
     
    267275         */
    268276        if (!cap) {
    269                 cap = malloc(sizeof(cap_t), 0);
     277                cap = slab_alloc(cap_slab, FRAME_ATOMIC);
    270278                if (!cap) {
    271279                        mutex_unlock(&task->cap_info->lock);
     
    274282                uintptr_t hbase;
    275283                if (!ra_alloc(task->cap_info->handles, 1, 1, &hbase)) {
    276                         free(cap);
     284                        slab_free(cap_slab, cap);
    277285                        mutex_unlock(&task->cap_info->lock);
    278286                        return ENOMEM;
     
    370378        hash_table_remove_item(&task->cap_info->caps, &cap->caps_link);
    371379        ra_free(task->cap_info->handles, handle, 1);
    372         free(cap);
     380        slab_free(cap_slab, cap);
    373381        mutex_unlock(&task->cap_info->lock);
    374382}
  • kernel/generic/src/main/main.c

    rd29ae35 rce732e74  
    9292#include <sysinfo/stats.h>
    9393#include <lib/ra.h>
     94#include <cap/cap.h>
    9495
    9596/* Ensure [u]int*_t types are of correct size.
     
    277278        timeout_init();
    278279        scheduler_init();
     280        caps_init();
    279281        task_init();
    280282        thread_init();
Note: See TracChangeset for help on using the changeset viewer.