Changeset 91b60499 in mainline for kernel/generic/src/proc/task.c


Ignore:
Timestamp:
2017-09-30T06:29:42Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
300f4c4
Parents:
d076f16 (diff), 6636fb19 (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 support for capabilities from lp:~jakub/helenos/caps

This commit introduces capabilities as task-local names for references to kernel
objects. Kernel objects are reference-counted wrappers for a select group of
objects allocated in and by the kernel that can be made accessible to userspace
in a controlled way via integer handles.

So far, a kernel object encapsulates either an irq_t or a phone_t.

Support for the former lead to the removal of kernel-assigned devnos and
unsecure deregistration of IRQs in which a random task was able to unregister
some other task's IRQ.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/task.c

    rd076f16 r91b60499  
    5050#include <adt/btree.h>
    5151#include <adt/list.h>
     52#include <cap/cap.h>
    5253#include <ipc/ipc.h>
    5354#include <ipc/ipcrsc.h>
     
    8384static void task_kill_internal(task_t *);
    8485static int tsk_constructor(void *, unsigned int);
     86static size_t tsk_destructor(void *obj);
    8587
    8688/** Initialize kernel tasks support.
     
    9294        avltree_create(&tasks_tree);
    9395        task_slab = slab_cache_create("task_t", sizeof(task_t), 0,
    94             tsk_constructor, NULL, 0);
     96            tsk_constructor, tsk_destructor, 0);
    9597}
    9698
     
    167169        list_initialize(&task->threads);
    168170       
     171        caps_task_alloc(task);
     172       
    169173        ipc_answerbox_init(&task->answerbox, task);
    170174       
    171         size_t i;
    172         for (i = 0; i < IPC_MAX_PHONES; i++)
    173                 ipc_phone_init(&task->phones[i], task);
    174 
    175175        spinlock_initialize(&task->active_calls_lock, "active_calls_lock");
    176176        list_initialize(&task->active_calls);
     
    186186}
    187187
     188size_t tsk_destructor(void *obj)
     189{
     190        task_t *task = (task_t *) obj;
     191       
     192        caps_task_free(task);
     193        return 0;
     194}
     195
    188196/** Create new task with no threads.
    189197 *
     
    206214        task->ucycles = 0;
    207215        task->kcycles = 0;
     216
     217        caps_task_init(task);
    208218
    209219        task->ipc_info.call_sent = 0;
     
    228238       
    229239        if ((ipc_phone_0) &&
    230             (container_check(ipc_phone_0->task->container, task->container)))
    231                 (void) ipc_phone_connect(&task->phones[0], ipc_phone_0);
     240            (container_check(ipc_phone_0->task->container, task->container))) {
     241                cap_handle_t phone_handle = phone_alloc(task);
     242                kobject_t *phone_obj = kobject_get(task, phone_handle,
     243                    KOBJECT_TYPE_PHONE);
     244                (void) ipc_phone_connect(phone_obj->phone, ipc_phone_0);
     245        }
    232246       
    233247        futex_task_init(task);
     
    603617        if (*additional)
    604618                printf("%-8" PRIu64 " %9" PRIu64 "%c %9" PRIu64 "%c "
    605                     "%9" PRIua, task->taskid, ucycles, usuffix, kcycles,
     619                    "%9" PRIua "\n", task->taskid, ucycles, usuffix, kcycles,
    606620                    ksuffix, atomic_get(&task->refcount));
    607621        else
     
    609623                    task->taskid, task->name, task->container, task, task->as);
    610624#endif
    611        
    612         if (*additional) {
    613                 size_t i;
    614                 for (i = 0; i < IPC_MAX_PHONES; i++) {
    615                         if (task->phones[i].callee)
    616                                 printf(" %zu:%p", i, task->phones[i].callee);
    617                 }
    618                 printf("\n");
    619         }
    620625       
    621626        irq_spinlock_unlock(&task->lock, false);
Note: See TracChangeset for help on using the changeset viewer.