Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ddi/ddi.c

    r7d83c54 r597fa24  
    5454#include <align.h>
    5555#include <errno.h>
    56 #include <mem.h>
     56#include <memw.h>
    5757#include <trace.h>
    5858#include <bitops.h>
     
    6060
    6161/** This lock protects the @c pareas ordered dictionary. */
    62 static mutex_t pareas_lock;
     62static MUTEX_INITIALIZE(pareas_lock, MUTEX_PASSIVE);
    6363
    6464/** Ordered dictionary of enabled physical memory areas by base address. */
     
    7474{
    7575        odict_initialize(&pareas, pareas_getkey, pareas_cmp);
    76         mutex_initialize(&pareas_lock, MUTEX_PASSIVE);
    7776}
    7877
     
    336335                return EPERM;
    337336
    338         irq_spinlock_lock(&tasks_lock, true);
    339 
    340337        task_t *task = task_find_by_id(id);
    341338
    342         if ((!task) || (!container_check(CONTAINER, task->container))) {
    343                 /*
    344                  * There is no task with the specified ID
    345                  * or the task belongs to a different security
    346                  * context.
    347                  */
    348                 irq_spinlock_unlock(&tasks_lock, true);
     339        if (!task)
    349340                return ENOENT;
    350         }
    351 
    352         /* Lock the task and release the lock protecting tasks dictionary. */
    353         irq_spinlock_exchange(&tasks_lock, &task->lock);
    354         errno_t rc = ddi_iospace_enable_arch(task, ioaddr, size);
     341
     342        errno_t rc = ENOENT;
     343
     344        irq_spinlock_lock(&task->lock, true);
     345
     346        /* Check that the task belongs to the correct security context. */
     347        if (container_check(CONTAINER, task->container))
     348                rc = ddi_iospace_enable_arch(task, ioaddr, size);
     349
    355350        irq_spinlock_unlock(&task->lock, true);
    356 
     351        task_release(task);
    357352        return rc;
    358353}
     
    377372                return EPERM;
    378373
    379         irq_spinlock_lock(&tasks_lock, true);
    380 
    381374        task_t *task = task_find_by_id(id);
    382375
    383         if ((!task) || (!container_check(CONTAINER, task->container))) {
    384                 /*
    385                  * There is no task with the specified ID
    386                  * or the task belongs to a different security
    387                  * context.
    388                  */
    389                 irq_spinlock_unlock(&tasks_lock, true);
     376        if (!task)
    390377                return ENOENT;
    391         }
    392 
    393         /* Lock the task and release the lock protecting tasks dictionary. */
    394         irq_spinlock_exchange(&tasks_lock, &task->lock);
    395         errno_t rc = ddi_iospace_disable_arch(task, ioaddr, size);
     378
     379        errno_t rc = ENOENT;
     380
     381        irq_spinlock_lock(&task->lock, true);
     382
     383        /* Check that the task belongs to the correct security context. */
     384        if (container_check(CONTAINER, task->container))
     385                rc = ddi_iospace_disable_arch(task, ioaddr, size);
     386
    396387        irq_spinlock_unlock(&task->lock, true);
    397 
     388        task_release(task);
    398389        return rc;
    399390}
Note: See TracChangeset for help on using the changeset viewer.