Changeset 3f74275 in mainline for kernel/generic/src/cap/cap.c
- Timestamp:
- 2017-08-20T16:45:01Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e68765e
- Parents:
- e7ac23d0
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/cap/cap.c
re7ac23d0 r3f74275 33 33 */ 34 34 35 #include < kobject/kobject.h>35 #include <cap/cap.h> 36 36 #include <proc/task.h> 37 37 #include <synch/spinlock.h> … … 39 39 #include <mm/slab.h> 40 40 41 void kobject_initialize(kobject_t *kobj)41 void cap_initialize(cap_t *cap) 42 42 { 43 kobj->type = KOBJECT_TYPE_INVALID;44 kobj->can_reclaim = NULL;43 cap->type = CAP_TYPE_INVALID; 44 cap->can_reclaim = NULL; 45 45 } 46 46 47 void kobject_task_alloc(task_t *task)47 void caps_task_alloc(task_t *task) 48 48 { 49 task-> kobject = malloc(sizeof(kobject_t) * MAX_KERNEL_OBJECTS, 0);49 task->caps = malloc(sizeof(cap_t) * MAX_CAPS, 0); 50 50 } 51 51 52 void kobject_task_init(task_t *task)52 void caps_task_init(task_t *task) 53 53 { 54 for (int cap = 0; cap < MAX_KERNEL_OBJECTS; cap++)55 kobject_initialize(&task->kobject[cap]);54 for (int i = 0; i < MAX_CAPS; i++) 55 cap_initialize(&task->caps[i]); 56 56 } 57 57 58 void kobject_task_free(task_t *task)58 void caps_task_free(task_t *task) 59 59 { 60 free(task-> kobject);60 free(task->caps); 61 61 } 62 62 63 kobject_t *kobject_get(task_t *task, int cap, kobject_type_t type)63 cap_t *cap_get(task_t *task, int handle, cap_type_t type) 64 64 { 65 if (( cap < 0) || (cap >= MAX_KERNEL_OBJECTS))65 if ((handle < 0) || (handle >= MAX_CAPS)) 66 66 return NULL; 67 if (task-> kobject[cap].type != type)67 if (task->caps[handle].type != type) 68 68 return NULL; 69 return &task-> kobject[cap];69 return &task->caps[handle]; 70 70 } 71 71 72 kobject_t *kobject_get_current(int cap, kobject_type_t type)72 cap_t *cap_get_current(int handle, cap_type_t type) 73 73 { 74 return kobject_get(TASK, cap, type);74 return cap_get(TASK, handle, type); 75 75 } 76 76 77 int kobject_alloc(task_t *task)77 int cap_alloc(task_t *task) 78 78 { 79 int cap;79 int handle; 80 80 81 81 irq_spinlock_lock(&task->lock, true); 82 for ( cap = 0; cap < MAX_KERNEL_OBJECTS; cap++) {83 kobject_t *kobj = &task->kobject[cap];84 if ( kobj->type > KOBJECT_TYPE_ALLOCATED) {85 if ( kobj->can_reclaim && kobj->can_reclaim(kobj))86 kobject_initialize(kobj);82 for (handle = 0; handle < MAX_CAPS; handle++) { 83 cap_t *cap = &task->caps[handle]; 84 if (cap->type > CAP_TYPE_ALLOCATED) { 85 if (cap->can_reclaim && cap->can_reclaim(cap)) 86 cap_initialize(cap); 87 87 } 88 if ( kobj->type == KOBJECT_TYPE_INVALID) {89 kobj->type = KOBJECT_TYPE_ALLOCATED;88 if (cap->type == CAP_TYPE_INVALID) { 89 cap->type = CAP_TYPE_ALLOCATED; 90 90 irq_spinlock_unlock(&task->lock, true); 91 return cap;91 return handle; 92 92 } 93 93 } … … 97 97 } 98 98 99 void kobject_free(task_t *task, int cap)99 void cap_free(task_t *task, int handle) 100 100 { 101 assert( cap>= 0);102 assert( cap < MAX_KERNEL_OBJECTS);103 assert(task-> kobject[cap].type != KOBJECT_TYPE_INVALID);101 assert(handle >= 0); 102 assert(handle < MAX_CAPS); 103 assert(task->caps[handle].type != CAP_TYPE_INVALID); 104 104 105 105 irq_spinlock_lock(&task->lock, true); 106 kobject_initialize(&task->kobject[cap]);106 cap_initialize(&task->caps[handle]); 107 107 irq_spinlock_unlock(&task->lock, true); 108 108 } 109 109 110 int kobject_to_cap(task_t *task, kobject_t *kobj)110 int cap_get_handle(task_t *task, cap_t *cap) 111 111 { 112 return kobj - task->kobject;112 return cap - task->caps; 113 113 } 114 114
Note:
See TracChangeset
for help on using the changeset viewer.