Rev 2089 | Rev 2134 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2089 | Rev 2132 | ||
---|---|---|---|
Line 70... | Line 70... | ||
70 | * |
70 | * |
71 | * @param area Pointer to the address space area. |
71 | * @param area Pointer to the address space area. |
72 | * @param addr Faulting virtual address. |
72 | * @param addr Faulting virtual address. |
73 | * @param access Access mode that caused the fault (i.e. read/write/exec). |
73 | * @param access Access mode that caused the fault (i.e. read/write/exec). |
74 | * |
74 | * |
75 | * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced). |
75 | * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. |
- | 76 | * serviced). |
|
76 | */ |
77 | */ |
77 | int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access) |
78 | int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access) |
78 | { |
79 | { |
79 | uintptr_t frame; |
80 | uintptr_t frame; |
80 | 81 | ||
Line 84... | Line 85... | ||
84 | if (area->sh_info) { |
85 | if (area->sh_info) { |
85 | btree_node_t *leaf; |
86 | btree_node_t *leaf; |
86 | 87 | ||
87 | /* |
88 | /* |
88 | * The area is shared, chances are that the mapping can be found |
89 | * The area is shared, chances are that the mapping can be found |
89 | * in the pagemap of the address space area share info structure. |
90 | * in the pagemap of the address space area share info |
- | 91 | * structure. |
|
90 | * In the case that the pagemap does not contain the respective |
92 | * In the case that the pagemap does not contain the respective |
91 | * mapping, a new frame is allocated and the mapping is created. |
93 | * mapping, a new frame is allocated and the mapping is created. |
92 | */ |
94 | */ |
93 | mutex_lock(&area->sh_info->lock); |
95 | mutex_lock(&area->sh_info->lock); |
94 | frame = (uintptr_t) btree_search(&area->sh_info->pagemap, |
96 | frame = (uintptr_t) btree_search(&area->sh_info->pagemap, |
Line 100... | Line 102... | ||
100 | /* |
102 | /* |
101 | * Zero can be returned as a valid frame address. |
103 | * Zero can be returned as a valid frame address. |
102 | * Just a small workaround. |
104 | * Just a small workaround. |
103 | */ |
105 | */ |
104 | for (i = 0; i < leaf->keys; i++) { |
106 | for (i = 0; i < leaf->keys; i++) { |
- | 107 | if (leaf->key[i] == |
|
105 | if (leaf->key[i] == ALIGN_DOWN(addr, PAGE_SIZE)) { |
108 | ALIGN_DOWN(addr, PAGE_SIZE)) { |
106 | allocate = false; |
109 | allocate = false; |
107 | break; |
110 | break; |
108 | } |
111 | } |
109 | } |
112 | } |
110 | if (allocate) { |
113 | if (allocate) { |
111 | frame = (uintptr_t) frame_alloc(ONE_FRAME, 0); |
114 | frame = (uintptr_t) frame_alloc(ONE_FRAME, 0); |
112 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
115 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
113 | 116 | ||
114 | /* |
117 | /* |
115 | * Insert the address of the newly allocated frame to the pagemap. |
118 | * Insert the address of the newly allocated |
- | 119 | * frame to the pagemap. |
|
116 | */ |
120 | */ |
- | 121 | btree_insert(&area->sh_info->pagemap, |
|
117 | btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, (void *) frame, leaf); |
122 | ALIGN_DOWN(addr, PAGE_SIZE) - area->base, |
- | 123 | (void *) frame, leaf); |
|
118 | } |
124 | } |
119 | } |
125 | } |
120 | frame_reference_add(ADDR2PFN(frame)); |
126 | frame_reference_add(ADDR2PFN(frame)); |
121 | mutex_unlock(&area->sh_info->lock); |
127 | mutex_unlock(&area->sh_info->lock); |
122 | } else { |
128 | } else { |
Line 139... | Line 145... | ||
139 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
145 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
140 | } |
146 | } |
141 | 147 | ||
142 | /* |
148 | /* |
143 | * Map 'page' to 'frame'. |
149 | * Map 'page' to 'frame'. |
144 | * Note that TLB shootdown is not attempted as only new information is being |
150 | * Note that TLB shootdown is not attempted as only new information is |
145 | * inserted into page tables. |
151 | * being inserted into page tables. |
146 | */ |
152 | */ |
147 | page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); |
153 | page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); |
148 | if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1)) |
154 | if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1)) |
149 | panic("Could not insert used space.\n"); |
155 | panic("Could not insert used space.\n"); |
150 | 156 | ||
Line 182... | Line 188... | ||
182 | 188 | ||
183 | /* |
189 | /* |
184 | * Copy used portions of the area to sh_info's page map. |
190 | * Copy used portions of the area to sh_info's page map. |
185 | */ |
191 | */ |
186 | mutex_lock(&area->sh_info->lock); |
192 | mutex_lock(&area->sh_info->lock); |
- | 193 | for (cur = area->used_space.leaf_head.next; |
|
187 | for (cur = area->used_space.leaf_head.next; cur != &area->used_space.leaf_head; cur = cur->next) { |
194 | cur != &area->used_space.leaf_head; cur = cur->next) { |
188 | btree_node_t *node; |
195 | btree_node_t *node; |
189 | int i; |
196 | int i; |
190 | 197 | ||
191 | node = list_get_instance(cur, btree_node_t, leaf_link); |
198 | node = list_get_instance(cur, btree_node_t, leaf_link); |
192 | for (i = 0; i < node->keys; i++) { |
199 | for (i = 0; i < node->keys; i++) { |
Line 196... | Line 203... | ||
196 | 203 | ||
197 | for (j = 0; j < count; j++) { |
204 | for (j = 0; j < count; j++) { |
198 | pte_t *pte; |
205 | pte_t *pte; |
199 | 206 | ||
200 | page_table_lock(area->as, false); |
207 | page_table_lock(area->as, false); |
201 | pte = page_mapping_find(area->as, base + j*PAGE_SIZE); |
208 | pte = page_mapping_find(area->as, |
- | 209 | base + j * PAGE_SIZE); |
|
202 | ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte)); |
210 | ASSERT(pte && PTE_VALID(pte) && |
- | 211 | PTE_PRESENT(pte)); |
|
203 | btree_insert(&area->sh_info->pagemap, (base + j*PAGE_SIZE) - area->base, |
212 | btree_insert(&area->sh_info->pagemap, |
- | 213 | (base + j * PAGE_SIZE) - area->base, |
|
204 | (void *) PTE_GET_FRAME(pte), NULL); |
214 | (void *) PTE_GET_FRAME(pte), NULL); |
205 | page_table_unlock(area->as, false); |
215 | page_table_unlock(area->as, false); |
- | 216 | ||
206 | frame_reference_add(ADDR2PFN(PTE_GET_FRAME(pte))); |
217 | pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(pte)); |
- | 218 | frame_reference_add(pfn); |
|
207 | } |
219 | } |
208 | 220 | ||
209 | } |
221 | } |
210 | } |
222 | } |
211 | mutex_unlock(&area->sh_info->lock); |
223 | mutex_unlock(&area->sh_info->lock); |
212 | } |
224 | } |
213 | 225 | ||
214 | /** @} |
226 | /** @} |
215 | */ |
227 | */ |
- | 228 |