Annotation of Gnu-Mach/i386/intel/read_fault.c, revision 1.1.1.2

1.1       root        1: /* 
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990 Carnegie Mellon University
                      4:  * All Rights Reserved.
                      5:  * 
                      6:  * Permission to use, copy, modify and distribute this software and its
                      7:  * documentation is hereby granted, provided that both the copyright
                      8:  * notice and this permission notice appear in all copies of the
                      9:  * software, derivative works or modified versions, and any portions
                     10:  * thereof, and that both notices appear in supporting documentation.
                     11:  * 
                     12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     15:  * 
                     16:  * Carnegie Mellon requests users of this software to return to
                     17:  * 
                     18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
                     22:  * 
                     23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: 
                     27: #include <vm/vm_fault.h>
                     28: #include <mach/kern_return.h>
                     29: #include <vm/vm_map.h>
                     30: #include <vm/vm_object.h>
                     31: #include <vm/vm_page.h>
                     32: #include <vm/pmap.h>
                     33: 
                     34: #include <kern/macro_help.h>
                     35: 
                     36: /*
                     37:  *     Expansion of vm_fault for read fault in kernel mode.
                     38:  *     Must enter the mapping as writable, since the i386
1.1.1.2 ! root       39:  *     ignores write protection in kernel mode.
1.1       root       40:  */
                     41: kern_return_t
                     42: intel_read_fault(map, vaddr)
                     43:        vm_map_t        map;
                     44:        vm_offset_t     vaddr;
                     45: {
                     46:        vm_map_version_t        version;        /* Map version for
                     47:                                                   verification */
                     48:        vm_object_t             object;         /* Top-level object */
                     49:        vm_offset_t             offset;         /* Top-level offset */
                     50:        vm_prot_t               prot;           /* Protection for mapping */
                     51:        vm_page_t               result_page;    /* Result of vm_fault_page */
                     52:        vm_page_t               top_page;       /* Placeholder page */
                     53:        boolean_t               wired;          /* Is map region wired? */
                     54:        kern_return_t           result;
                     55:        register vm_page_t      m;
                     56: 
                     57:     RetryFault:
                     58: 
                     59:        /*
                     60:         *      Find the backing store object and offset into it
                     61:         *      to begin search.
                     62:         */
                     63:        result = vm_map_lookup(&map, vaddr, VM_PROT_READ, &version,
1.1.1.2 ! root       64:                        &object, &offset, &prot, &wired);
1.1       root       65:        if (result != KERN_SUCCESS)
                     66:            return (result);
                     67: 
                     68:        /*
                     69:         *      Make a reference to this object to prevent its
                     70:         *      disposal while we are playing with it.
                     71:         */
                     72:        assert(object->ref_count > 0);
                     73:        object->ref_count++;
                     74:        vm_object_paging_begin(object);
                     75: 
                     76:        result = vm_fault_page(object, offset, VM_PROT_READ, FALSE, TRUE,
                     77:                               &prot, &result_page, &top_page,
                     78:                               FALSE, (void (*)()) 0);
                     79: 
                     80:        if (result != VM_FAULT_SUCCESS) {
                     81:            vm_object_deallocate(object);
                     82: 
                     83:            switch (result) {
                     84:                case VM_FAULT_RETRY:
                     85:                    goto RetryFault;
                     86:                case VM_FAULT_INTERRUPTED:
                     87:                    return (KERN_SUCCESS);
                     88:                case VM_FAULT_MEMORY_SHORTAGE:
                     89:                    VM_PAGE_WAIT((void (*)()) 0);
                     90:                    goto RetryFault;
                     91:                case VM_FAULT_FICTITIOUS_SHORTAGE:
                     92:                    vm_page_more_fictitious();
                     93:                    goto RetryFault;
                     94:                case VM_FAULT_MEMORY_ERROR:
                     95:                    return (KERN_MEMORY_ERROR);
                     96:            }
                     97:        }
                     98: 
                     99:        m = result_page;
                    100: 
                    101:        /*
                    102:         *      How to clean up the result of vm_fault_page.  This
                    103:         *      happens whether the mapping is entered or not.
                    104:         */
                    105: 
                    106: #define UNLOCK_AND_DEALLOCATE                          \
                    107:        MACRO_BEGIN                                     \
                    108:        vm_fault_cleanup(m->object, top_page);          \
                    109:        vm_object_deallocate(object);                   \
                    110:        MACRO_END
                    111: 
                    112:        /*
                    113:         *      What to do with the resulting page from vm_fault_page
                    114:         *      if it doesn't get entered into the physical map:
                    115:         */
                    116: 
                    117: #define RELEASE_PAGE(m)                                        \
                    118:        MACRO_BEGIN                                     \
                    119:        PAGE_WAKEUP_DONE(m);                            \
                    120:        vm_page_lock_queues();                          \
                    121:        if (!m->active && !m->inactive)                 \
                    122:                vm_page_activate(m);                    \
                    123:        vm_page_unlock_queues();                        \
                    124:        MACRO_END
                    125: 
                    126:        /*
                    127:         *      We must verify that the maps have not changed.
                    128:         */
                    129:        vm_object_unlock(m->object);
                    130:        while (!vm_map_verify(map, &version)) {
                    131:            vm_object_t         retry_object;
                    132:            vm_offset_t         retry_offset;
                    133:            vm_prot_t           retry_prot;
                    134: 
                    135:            result = vm_map_lookup(&map, vaddr, VM_PROT_READ, &version,
                    136:                                &retry_object, &retry_offset, &retry_prot,
1.1.1.2 ! root      137:                                &wired);
1.1       root      138:            if (result != KERN_SUCCESS) {
                    139:                vm_object_lock(m->object);
                    140:                RELEASE_PAGE(m);
                    141:                UNLOCK_AND_DEALLOCATE;
                    142:                return (result);
                    143:            }
                    144: 
                    145:            vm_object_unlock(retry_object);
                    146: 
                    147:            if (retry_object != object || retry_offset != offset) {
                    148:                vm_object_lock(m->object);
                    149:                RELEASE_PAGE(m);
                    150:                UNLOCK_AND_DEALLOCATE;
                    151:                goto RetryFault;
                    152:            }
                    153:        }
                    154: 
                    155:        /*
                    156:         *      Put the page in the physical map.
                    157:         */
                    158:        PMAP_ENTER(map->pmap, vaddr, m, VM_PROT_READ|VM_PROT_WRITE, wired);
                    159: 
                    160:        vm_object_lock(m->object);
                    161:        vm_page_lock_queues();
                    162:        if (!m->active && !m->inactive)
                    163:                vm_page_activate(m);
                    164:        m->reference = TRUE;
                    165:        vm_page_unlock_queues();
                    166: 
                    167:        vm_map_verify_done(map, &version);
                    168:        PAGE_WAKEUP_DONE(m);
                    169: 
                    170:        UNLOCK_AND_DEALLOCATE;
                    171: 
                    172: #undef UNLOCK_AND_DEALLOCATE
                    173: #undef RELEASE_PAGE
                    174: 
                    175:        return (KERN_SUCCESS);
                    176: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.