Changeset 1dbc43f in mainline for kernel/arch/ppc32/src/mm/pht.c


Ignore:
Timestamp:
2012-11-22T21:23:47Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
908bb96
Parents:
34ae0a5
Message:

Unify user page fault handling in as_page_fault().

  • Remove lots of architecture-dependent boilerplate code.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ppc32/src/mm/pht.c

    r34ae0a5 r1dbc43f  
    4949 * @param access   Access mode that caused the fault.
    5050 * @param istate   Pointer to interrupted state.
    51  * @param pfrc     Pointer to variable where as_page_fault() return code
    52  *                 will be stored.
    5351 *
    5452 * @return PTE on success, NULL otherwise.
     
    5654 */
    5755static pte_t *find_mapping_and_check(as_t *as, uintptr_t badvaddr, int access,
    58     istate_t *istate, int *pfrc)
     56    istate_t *istate)
    5957{
    6058        /*
     
    6866                 */
    6967                return pte;
    70         } else {
     68        }
     69        /*
     70         * Mapping not found in page tables.
     71         * Resort to higher-level page fault handler.
     72         */
     73        if (as_page_fault(badvaddr, access, istate) == AS_PF_OK) {
    7174                /*
    72                  * Mapping not found in page tables.
    73                  * Resort to higher-level page fault handler.
     75                 * The higher-level page fault handler succeeded,
     76                 * The mapping ought to be in place.
    7477                 */
    75                 int rc = as_page_fault(badvaddr, access, istate);
    76                 switch (rc) {
    77                 case AS_PF_OK:
    78                         /*
    79                          * The higher-level page fault handler succeeded,
    80                          * The mapping ought to be in place.
    81                          */
    82                         pte = page_mapping_find(as, badvaddr, true);
    83                         ASSERT((pte) && (pte->present));
    84                         *pfrc = 0;
    85                         return pte;
    86                 case AS_PF_DEFER:
    87                         *pfrc = rc;
    88                         return NULL;
    89                 case AS_PF_FAULT:
    90                         *pfrc = rc;
    91                         return NULL;
    92                 default:
    93                         panic("Unexpected rc (%d).", rc);
    94                 }
    95         }
    96 }
    97 
    98 static void pht_refill_fail(uintptr_t badvaddr, istate_t *istate)
    99 {
    100         fault_if_from_uspace(istate, "PHT Refill Exception on %p.",
    101             (void *) badvaddr);
    102         panic_memtrap(istate, PF_ACCESS_UNKNOWN, badvaddr,
    103             "PHT Refill Exception.");
     78                pte = page_mapping_find(as, badvaddr, true);
     79                ASSERT((pte) && (pte->present));
     80                return pte;
     81        }
     82
     83        return NULL;
    10484}
    10585
     
    202182                badvaddr = istate->pc;
    203183       
    204         int pfrc;
    205184        pte_t *pte = find_mapping_and_check(AS, badvaddr,
    206             PF_ACCESS_READ /* FIXME */, istate, &pfrc);
    207        
    208         if (!pte) {
    209                 switch (pfrc) {
    210                 case AS_PF_FAULT:
    211                         pht_refill_fail(badvaddr, istate);
    212                         return;
    213                 case AS_PF_DEFER:
    214                         /*
    215                          * The page fault came during copy_from_uspace()
    216                          * or copy_to_uspace().
    217                          */
    218                         return;
    219                 default:
    220                         panic("Unexpected pfrc (%d).", pfrc);
    221                 }
    222         }
    223        
    224         /* Record access to PTE */
    225         pte->accessed = 1;
    226         pht_insert(badvaddr, pte);
     185            PF_ACCESS_READ /* FIXME */, istate);
     186       
     187        if (pte) {
     188                /* Record access to PTE */
     189                pte->accessed = 1;
     190                pht_insert(badvaddr, pte);
     191        }
    227192}
    228193
Note: See TracChangeset for help on using the changeset viewer.