Rev 1550 | Rev 1757 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1550 | Rev 1702 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Jakub Jermar |
2 | * Copyright (C) 2006 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
- | 29 | /** @addtogroup genericmm |
|
- | 30 | * @{ |
|
- | 31 | */ |
|
- | 32 | ||
29 | /** |
33 | /** |
30 | * @file backend_elf.c |
34 | * @file |
31 | * @brief Backend for address space areas backed by an ELF image. |
35 | * @brief Backend for address space areas backed by an ELF image. |
32 | */ |
36 | */ |
33 | 37 | ||
34 | #include <elf.h> |
38 | #include <elf.h> |
35 | #include <debug.h> |
39 | #include <debug.h> |
36 | #include <arch/types.h> |
40 | #include <arch/types.h> |
37 | #include <typedefs.h> |
41 | #include <typedefs.h> |
38 | #include <mm/as.h> |
42 | #include <mm/as.h> |
39 | #include <mm/frame.h> |
43 | #include <mm/frame.h> |
40 | #include <mm/slab.h> |
44 | #include <mm/slab.h> |
41 | #include <mm/page.h> |
45 | #include <mm/page.h> |
42 | #include <genarch/mm/page_pt.h> |
46 | #include <genarch/mm/page_pt.h> |
43 | #include <genarch/mm/page_ht.h> |
47 | #include <genarch/mm/page_ht.h> |
44 | #include <align.h> |
48 | #include <align.h> |
45 | #include <memstr.h> |
49 | #include <memstr.h> |
46 | #include <macros.h> |
50 | #include <macros.h> |
47 | #include <arch.h> |
51 | #include <arch.h> |
48 | 52 | ||
49 | static int elf_page_fault(as_area_t *area, __address addr, pf_access_t access); |
53 | static int elf_page_fault(as_area_t *area, __address addr, pf_access_t access); |
50 | static void elf_frame_free(as_area_t *area, __address page, __address frame); |
54 | static void elf_frame_free(as_area_t *area, __address page, __address frame); |
51 | static void elf_share(as_area_t *area); |
55 | static void elf_share(as_area_t *area); |
52 | 56 | ||
53 | mem_backend_t elf_backend = { |
57 | mem_backend_t elf_backend = { |
54 | .page_fault = elf_page_fault, |
58 | .page_fault = elf_page_fault, |
55 | .frame_free = elf_frame_free, |
59 | .frame_free = elf_frame_free, |
56 | .share = elf_share |
60 | .share = elf_share |
57 | }; |
61 | }; |
58 | 62 | ||
59 | /** Service a page fault in the ELF backend address space area. |
63 | /** Service a page fault in the ELF backend address space area. |
60 | * |
64 | * |
61 | * The address space area and page tables must be already locked. |
65 | * The address space area and page tables must be already locked. |
62 | * |
66 | * |
63 | * @param area Pointer to the address space area. |
67 | * @param area Pointer to the address space area. |
64 | * @param addr Faulting virtual address. |
68 | * @param addr Faulting virtual address. |
65 | * @param access Access mode that caused the fault (i.e. read/write/exec). |
69 | * @param access Access mode that caused the fault (i.e. read/write/exec). |
66 | * |
70 | * |
67 | * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced). |
71 | * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced). |
68 | */ |
72 | */ |
69 | int elf_page_fault(as_area_t *area, __address addr, pf_access_t access) |
73 | int elf_page_fault(as_area_t *area, __address addr, pf_access_t access) |
70 | { |
74 | { |
71 | elf_header_t *elf = area->backend_data.elf; |
75 | elf_header_t *elf = area->backend_data.elf; |
72 | elf_segment_header_t *entry = area->backend_data.segment; |
76 | elf_segment_header_t *entry = area->backend_data.segment; |
73 | btree_node_t *leaf; |
77 | btree_node_t *leaf; |
74 | __address base, frame; |
78 | __address base, frame; |
75 | index_t i; |
79 | index_t i; |
76 | 80 | ||
77 | if (!as_area_check_access(area, access)) |
81 | if (!as_area_check_access(area, access)) |
78 | return AS_PF_FAULT; |
82 | return AS_PF_FAULT; |
79 | 83 | ||
80 | ASSERT((addr >= entry->p_vaddr) && (addr < entry->p_vaddr + entry->p_memsz)); |
84 | ASSERT((addr >= entry->p_vaddr) && (addr < entry->p_vaddr + entry->p_memsz)); |
81 | i = (addr - entry->p_vaddr) >> PAGE_WIDTH; |
85 | i = (addr - entry->p_vaddr) >> PAGE_WIDTH; |
82 | base = (__address) (((void *) elf) + entry->p_offset); |
86 | base = (__address) (((void *) elf) + entry->p_offset); |
83 | ASSERT(ALIGN_UP(base, FRAME_SIZE) == base); |
87 | ASSERT(ALIGN_UP(base, FRAME_SIZE) == base); |
84 | 88 | ||
85 | if (area->sh_info) { |
89 | if (area->sh_info) { |
86 | bool found = false; |
90 | bool found = false; |
87 | 91 | ||
88 | /* |
92 | /* |
89 | * The address space area is shared. |
93 | * The address space area is shared. |
90 | */ |
94 | */ |
91 | 95 | ||
92 | mutex_lock(&area->sh_info->lock); |
96 | mutex_lock(&area->sh_info->lock); |
93 | frame = (__address) btree_search(&area->sh_info->pagemap, |
97 | frame = (__address) btree_search(&area->sh_info->pagemap, |
94 | ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf); |
98 | ALIGN_DOWN(addr, PAGE_SIZE) - area->base, &leaf); |
95 | if (!frame) { |
99 | if (!frame) { |
96 | int i; |
100 | int i; |
97 | 101 | ||
98 | /* |
102 | /* |
99 | * Workaround for valid NULL address. |
103 | * Workaround for valid NULL address. |
100 | */ |
104 | */ |
101 | 105 | ||
102 | for (i = 0; i < leaf->keys; i++) { |
106 | for (i = 0; i < leaf->keys; i++) { |
103 | if (leaf->key[i] == ALIGN_DOWN(addr, PAGE_SIZE)) { |
107 | if (leaf->key[i] == ALIGN_DOWN(addr, PAGE_SIZE)) { |
104 | found = true; |
108 | found = true; |
105 | break; |
109 | break; |
106 | } |
110 | } |
107 | } |
111 | } |
108 | } |
112 | } |
109 | if (frame || found) { |
113 | if (frame || found) { |
110 | frame_reference_add(ADDR2PFN(frame)); |
114 | frame_reference_add(ADDR2PFN(frame)); |
111 | page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); |
115 | page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); |
112 | if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1)) |
116 | if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1)) |
113 | panic("Could not insert used space.\n"); |
117 | panic("Could not insert used space.\n"); |
114 | mutex_unlock(&area->sh_info->lock); |
118 | mutex_unlock(&area->sh_info->lock); |
115 | return AS_PF_OK; |
119 | return AS_PF_OK; |
116 | } |
120 | } |
117 | } |
121 | } |
118 | 122 | ||
119 | /* |
123 | /* |
120 | * The area is either not shared or the pagemap does not contain the mapping. |
124 | * The area is either not shared or the pagemap does not contain the mapping. |
121 | */ |
125 | */ |
122 | 126 | ||
123 | if (ALIGN_DOWN(addr, PAGE_SIZE) + PAGE_SIZE < entry->p_vaddr + entry->p_filesz) { |
127 | if (ALIGN_DOWN(addr, PAGE_SIZE) + PAGE_SIZE < entry->p_vaddr + entry->p_filesz) { |
124 | /* |
128 | /* |
125 | * Initialized portion of the segment. The memory is backed |
129 | * Initialized portion of the segment. The memory is backed |
126 | * directly by the content of the ELF image. Pages are |
130 | * directly by the content of the ELF image. Pages are |
127 | * only copied if the segment is writable so that there |
131 | * only copied if the segment is writable so that there |
128 | * can be more instantions of the same memory ELF image |
132 | * can be more instantions of the same memory ELF image |
129 | * used at a time. Note that this could be later done |
133 | * used at a time. Note that this could be later done |
130 | * as COW. |
134 | * as COW. |
131 | */ |
135 | */ |
132 | if (entry->p_flags & PF_W) { |
136 | if (entry->p_flags & PF_W) { |
133 | frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0)); |
137 | frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0)); |
134 | memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), FRAME_SIZE); |
138 | memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), FRAME_SIZE); |
135 | 139 | ||
136 | if (area->sh_info) { |
140 | if (area->sh_info) { |
137 | frame_reference_add(ADDR2PFN(frame)); |
141 | frame_reference_add(ADDR2PFN(frame)); |
138 | btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, |
142 | btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, |
139 | (void *) frame, leaf); |
143 | (void *) frame, leaf); |
140 | } |
144 | } |
141 | 145 | ||
142 | } else { |
146 | } else { |
143 | frame = KA2PA(base + i*FRAME_SIZE); |
147 | frame = KA2PA(base + i*FRAME_SIZE); |
144 | } |
148 | } |
145 | } else if (ALIGN_DOWN(addr, PAGE_SIZE) >= ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { |
149 | } else if (ALIGN_DOWN(addr, PAGE_SIZE) >= ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { |
146 | /* |
150 | /* |
147 | * This is the uninitialized portion of the segment. |
151 | * This is the uninitialized portion of the segment. |
148 | * It is not physically present in the ELF image. |
152 | * It is not physically present in the ELF image. |
149 | * To resolve the situation, a frame must be allocated |
153 | * To resolve the situation, a frame must be allocated |
150 | * and cleared. |
154 | * and cleared. |
151 | */ |
155 | */ |
152 | frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0)); |
156 | frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0)); |
153 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
157 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
154 | 158 | ||
155 | if (area->sh_info) { |
159 | if (area->sh_info) { |
156 | frame_reference_add(ADDR2PFN(frame)); |
160 | frame_reference_add(ADDR2PFN(frame)); |
157 | btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, |
161 | btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, |
158 | (void *) frame, leaf); |
162 | (void *) frame, leaf); |
159 | } |
163 | } |
160 | 164 | ||
161 | } else { |
165 | } else { |
162 | size_t size; |
166 | size_t size; |
163 | /* |
167 | /* |
164 | * The mixed case. |
168 | * The mixed case. |
165 | * The lower part is backed by the ELF image and |
169 | * The lower part is backed by the ELF image and |
166 | * the upper part is anonymous memory. |
170 | * the upper part is anonymous memory. |
167 | */ |
171 | */ |
168 | size = entry->p_filesz - (i<<PAGE_WIDTH); |
172 | size = entry->p_filesz - (i<<PAGE_WIDTH); |
169 | frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0)); |
173 | frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0)); |
170 | memsetb(PA2KA(frame) + size, FRAME_SIZE - size, 0); |
174 | memsetb(PA2KA(frame) + size, FRAME_SIZE - size, 0); |
171 | memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), size); |
175 | memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), size); |
172 | 176 | ||
173 | if (area->sh_info) { |
177 | if (area->sh_info) { |
174 | frame_reference_add(ADDR2PFN(frame)); |
178 | frame_reference_add(ADDR2PFN(frame)); |
175 | btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, |
179 | btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, |
176 | (void *) frame, leaf); |
180 | (void *) frame, leaf); |
177 | } |
181 | } |
178 | 182 | ||
179 | } |
183 | } |
180 | 184 | ||
181 | if (area->sh_info) |
185 | if (area->sh_info) |
182 | mutex_unlock(&area->sh_info->lock); |
186 | mutex_unlock(&area->sh_info->lock); |
183 | 187 | ||
184 | page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); |
188 | page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); |
185 | if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1)) |
189 | if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1)) |
186 | panic("Could not insert used space.\n"); |
190 | panic("Could not insert used space.\n"); |
187 | 191 | ||
188 | return AS_PF_OK; |
192 | return AS_PF_OK; |
189 | } |
193 | } |
190 | 194 | ||
191 | /** Free a frame that is backed by the ELF backend. |
195 | /** Free a frame that is backed by the ELF backend. |
192 | * |
196 | * |
193 | * The address space area and page tables must be already locked. |
197 | * The address space area and page tables must be already locked. |
194 | * |
198 | * |
195 | * @param area Pointer to the address space area. |
199 | * @param area Pointer to the address space area. |
196 | * @param page Page that is mapped to frame. Must be aligned to PAGE_SIZE. |
200 | * @param page Page that is mapped to frame. Must be aligned to PAGE_SIZE. |
197 | * @param frame Frame to be released. |
201 | * @param frame Frame to be released. |
198 | * |
202 | * |
199 | */ |
203 | */ |
200 | void elf_frame_free(as_area_t *area, __address page, __address frame) |
204 | void elf_frame_free(as_area_t *area, __address page, __address frame) |
201 | { |
205 | { |
202 | elf_header_t *elf = area->backend_data.elf; |
206 | elf_header_t *elf = area->backend_data.elf; |
203 | elf_segment_header_t *entry = area->backend_data.segment; |
207 | elf_segment_header_t *entry = area->backend_data.segment; |
204 | __address base; |
208 | __address base; |
205 | index_t i; |
209 | index_t i; |
206 | 210 | ||
207 | ASSERT((page >= entry->p_vaddr) && (page < entry->p_vaddr + entry->p_memsz)); |
211 | ASSERT((page >= entry->p_vaddr) && (page < entry->p_vaddr + entry->p_memsz)); |
208 | i = (page - entry->p_vaddr) >> PAGE_WIDTH; |
212 | i = (page - entry->p_vaddr) >> PAGE_WIDTH; |
209 | base = (__address) (((void *) elf) + entry->p_offset); |
213 | base = (__address) (((void *) elf) + entry->p_offset); |
210 | ASSERT(ALIGN_UP(base, FRAME_SIZE) == base); |
214 | ASSERT(ALIGN_UP(base, FRAME_SIZE) == base); |
211 | 215 | ||
212 | if (page + PAGE_SIZE < ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { |
216 | if (page + PAGE_SIZE < ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { |
213 | if (entry->p_flags & PF_W) { |
217 | if (entry->p_flags & PF_W) { |
214 | /* |
218 | /* |
215 | * Free the frame with the copy of writable segment data. |
219 | * Free the frame with the copy of writable segment data. |
216 | */ |
220 | */ |
217 | frame_free(ADDR2PFN(frame)); |
221 | frame_free(ADDR2PFN(frame)); |
218 | } |
222 | } |
219 | } else { |
223 | } else { |
220 | /* |
224 | /* |
221 | * The frame is either anonymous memory or the mixed case (i.e. lower |
225 | * The frame is either anonymous memory or the mixed case (i.e. lower |
222 | * part is backed by the ELF image and the upper is anonymous). |
226 | * part is backed by the ELF image and the upper is anonymous). |
223 | * In any case, a frame needs to be freed. |
227 | * In any case, a frame needs to be freed. |
224 | */ |
228 | */ |
225 | frame_free(ADDR2PFN(frame)); |
229 | frame_free(ADDR2PFN(frame)); |
226 | } |
230 | } |
227 | } |
231 | } |
228 | 232 | ||
229 | /** Share ELF image backed address space area. |
233 | /** Share ELF image backed address space area. |
230 | * |
234 | * |
231 | * If the area is writable, then all mapped pages are duplicated in the pagemap. |
235 | * If the area is writable, then all mapped pages are duplicated in the pagemap. |
232 | * Otherwise only portions of the area that are not backed by the ELF image |
236 | * Otherwise only portions of the area that are not backed by the ELF image |
233 | * are put into the pagemap. |
237 | * are put into the pagemap. |
234 | * |
238 | * |
235 | * The address space and address space area must be locked prior to the call. |
239 | * The address space and address space area must be locked prior to the call. |
236 | * |
240 | * |
237 | * @param area Address space area. |
241 | * @param area Address space area. |
238 | */ |
242 | */ |
239 | void elf_share(as_area_t *area) |
243 | void elf_share(as_area_t *area) |
240 | { |
244 | { |
241 | elf_segment_header_t *entry = area->backend_data.segment; |
245 | elf_segment_header_t *entry = area->backend_data.segment; |
242 | link_t *cur; |
246 | link_t *cur; |
243 | btree_node_t *leaf, *node; |
247 | btree_node_t *leaf, *node; |
244 | __address start_anon = entry->p_vaddr + entry->p_filesz; |
248 | __address start_anon = entry->p_vaddr + entry->p_filesz; |
245 | 249 | ||
246 | /* |
250 | /* |
247 | * Find the node in which to start linear search. |
251 | * Find the node in which to start linear search. |
248 | */ |
252 | */ |
249 | if (area->flags & AS_AREA_WRITE) { |
253 | if (area->flags & AS_AREA_WRITE) { |
250 | node = list_get_instance(area->used_space.leaf_head.next, btree_node_t, leaf_link); |
254 | node = list_get_instance(area->used_space.leaf_head.next, btree_node_t, leaf_link); |
251 | } else { |
255 | } else { |
252 | (void) btree_search(&area->sh_info->pagemap, start_anon, &leaf); |
256 | (void) btree_search(&area->sh_info->pagemap, start_anon, &leaf); |
253 | node = btree_leaf_node_left_neighbour(&area->sh_info->pagemap, leaf); |
257 | node = btree_leaf_node_left_neighbour(&area->sh_info->pagemap, leaf); |
254 | if (!node) |
258 | if (!node) |
255 | node = leaf; |
259 | node = leaf; |
256 | } |
260 | } |
257 | 261 | ||
258 | /* |
262 | /* |
259 | * Copy used anonymous portions of the area to sh_info's page map. |
263 | * Copy used anonymous portions of the area to sh_info's page map. |
260 | */ |
264 | */ |
261 | mutex_lock(&area->sh_info->lock); |
265 | mutex_lock(&area->sh_info->lock); |
262 | for (cur = &node->leaf_link; cur != &area->used_space.leaf_head; cur = cur->next) { |
266 | for (cur = &node->leaf_link; cur != &area->used_space.leaf_head; cur = cur->next) { |
263 | int i; |
267 | int i; |
264 | 268 | ||
265 | node = list_get_instance(cur, btree_node_t, leaf_link); |
269 | node = list_get_instance(cur, btree_node_t, leaf_link); |
266 | 270 | ||
267 | for (i = 0; i < node->keys; i++) { |
271 | for (i = 0; i < node->keys; i++) { |
268 | __address base = node->key[i]; |
272 | __address base = node->key[i]; |
269 | count_t count = (count_t) node->value[i]; |
273 | count_t count = (count_t) node->value[i]; |
270 | int j; |
274 | int j; |
271 | 275 | ||
272 | /* |
276 | /* |
273 | * Skip read-only areas of used space that are backed |
277 | * Skip read-only areas of used space that are backed |
274 | * by the ELF image. |
278 | * by the ELF image. |
275 | */ |
279 | */ |
276 | if (!(area->flags & AS_AREA_WRITE)) |
280 | if (!(area->flags & AS_AREA_WRITE)) |
277 | if (base + count*PAGE_SIZE <= start_anon) |
281 | if (base + count*PAGE_SIZE <= start_anon) |
278 | continue; |
282 | continue; |
279 | 283 | ||
280 | for (j = 0; j < count; j++) { |
284 | for (j = 0; j < count; j++) { |
281 | pte_t *pte; |
285 | pte_t *pte; |
282 | 286 | ||
283 | /* |
287 | /* |
284 | * Skip read-only pages that are backed by the ELF image. |
288 | * Skip read-only pages that are backed by the ELF image. |
285 | */ |
289 | */ |
286 | if (!(area->flags & AS_AREA_WRITE)) |
290 | if (!(area->flags & AS_AREA_WRITE)) |
287 | if (base + (j + 1)*PAGE_SIZE <= start_anon) |
291 | if (base + (j + 1)*PAGE_SIZE <= start_anon) |
288 | continue; |
292 | continue; |
289 | 293 | ||
290 | page_table_lock(area->as, false); |
294 | page_table_lock(area->as, false); |
291 | pte = page_mapping_find(area->as, base + j*PAGE_SIZE); |
295 | pte = page_mapping_find(area->as, base + j*PAGE_SIZE); |
292 | ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte)); |
296 | ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte)); |
293 | btree_insert(&area->sh_info->pagemap, (base + j*PAGE_SIZE) - area->base, |
297 | btree_insert(&area->sh_info->pagemap, (base + j*PAGE_SIZE) - area->base, |
294 | (void *) PTE_GET_FRAME(pte), NULL); |
298 | (void *) PTE_GET_FRAME(pte), NULL); |
295 | page_table_unlock(area->as, false); |
299 | page_table_unlock(area->as, false); |
296 | frame_reference_add(ADDR2PFN(PTE_GET_FRAME(pte))); |
300 | frame_reference_add(ADDR2PFN(PTE_GET_FRAME(pte))); |
297 | } |
301 | } |
298 | 302 | ||
299 | } |
303 | } |
300 | } |
304 | } |
301 | mutex_unlock(&area->sh_info->lock); |
305 | mutex_unlock(&area->sh_info->lock); |
302 | } |
306 | } |
- | 307 | ||
- | 308 | /** @} |
|
- | 309 | */ |
|
- | 310 | ||
303 | 311 |