Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/as.c

    r94795812 r59fb782  
    7979#include <syscall/copy.h>
    8080#include <arch/interrupt.h>
     81#include <interrupt.h>
    8182
    8283/**
     
    426427        /*
    427428         * So far, the area does not conflict with other areas.
    428          * Check if it doesn't conflict with kernel address space.
     429         * Check if it is contained in the user address space.
    429430         */
    430431        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    431                 return !overlaps(addr, P2SZ(count), KERNEL_ADDRESS_SPACE_START,
    432                     KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
     432                return iswithin(USER_ADDRESS_SPACE_START,
     433                    (USER_ADDRESS_SPACE_END - USER_ADDRESS_SPACE_START) + 1,
     434                    addr, P2SZ(count));
    433435        }
    434436       
     
    542544    mem_backend_data_t *backend_data, uintptr_t *base, uintptr_t bound)
    543545{
    544         if ((*base != (uintptr_t) -1) && ((*base % PAGE_SIZE) != 0))
     546        if ((*base != (uintptr_t) -1) && !IS_ALIGNED(*base, PAGE_SIZE))
    545547                return NULL;
    546548       
     
    686688int as_area_resize(as_t *as, uintptr_t address, size_t size, unsigned int flags)
    687689{
     690        if (!IS_ALIGNED(address, PAGE_SIZE))
     691                return EINVAL;
     692
    688693        mutex_lock(&as->lock);
    689694       
     
    696701                return ENOENT;
    697702        }
    698        
    699         if (area->backend == &phys_backend) {
    700                 /*
    701                  * Remapping of address space areas associated
    702                  * with memory mapped devices is not supported.
     703
     704        if (!area->backend->is_resizable(area)) {
     705                /*
     706                 * The backend does not support resizing for this area.
    703707                 */
    704708                mutex_unlock(&area->lock);
     
    10571061        }
    10581062       
    1059         if ((!src_area->backend) || (!src_area->backend->share)) {
    1060                 /*
    1061                  * There is no backend or the backend does not
    1062                  * know how to share the area.
     1063        if (!src_area->backend->is_shareable(src_area)) {
     1064                /*
     1065                 * The backend does not permit sharing of this area.
    10631066                 */
    10641067                mutex_unlock(&src_area->lock);
     
    13501353 * Interrupts are assumed disabled.
    13511354 *
    1352  * @param page   Faulting page.
    1353  * @param access Access mode that caused the page fault (i.e.
    1354  *               read/write/exec).
    1355  * @param istate Pointer to the interrupted state.
     1355 * @param address Faulting address.
     1356 * @param access  Access mode that caused the page fault (i.e.
     1357 *                read/write/exec).
     1358 * @param istate  Pointer to the interrupted state.
    13561359 *
    13571360 * @return AS_PF_FAULT on page fault.
     
    13611364 *
    13621365 */
    1363 int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate)
    1364 {
     1366int as_page_fault(uintptr_t address, pf_access_t access, istate_t *istate)
     1367{
     1368        uintptr_t page = ALIGN_DOWN(address, PAGE_SIZE);
     1369        int rc = AS_PF_FAULT;
     1370
    13651371        if (!THREAD)
    1366                 return AS_PF_FAULT;
     1372                goto page_fault;
    13671373       
    13681374        if (!AS)
    1369                 return AS_PF_FAULT;
     1375                goto page_fault;
    13701376       
    13711377        mutex_lock(&AS->lock);
     
    14231429         * Resort to the backend page fault handler.
    14241430         */
    1425         if (area->backend->page_fault(area, page, access) != AS_PF_OK) {
     1431        rc = area->backend->page_fault(area, page, access);
     1432        if (rc != AS_PF_OK) {
    14261433                page_table_unlock(AS, false);
    14271434                mutex_unlock(&area->lock);
     
    14441451                istate_set_retaddr(istate,
    14451452                    (uintptr_t) &memcpy_to_uspace_failover_address);
     1453        } else if (rc == AS_PF_SILENT) {
     1454                printf("Killing task %" PRIu64 " due to a "
     1455                    "failed late reservation request.\n", TASK->taskid);
     1456                task_kill_self(true);
    14461457        } else {
    1447                 return AS_PF_FAULT;
     1458                fault_if_from_uspace(istate, "Page fault: %p.", (void *) address);
     1459                panic_memtrap(istate, access, address, NULL);
    14481460        }
    14491461       
     
    16711683{
    16721684        ASSERT(mutex_locked(&area->lock));
    1673         ASSERT(page == ALIGN_DOWN(page, PAGE_SIZE));
     1685        ASSERT(IS_ALIGNED(page, PAGE_SIZE));
    16741686        ASSERT(count);
    16751687       
     
    19551967{
    19561968        ASSERT(mutex_locked(&area->lock));
    1957         ASSERT(page == ALIGN_DOWN(page, PAGE_SIZE));
     1969        ASSERT(IS_ALIGNED(page, PAGE_SIZE));
    19581970        ASSERT(count);
    19591971       
     
    21322144{
    21332145        uintptr_t virt = base;
    2134         as_area_t *area = as_area_create(AS, flags | AS_AREA_CACHEABLE, size,
     2146        as_area_t *area = as_area_create(AS, flags, size,
    21352147            AS_AREA_ATTR_NONE, &anon_backend, NULL, &virt, bound);
    21362148        if (area == NULL)
Note: See TracChangeset for help on using the changeset viewer.