Changes in kernel/generic/src/cap/cap.c [c1f68b0:cde999a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/cap/cap.c
rc1f68b0 rcde999a 41 41 * A kernel object (kobject_t) encapsulates one of the following raw objects: 42 42 * 43 * - IPC call 43 44 * - IPC phone 44 45 * - IRQ object … … 73 74 74 75 #include <cap/cap.h> 76 #include <abi/cap.h> 75 77 #include <proc/task.h> 76 78 #include <synch/mutex.h> … … 81 83 #include <stdint.h> 82 84 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 89 static slab_cache_t *cap_cache; 86 90 87 91 static size_t caps_hash(const ht_link_t *item) … … 112 116 void caps_init(void) 113 117 { 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, 115 119 NULL, 0); 116 120 } … … 129 133 if (!task->cap_info->handles) 130 134 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)) 132 136 goto error_span; 133 137 if (!hash_table_create(&task->cap_info->caps, 0, 0, &caps_ops)) … … 220 224 assert(mutex_locked(&task->cap_info->lock)); 221 225 222 if ((handle < 0) || (handle >= MAX_CAPS))226 if ((handle < CAPS_START) || (handle > CAPS_LAST)) 223 227 return NULL; 224 228 ht_link_t *link = hash_table_find(&task->cap_info->caps, &handle); … … 253 257 * @param task Task for which to allocate the new capability. 254 258 * 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 */ 263 int cap_alloc(task_t *task, cap_handle_t *handle) 259 264 { 260 265 cap_t *cap = NULL; 261 cap_handle_t handle;262 266 263 267 /* … … 273 277 */ 274 278 if (!cap) { 275 cap = slab_alloc(cap_ slab, FRAME_ATOMIC);279 cap = slab_alloc(cap_cache, FRAME_ATOMIC); 276 280 if (!cap) { 277 281 mutex_unlock(&task->cap_info->lock); … … 280 284 uintptr_t hbase; 281 285 if (!ra_alloc(task->cap_info->handles, 1, 1, &hbase)) { 282 slab_free(cap_ slab, cap);286 slab_free(cap_cache, cap); 283 287 mutex_unlock(&task->cap_info->lock); 284 288 return ENOMEM; … … 289 293 290 294 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; 295 299 } 296 300 … … 357 361 void cap_free(task_t *task, cap_handle_t handle) 358 362 { 359 assert(handle >= 0);360 assert(handle < MAX_CAPS);363 assert(handle >= CAPS_START); 364 assert(handle <= CAPS_LAST); 361 365 362 366 mutex_lock(&task->cap_info->lock); … … 367 371 hash_table_remove_item(&task->cap_info->caps, &cap->caps_link); 368 372 ra_free(task->cap_info->handles, handle, 1); 369 slab_free(cap_ slab, cap);373 slab_free(cap_cache, cap); 370 374 mutex_unlock(&task->cap_info->lock); 371 375 }
Note:
See TracChangeset
for help on using the changeset viewer.