|
|
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
39: * (and i860 in i386 compatability mode) ignores write
40: * protection in kernel mode.
41: */
42: kern_return_t
43: intel_read_fault(map, vaddr)
44: vm_map_t map;
45: vm_offset_t vaddr;
46: {
47: vm_map_version_t version; /* Map version for
48: verification */
49: vm_object_t object; /* Top-level object */
50: vm_offset_t offset; /* Top-level offset */
51: vm_prot_t prot; /* Protection for mapping */
52: vm_page_t result_page; /* Result of vm_fault_page */
53: vm_page_t top_page; /* Placeholder page */
54: boolean_t wired; /* Is map region wired? */
55: boolean_t su;
56: kern_return_t result;
57: register vm_page_t m;
58:
59: RetryFault:
60:
61: /*
62: * Find the backing store object and offset into it
63: * to begin search.
64: */
65: result = vm_map_lookup(&map, vaddr, VM_PROT_READ, &version,
66: &object, &offset, &prot, &wired, &su);
67: if (result != KERN_SUCCESS)
68: return (result);
69:
70: /*
71: * Make a reference to this object to prevent its
72: * disposal while we are playing with it.
73: */
74: assert(object->ref_count > 0);
75: object->ref_count++;
76: vm_object_paging_begin(object);
77:
78: result = vm_fault_page(object, offset, VM_PROT_READ, FALSE, TRUE,
79: &prot, &result_page, &top_page,
80: FALSE, (void (*)()) 0);
81:
82: if (result != VM_FAULT_SUCCESS) {
83: vm_object_deallocate(object);
84:
85: switch (result) {
86: case VM_FAULT_RETRY:
87: goto RetryFault;
88: case VM_FAULT_INTERRUPTED:
89: return (KERN_SUCCESS);
90: case VM_FAULT_MEMORY_SHORTAGE:
91: VM_PAGE_WAIT((void (*)()) 0);
92: goto RetryFault;
93: case VM_FAULT_FICTITIOUS_SHORTAGE:
94: vm_page_more_fictitious();
95: goto RetryFault;
96: case VM_FAULT_MEMORY_ERROR:
97: return (KERN_MEMORY_ERROR);
98: }
99: }
100:
101: m = result_page;
102:
103: /*
104: * How to clean up the result of vm_fault_page. This
105: * happens whether the mapping is entered or not.
106: */
107:
108: #define UNLOCK_AND_DEALLOCATE \
109: MACRO_BEGIN \
110: vm_fault_cleanup(m->object, top_page); \
111: vm_object_deallocate(object); \
112: MACRO_END
113:
114: /*
115: * What to do with the resulting page from vm_fault_page
116: * if it doesn't get entered into the physical map:
117: */
118:
119: #define RELEASE_PAGE(m) \
120: MACRO_BEGIN \
121: PAGE_WAKEUP_DONE(m); \
122: vm_page_lock_queues(); \
123: if (!m->active && !m->inactive) \
124: vm_page_activate(m); \
125: vm_page_unlock_queues(); \
126: MACRO_END
127:
128: /*
129: * We must verify that the maps have not changed.
130: */
131: vm_object_unlock(m->object);
132: while (!vm_map_verify(map, &version)) {
133: vm_object_t retry_object;
134: vm_offset_t retry_offset;
135: vm_prot_t retry_prot;
136:
137: result = vm_map_lookup(&map, vaddr, VM_PROT_READ, &version,
138: &retry_object, &retry_offset, &retry_prot,
139: &wired, &su);
140: if (result != KERN_SUCCESS) {
141: vm_object_lock(m->object);
142: RELEASE_PAGE(m);
143: UNLOCK_AND_DEALLOCATE;
144: return (result);
145: }
146:
147: vm_object_unlock(retry_object);
148:
149: if (retry_object != object || retry_offset != offset) {
150: vm_object_lock(m->object);
151: RELEASE_PAGE(m);
152: UNLOCK_AND_DEALLOCATE;
153: goto RetryFault;
154: }
155: }
156:
157: /*
158: * Put the page in the physical map.
159: */
160: PMAP_ENTER(map->pmap, vaddr, m, VM_PROT_READ|VM_PROT_WRITE, wired);
161:
162: vm_object_lock(m->object);
163: vm_page_lock_queues();
164: if (!m->active && !m->inactive)
165: vm_page_activate(m);
166: m->reference = TRUE;
167: vm_page_unlock_queues();
168:
169: vm_map_verify_done(map, &version);
170: PAGE_WAKEUP_DONE(m);
171:
172: UNLOCK_AND_DEALLOCATE;
173:
174: #undef UNLOCK_AND_DEALLOCATE
175: #undef RELEASE_PAGE
176:
177: return (KERN_SUCCESS);
178: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.