Ignore:
File:
1 edited

Legend:

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

    rd7533c7 rc0699467  
    4141
    4242#include <ddi/ddi.h>
    43 #include <ddi/ddi_arg.h>
    4443#include <proc/task.h>
    4544#include <security/cap.h>
     
    122121        backend_data.frames = pages;
    123122       
    124         /* Find the zone of the physical memory */
     123        /*
     124         * Check if the memory region is explicitly enabled
     125         * for mapping by any parea structure.
     126         */
     127       
     128        mutex_lock(&parea_lock);
     129        btree_node_t *nodep;
     130        parea_t *parea = (parea_t *) btree_search(&parea_btree,
     131            (btree_key_t) pf, &nodep);
     132       
     133        if ((parea != NULL) && (parea->frames >= pages)) {
     134                if ((!priv) && (!parea->unpriv)) {
     135                        mutex_unlock(&parea_lock);
     136                        return EPERM;
     137                }
     138               
     139                goto map;
     140        }
     141       
     142        parea = NULL;
     143        mutex_unlock(&parea_lock);
     144       
     145        /*
     146         * Check if the memory region is part of physical
     147         * memory generally enabled for mapping.
     148         */
     149       
    125150        irq_spinlock_lock(&zones.lock, true);
    126151        size_t znum = find_zone(ADDR2PFN(pf), pages, 0);
     
    153178        }
    154179       
    155         if (zone_flags_available(zones.info[znum].flags)) {
    156                 /*
    157                  * Frames are part of physical memory, check
    158                  * if the memory region is enabled for mapping.
    159                  */
    160                 irq_spinlock_unlock(&zones.lock, true);
    161                
    162                 mutex_lock(&parea_lock);
    163                 btree_node_t *nodep;
    164                 parea_t *parea = (parea_t *) btree_search(&parea_btree,
    165                     (btree_key_t) pf, &nodep);
    166                
    167                 if ((!parea) || (parea->frames < pages)) {
    168                         mutex_unlock(&parea_lock);
    169                         return ENOENT;
    170                 }
    171                
    172                 if (!priv) {
    173                         if (!parea->unpriv) {
    174                                 mutex_unlock(&parea_lock);
    175                                 return EPERM;
    176                         }
    177                 }
    178                
    179                 mutex_unlock(&parea_lock);
    180                 goto map;
    181         }
    182        
    183180        irq_spinlock_unlock(&zones.lock, true);
    184181        return ENOENT;
     
    188185            AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
    189186                /*
    190                  * The address space area could not have been created.
     187                 * The address space area was not created.
    191188                 * We report it using ENOMEM.
    192189                 */
     190               
     191                if (parea != NULL)
     192                        mutex_unlock(&parea_lock);
     193               
    193194                return ENOMEM;
    194195        }
     
    197198         * Mapping is created on-demand during page fault.
    198199         */
    199         return 0;
     200       
     201        if (parea != NULL) {
     202                parea->mapped = true;
     203                mutex_unlock(&parea_lock);
     204        }
     205       
     206        return EOK;
    200207}
    201208
     
    224231        task_t *task = task_find_by_id(id);
    225232       
    226         if ((!task) || (!context_check(CONTEXT, task->context))) {
     233        if ((!task) || (!container_check(CONTAINER, task->container))) {
    227234                /*
    228235                 * There is no task with the specified ID
Note: See TracChangeset for help on using the changeset viewer.