Ignore:
File:
1 edited

Legend:

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

    rfeeac0d rc46bfbc  
    3636 */
    3737
     38#include <assert.h>
    3839#include <proc/thread.h>
    3940#include <proc/task.h>
     
    4142#include <mm/slab.h>
    4243#include <atomic.h>
     44#include <synch/futex.h>
    4345#include <synch/spinlock.h>
    4446#include <synch/waitq.h>
     
    4850#include <adt/btree.h>
    4951#include <adt/list.h>
     52#include <cap/cap.h>
    5053#include <ipc/ipc.h>
    5154#include <ipc/ipcrsc.h>
     
    5558#include <func.h>
    5659#include <str.h>
    57 #include <memstr.h>
    5860#include <syscall/copy.h>
    5961#include <macros.h>
     
    8284static void task_kill_internal(task_t *);
    8385static int tsk_constructor(void *, unsigned int);
     86static size_t tsk_destructor(void *obj);
    8487
    8588/** Initialize kernel tasks support.
     
    9194        avltree_create(&tasks_tree);
    9295        task_slab = slab_cache_create("task_t", sizeof(task_t), 0,
    93             tsk_constructor, NULL, 0);
     96            tsk_constructor, tsk_destructor, 0);
    9497}
    9598
     
    158161{
    159162        task_t *task = (task_t *) obj;
     163
     164        int rc = caps_task_alloc(task);
     165        if (rc != EOK)
     166                return rc;
    160167       
    161168        atomic_set(&task->refcount, 0);
     
    163170       
    164171        irq_spinlock_initialize(&task->lock, "task_t_lock");
    165         mutex_initialize(&task->futexes_lock, MUTEX_PASSIVE);
    166172       
    167173        list_initialize(&task->threads);
     
    169175        ipc_answerbox_init(&task->answerbox, task);
    170176       
    171         size_t i;
    172         for (i = 0; i < IPC_MAX_PHONES; i++)
    173                 ipc_phone_init(&task->phones[i], task);
    174 
    175177        spinlock_initialize(&task->active_calls_lock, "active_calls_lock");
    176178        list_initialize(&task->active_calls);
    177        
     179               
    178180#ifdef CONFIG_UDEBUG
    179181        /* Init kbox stuff */
     
    186188}
    187189
     190size_t tsk_destructor(void *obj)
     191{
     192        task_t *task = (task_t *) obj;
     193       
     194        caps_task_free(task);
     195        return 0;
     196}
     197
    188198/** Create new task with no threads.
    189199 *
     
    203213       
    204214        task->container = CONTAINER;
    205         task->capabilities = 0;
     215        task->perms = 0;
    206216        task->ucycles = 0;
    207217        task->kcycles = 0;
     218
     219        caps_task_init(task);
    208220
    209221        task->ipc_info.call_sent = 0;
     
    228240       
    229241        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);
    232        
    233         btree_create(&task->futexes);
     242            (container_check(ipc_phone_0->task->container, task->container))) {
     243                cap_handle_t phone_handle = phone_alloc(task);
     244                kobject_t *phone_obj = kobject_get(task, phone_handle,
     245                    KOBJECT_TYPE_PHONE);
     246                (void) ipc_phone_connect(phone_obj->phone, ipc_phone_0);
     247        }
     248       
     249        futex_task_init(task);
    234250       
    235251        /*
     
    272288         * Free up dynamically allocated state.
    273289         */
    274         btree_destroy(&task->futexes);
     290        futex_task_deinit(task);
    275291       
    276292        /*
     
    420436task_t *task_find_by_id(task_id_t id)
    421437{
    422         ASSERT(interrupts_disabled());
    423         ASSERT(irq_spinlock_locked(&tasks_lock));
     438        assert(interrupts_disabled());
     439        assert(irq_spinlock_locked(&tasks_lock));
    424440
    425441        avltree_node_t *node =
     
    444460void task_get_accounting(task_t *task, uint64_t *ucycles, uint64_t *kcycles)
    445461{
    446         ASSERT(interrupts_disabled());
    447         ASSERT(irq_spinlock_locked(&task->lock));
     462        assert(interrupts_disabled());
     463        assert(irq_spinlock_locked(&task->lock));
    448464
    449465        /* Accumulated values of task */
     
    603619        if (*additional)
    604620                printf("%-8" PRIu64 " %9" PRIu64 "%c %9" PRIu64 "%c "
    605                     "%9" PRIua, task->taskid, ucycles, usuffix, kcycles,
     621                    "%9" PRIua "\n", task->taskid, ucycles, usuffix, kcycles,
    606622                    ksuffix, atomic_get(&task->refcount));
    607623        else
     
    609625                    task->taskid, task->name, task->container, task, task->as);
    610626#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         }
    620627       
    621628        irq_spinlock_unlock(&task->lock, false);
Note: See TracChangeset for help on using the changeset viewer.