Ignore:
File:
1 edited

Legend:

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

    r597fa24 r5a5269d  
    5454#include <align.h>
    5555#include <errno.h>
    56 #include <memw.h>
     56#include <mem.h>
    5757#include <trace.h>
    5858#include <bitops.h>
     
    6060
    6161/** This lock protects the @c pareas ordered dictionary. */
    62 static MUTEX_INITIALIZE(pareas_lock, MUTEX_PASSIVE);
     62static mutex_t pareas_lock;
    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);
    7677}
    7778
     
    104105
    105106        mutex_unlock(&pareas_lock);
    106 }
    107 
    108 /** Norify physical area has been unmapped.
    109  *
    110  * @param parea Physical area
    111  */
    112 void ddi_parea_unmap_notify(parea_t *parea)
    113 {
    114         parea->mapped = false;
    115         if (parea->mapped_changed != NULL)
    116                 parea->mapped_changed(parea->arg);
    117107}
    118108
     
    214204
    215205map:
    216         backend_data.parea = parea;
    217 
    218206        if (!as_area_create(TASK->as, flags, FRAMES2SIZE(pages),
    219207            AS_AREA_ATTR_NONE, &phys_backend, &backend_data, virt, bound)) {
     
    335323                return EPERM;
    336324
     325        irq_spinlock_lock(&tasks_lock, true);
     326
    337327        task_t *task = task_find_by_id(id);
    338328
    339         if (!task)
     329        if ((!task) || (!container_check(CONTAINER, task->container))) {
     330                /*
     331                 * There is no task with the specified ID
     332                 * or the task belongs to a different security
     333                 * context.
     334                 */
     335                irq_spinlock_unlock(&tasks_lock, true);
    340336                return ENOENT;
    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 
     337        }
     338
     339        /* Lock the task and release the lock protecting tasks dictionary. */
     340        irq_spinlock_exchange(&tasks_lock, &task->lock);
     341        errno_t rc = ddi_iospace_enable_arch(task, ioaddr, size);
    350342        irq_spinlock_unlock(&task->lock, true);
    351         task_release(task);
     343
    352344        return rc;
    353345}
     
    372364                return EPERM;
    373365
     366        irq_spinlock_lock(&tasks_lock, true);
     367
    374368        task_t *task = task_find_by_id(id);
    375369
    376         if (!task)
     370        if ((!task) || (!container_check(CONTAINER, task->container))) {
     371                /*
     372                 * There is no task with the specified ID
     373                 * or the task belongs to a different security
     374                 * context.
     375                 */
     376                irq_spinlock_unlock(&tasks_lock, true);
    377377                return ENOENT;
    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 
     378        }
     379
     380        /* Lock the task and release the lock protecting tasks dictionary. */
     381        irq_spinlock_exchange(&tasks_lock, &task->lock);
     382        errno_t rc = ddi_iospace_disable_arch(task, ioaddr, size);
    387383        irq_spinlock_unlock(&task->lock, true);
    388         task_release(task);
     384
    389385        return rc;
    390386}
     
    447443        backend_data.frames = frames;
    448444        backend_data.anonymous = true;
    449         backend_data.parea = NULL;
    450445
    451446        if (!as_area_create(TASK->as, map_flags, size,
Note: See TracChangeset for help on using the changeset viewer.