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

Changeset c46bfbc in mainline


Ignore:
Timestamp:
2017-10-10T15:34:37Z (3 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
33f86a3
Parents:
cccd60c3
Message:

Allow caps_task_alloc() to fail

Location:
kernel/generic
Files:
3 edited

Legend:

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

    rcccd60c3 rc46bfbc  
    111111} cap_info_t;
    112112
    113 extern void caps_task_alloc(struct task *);
     113extern int caps_task_alloc(struct task *);
    114114extern void caps_task_free(struct task *);
    115115extern void caps_task_init(struct task *);
  • kernel/generic/src/cap/cap.c

    rcccd60c3 rc46bfbc  
    114114 * @param task  Task for which to allocate the info structure.
    115115 */
    116 void caps_task_alloc(task_t *task)
    117 {
    118         task->cap_info = (cap_info_t *) malloc(sizeof(cap_info_t), 0);
     116int caps_task_alloc(task_t *task)
     117{
     118        task->cap_info = (cap_info_t *) malloc(sizeof(cap_info_t),
     119            FRAME_ATOMIC);
     120        if (!task->cap_info)
     121                return ENOMEM;
    119122        task->cap_info->handles = ra_arena_create();
    120         // FIXME: allow caps_task_alloc() to fail
    121         assert(task->cap_info->handles);
    122         bool success = ra_span_add(task->cap_info->handles, 0, MAX_CAPS);
    123         // FIXME: allow caps_task_alloc() to fail
    124         assert(success);
    125         success = hash_table_create(&task->cap_info->caps, 0, 0, &caps_ops);
    126         // FIXME: allow caps_task_alloc() to fail
    127         assert(success);
     123        if (!task->cap_info->handles)
     124                goto error_handles;
     125        if (!ra_span_add(task->cap_info->handles, 0, MAX_CAPS))
     126                goto error_span;
     127        if (!hash_table_create(&task->cap_info->caps, 0, 0, &caps_ops))
     128                goto error_span;
     129        return EOK;
     130
     131error_span:
     132        ra_arena_destroy(task->cap_info->handles);
     133error_handles:
     134        free(task->cap_info);
     135        return ENOMEM;
    128136}
    129137
  • kernel/generic/src/proc/task.c

    rcccd60c3 rc46bfbc  
    161161{
    162162        task_t *task = (task_t *) obj;
     163
     164        int rc = caps_task_alloc(task);
     165        if (rc != EOK)
     166                return rc;
    163167       
    164168        atomic_set(&task->refcount, 0);
     
    168172       
    169173        list_initialize(&task->threads);
    170        
    171         caps_task_alloc(task);
    172174       
    173175        ipc_answerbox_init(&task->answerbox, task);
Note: See TracChangeset for help on using the changeset viewer.