[0ee077ee] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Jakub Jermar
|
---|
[0ee077ee] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 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
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 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
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 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
|
---|
| 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
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[cc73a8a1] | 29 | /** @addtogroup genericmm
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
[0ee077ee] | 33 | /**
|
---|
[b45c443] | 34 | * @file
|
---|
[0ee077ee] | 35 | * @brief Backend for address space areas backed by an ELF image.
|
---|
| 36 | */
|
---|
| 37 |
|
---|
[d4b5542] | 38 | #include <lib/elf.h>
|
---|
[0ee077ee] | 39 | #include <debug.h>
|
---|
[d99c1d2] | 40 | #include <typedefs.h>
|
---|
[0ee077ee] | 41 | #include <mm/as.h>
|
---|
| 42 | #include <mm/frame.h>
|
---|
| 43 | #include <mm/slab.h>
|
---|
[00b595b] | 44 | #include <mm/page.h>
|
---|
[03523dc] | 45 | #include <mm/reserve.h>
|
---|
[c7f8fc5] | 46 | #include <mm/km.h>
|
---|
[00b595b] | 47 | #include <genarch/mm/page_pt.h>
|
---|
| 48 | #include <genarch/mm/page_ht.h>
|
---|
[0ee077ee] | 49 | #include <align.h>
|
---|
| 50 | #include <memstr.h>
|
---|
| 51 | #include <macros.h>
|
---|
| 52 | #include <arch.h>
|
---|
[36e86862] | 53 | #include <arch/barrier.h>
|
---|
[0ee077ee] | 54 |
|
---|
[03523dc] | 55 | static bool elf_create(as_area_t *);
|
---|
| 56 | static bool elf_resize(as_area_t *, size_t);
|
---|
| 57 | static void elf_share(as_area_t *);
|
---|
| 58 | static void elf_destroy(as_area_t *);
|
---|
| 59 |
|
---|
[cda1378] | 60 | static int elf_page_fault(as_area_t *, uintptr_t, pf_access_t);
|
---|
| 61 | static void elf_frame_free(as_area_t *, uintptr_t, uintptr_t);
|
---|
[0ee077ee] | 62 |
|
---|
| 63 | mem_backend_t elf_backend = {
|
---|
[03523dc] | 64 | .create = elf_create,
|
---|
| 65 | .resize = elf_resize,
|
---|
| 66 | .share = elf_share,
|
---|
| 67 | .destroy = elf_destroy,
|
---|
| 68 |
|
---|
[0ee077ee] | 69 | .page_fault = elf_page_fault,
|
---|
| 70 | .frame_free = elf_frame_free,
|
---|
| 71 | };
|
---|
| 72 |
|
---|
[3ac69647] | 73 | static size_t elf_nonanon_pages_get(as_area_t *area)
|
---|
[03523dc] | 74 | {
|
---|
[9dd730d1] | 75 | elf_segment_header_t *entry = area->backend_data.segment;
|
---|
[8f6c6264] | 76 | uintptr_t first = ALIGN_UP(entry->p_vaddr, PAGE_SIZE);
|
---|
| 77 | uintptr_t last = ALIGN_DOWN(entry->p_vaddr + entry->p_filesz,
|
---|
| 78 | PAGE_SIZE);
|
---|
[9dd730d1] | 79 |
|
---|
[2c86f81] | 80 | if (entry->p_flags & PF_W)
|
---|
[3ac69647] | 81 | return 0;
|
---|
| 82 |
|
---|
[8f6c6264] | 83 | if (last < first)
|
---|
| 84 | return 0;
|
---|
| 85 |
|
---|
| 86 | return last - first;
|
---|
[3ac69647] | 87 | }
|
---|
| 88 |
|
---|
| 89 | bool elf_create(as_area_t *area)
|
---|
| 90 | {
|
---|
| 91 | size_t nonanon_pages = elf_nonanon_pages_get(area);
|
---|
[2c86f81] | 92 |
|
---|
[9dd730d1] | 93 | if (area->pages <= nonanon_pages)
|
---|
| 94 | return true;
|
---|
| 95 |
|
---|
| 96 | return reserve_try_alloc(area->pages - nonanon_pages);
|
---|
[03523dc] | 97 | }
|
---|
| 98 |
|
---|
| 99 | bool elf_resize(as_area_t *area, size_t new_pages)
|
---|
| 100 | {
|
---|
[3ac69647] | 101 | size_t nonanon_pages = elf_nonanon_pages_get(area);
|
---|
[2c86f81] | 102 |
|
---|
[9dd730d1] | 103 | if (new_pages > area->pages) {
|
---|
| 104 | /* The area is growing. */
|
---|
| 105 | if (area->pages >= nonanon_pages)
|
---|
| 106 | return reserve_try_alloc(new_pages - area->pages);
|
---|
| 107 | else if (new_pages > nonanon_pages)
|
---|
| 108 | return reserve_try_alloc(new_pages - nonanon_pages);
|
---|
| 109 | } else if (new_pages < area->pages) {
|
---|
| 110 | /* The area is shrinking. */
|
---|
| 111 | if (new_pages >= nonanon_pages)
|
---|
| 112 | reserve_free(area->pages - new_pages);
|
---|
| 113 | else if (area->pages > nonanon_pages)
|
---|
| 114 | reserve_free(nonanon_pages - new_pages);
|
---|
| 115 | }
|
---|
[03523dc] | 116 |
|
---|
| 117 | return true;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /** Share ELF image backed address space area.
|
---|
| 121 | *
|
---|
| 122 | * If the area is writable, then all mapped pages are duplicated in the pagemap.
|
---|
| 123 | * Otherwise only portions of the area that are not backed by the ELF image
|
---|
| 124 | * are put into the pagemap.
|
---|
| 125 | *
|
---|
| 126 | * @param area Address space area.
|
---|
| 127 | */
|
---|
| 128 | void elf_share(as_area_t *area)
|
---|
| 129 | {
|
---|
| 130 | elf_segment_header_t *entry = area->backend_data.segment;
|
---|
| 131 | link_t *cur;
|
---|
| 132 | btree_node_t *leaf, *node;
|
---|
| 133 | uintptr_t start_anon = entry->p_vaddr + entry->p_filesz;
|
---|
| 134 |
|
---|
| 135 | ASSERT(mutex_locked(&area->as->lock));
|
---|
| 136 | ASSERT(mutex_locked(&area->lock));
|
---|
| 137 |
|
---|
| 138 | /*
|
---|
| 139 | * Find the node in which to start linear search.
|
---|
| 140 | */
|
---|
| 141 | if (area->flags & AS_AREA_WRITE) {
|
---|
[55b77d9] | 142 | node = list_get_instance(list_first(&area->used_space.leaf_list),
|
---|
[03523dc] | 143 | btree_node_t, leaf_link);
|
---|
| 144 | } else {
|
---|
| 145 | (void) btree_search(&area->sh_info->pagemap, start_anon, &leaf);
|
---|
| 146 | node = btree_leaf_node_left_neighbour(&area->sh_info->pagemap,
|
---|
| 147 | leaf);
|
---|
| 148 | if (!node)
|
---|
| 149 | node = leaf;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | /*
|
---|
| 153 | * Copy used anonymous portions of the area to sh_info's page map.
|
---|
| 154 | */
|
---|
| 155 | mutex_lock(&area->sh_info->lock);
|
---|
[55b77d9] | 156 | for (cur = &node->leaf_link; cur != &area->used_space.leaf_list.head;
|
---|
[03523dc] | 157 | cur = cur->next) {
|
---|
| 158 | unsigned int i;
|
---|
| 159 |
|
---|
| 160 | node = list_get_instance(cur, btree_node_t, leaf_link);
|
---|
| 161 |
|
---|
| 162 | for (i = 0; i < node->keys; i++) {
|
---|
| 163 | uintptr_t base = node->key[i];
|
---|
| 164 | size_t count = (size_t) node->value[i];
|
---|
| 165 | unsigned int j;
|
---|
| 166 |
|
---|
| 167 | /*
|
---|
| 168 | * Skip read-only areas of used space that are backed
|
---|
| 169 | * by the ELF image.
|
---|
| 170 | */
|
---|
| 171 | if (!(area->flags & AS_AREA_WRITE))
|
---|
| 172 | if (base >= entry->p_vaddr &&
|
---|
[b4ffe5bc] | 173 | base + P2SZ(count) <= start_anon)
|
---|
[03523dc] | 174 | continue;
|
---|
| 175 |
|
---|
| 176 | for (j = 0; j < count; j++) {
|
---|
| 177 | pte_t *pte;
|
---|
| 178 |
|
---|
| 179 | /*
|
---|
| 180 | * Skip read-only pages that are backed by the
|
---|
| 181 | * ELF image.
|
---|
| 182 | */
|
---|
| 183 | if (!(area->flags & AS_AREA_WRITE))
|
---|
| 184 | if (base >= entry->p_vaddr &&
|
---|
[b4ffe5bc] | 185 | base + P2SZ(j + 1) <= start_anon)
|
---|
[03523dc] | 186 | continue;
|
---|
| 187 |
|
---|
| 188 | page_table_lock(area->as, false);
|
---|
| 189 | pte = page_mapping_find(area->as,
|
---|
[b4ffe5bc] | 190 | base + P2SZ(j), false);
|
---|
[03523dc] | 191 | ASSERT(pte && PTE_VALID(pte) &&
|
---|
| 192 | PTE_PRESENT(pte));
|
---|
| 193 | btree_insert(&area->sh_info->pagemap,
|
---|
[b4ffe5bc] | 194 | (base + P2SZ(j)) - area->base,
|
---|
[03523dc] | 195 | (void *) PTE_GET_FRAME(pte), NULL);
|
---|
| 196 | page_table_unlock(area->as, false);
|
---|
| 197 |
|
---|
| 198 | pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(pte));
|
---|
| 199 | frame_reference_add(pfn);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 | mutex_unlock(&area->sh_info->lock);
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | void elf_destroy(as_area_t *area)
|
---|
| 208 | {
|
---|
[3ac69647] | 209 | size_t nonanon_pages = elf_nonanon_pages_get(area);
|
---|
[2c86f81] | 210 |
|
---|
[9dd730d1] | 211 | if (area->pages > nonanon_pages)
|
---|
| 212 | reserve_free(area->pages - nonanon_pages);
|
---|
[03523dc] | 213 | }
|
---|
| 214 |
|
---|
[0ee077ee] | 215 | /** Service a page fault in the ELF backend address space area.
|
---|
| 216 | *
|
---|
| 217 | * The address space area and page tables must be already locked.
|
---|
| 218 | *
|
---|
[36e86862] | 219 | * @param area Pointer to the address space area.
|
---|
| 220 | * @param addr Faulting virtual address.
|
---|
| 221 | * @param access Access mode that caused the fault (i.e.
|
---|
| 222 | * read/write/exec).
|
---|
[0ee077ee] | 223 | *
|
---|
[36e86862] | 224 | * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK
|
---|
| 225 | * on success (i.e. serviced).
|
---|
[0ee077ee] | 226 | */
|
---|
[7f1c620] | 227 | int elf_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
|
---|
[0ee077ee] | 228 | {
|
---|
[127c957b] | 229 | elf_header_t *elf = area->backend_data.elf;
|
---|
| 230 | elf_segment_header_t *entry = area->backend_data.segment;
|
---|
[00b595b] | 231 | btree_node_t *leaf;
|
---|
[c7f8fc5] | 232 | uintptr_t base;
|
---|
| 233 | uintptr_t frame;
|
---|
| 234 | uintptr_t kpage;
|
---|
| 235 | uintptr_t upage;
|
---|
| 236 | uintptr_t start_anon;
|
---|
[98000fb] | 237 | size_t i;
|
---|
[454f1da] | 238 | bool dirty = false;
|
---|
[0ee077ee] | 239 |
|
---|
[1d432f9] | 240 | ASSERT(page_table_locked(AS));
|
---|
| 241 | ASSERT(mutex_locked(&area->lock));
|
---|
| 242 |
|
---|
[0ee077ee] | 243 | if (!as_area_check_access(area, access))
|
---|
| 244 | return AS_PF_FAULT;
|
---|
[917a8c8] | 245 |
|
---|
| 246 | if (addr < ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE))
|
---|
| 247 | return AS_PF_FAULT;
|
---|
| 248 |
|
---|
| 249 | if (addr >= entry->p_vaddr + entry->p_memsz)
|
---|
| 250 | return AS_PF_FAULT;
|
---|
| 251 |
|
---|
[1cc2974] | 252 | i = (addr - ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) >> PAGE_WIDTH;
|
---|
| 253 | base = (uintptr_t)
|
---|
| 254 | (((void *) elf) + ALIGN_DOWN(entry->p_offset, PAGE_SIZE));
|
---|
| 255 |
|
---|
[c7f8fc5] | 256 | /* Virtual address of faulting page */
|
---|
| 257 | upage = ALIGN_DOWN(addr, PAGE_SIZE);
|
---|
[1cc2974] | 258 |
|
---|
| 259 | /* Virtual address of the end of initialized part of segment */
|
---|
| 260 | start_anon = entry->p_vaddr + entry->p_filesz;
|
---|
[00b595b] | 261 |
|
---|
| 262 | if (area->sh_info) {
|
---|
| 263 | bool found = false;
|
---|
| 264 |
|
---|
| 265 | /*
|
---|
| 266 | * The address space area is shared.
|
---|
| 267 | */
|
---|
[1cc2974] | 268 |
|
---|
[00b595b] | 269 | mutex_lock(&area->sh_info->lock);
|
---|
[7f1c620] | 270 | frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
|
---|
[c7f8fc5] | 271 | upage - area->base, &leaf);
|
---|
[00b595b] | 272 | if (!frame) {
|
---|
[6c441cf8] | 273 | unsigned int i;
|
---|
[00b595b] | 274 |
|
---|
| 275 | /*
|
---|
| 276 | * Workaround for valid NULL address.
|
---|
| 277 | */
|
---|
| 278 |
|
---|
| 279 | for (i = 0; i < leaf->keys; i++) {
|
---|
[c7f8fc5] | 280 | if (leaf->key[i] == upage - area->base) {
|
---|
[00b595b] | 281 | found = true;
|
---|
| 282 | break;
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
| 286 | if (frame || found) {
|
---|
[c9d2235b] | 287 | frame_reference_add(ADDR2PFN(frame));
|
---|
[c7f8fc5] | 288 | page_mapping_insert(AS, upage, frame,
|
---|
[d5bd8d7] | 289 | as_area_get_flags(area));
|
---|
[c7f8fc5] | 290 | if (!used_space_insert(area, upage, 1))
|
---|
[f651e80] | 291 | panic("Cannot insert used space.");
|
---|
[00b595b] | 292 | mutex_unlock(&area->sh_info->lock);
|
---|
| 293 | return AS_PF_OK;
|
---|
| 294 | }
|
---|
| 295 | }
|
---|
[1cc2974] | 296 |
|
---|
[00b595b] | 297 | /*
|
---|
[d5bd8d7] | 298 | * The area is either not shared or the pagemap does not contain the
|
---|
| 299 | * mapping.
|
---|
[00b595b] | 300 | */
|
---|
[c7f8fc5] | 301 | if (upage >= entry->p_vaddr && upage + PAGE_SIZE <= start_anon) {
|
---|
[0ee077ee] | 302 | /*
|
---|
| 303 | * Initialized portion of the segment. The memory is backed
|
---|
| 304 | * directly by the content of the ELF image. Pages are
|
---|
| 305 | * only copied if the segment is writable so that there
|
---|
| 306 | * can be more instantions of the same memory ELF image
|
---|
| 307 | * used at a time. Note that this could be later done
|
---|
| 308 | * as COW.
|
---|
| 309 | */
|
---|
| 310 | if (entry->p_flags & PF_W) {
|
---|
[c7f8fc5] | 311 | kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
|
---|
[d56382d] | 312 | memcpy((void *) kpage, (void *) (base + i * PAGE_SIZE),
|
---|
[c7f8fc5] | 313 | PAGE_SIZE);
|
---|
[d56382d] | 314 | if (entry->p_flags & PF_X) {
|
---|
| 315 | smc_coherence_block((void *) kpage, PAGE_SIZE);
|
---|
| 316 | }
|
---|
[c7f8fc5] | 317 | km_temporary_page_put(kpage);
|
---|
[454f1da] | 318 | dirty = true;
|
---|
[0ee077ee] | 319 | } else {
|
---|
[1cc2974] | 320 | frame = KA2PA(base + i * FRAME_SIZE);
|
---|
[0ee077ee] | 321 | }
|
---|
[c7f8fc5] | 322 | } else if (upage >= start_anon) {
|
---|
[0ee077ee] | 323 | /*
|
---|
| 324 | * This is the uninitialized portion of the segment.
|
---|
| 325 | * It is not physically present in the ELF image.
|
---|
| 326 | * To resolve the situation, a frame must be allocated
|
---|
| 327 | * and cleared.
|
---|
| 328 | */
|
---|
[c7f8fc5] | 329 | kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
|
---|
| 330 | memsetb((void *) kpage, PAGE_SIZE, 0);
|
---|
| 331 | km_temporary_page_put(kpage);
|
---|
[454f1da] | 332 | dirty = true;
|
---|
[0ee077ee] | 333 | } else {
|
---|
[1cc2974] | 334 | size_t pad_lo, pad_hi;
|
---|
[0ee077ee] | 335 | /*
|
---|
| 336 | * The mixed case.
|
---|
[1cc2974] | 337 | *
|
---|
| 338 | * The middle part is backed by the ELF image and
|
---|
| 339 | * the lower and upper parts are anonymous memory.
|
---|
| 340 | * (The segment can be and often is shorter than 1 page).
|
---|
[0ee077ee] | 341 | */
|
---|
[c7f8fc5] | 342 | if (upage < entry->p_vaddr)
|
---|
| 343 | pad_lo = entry->p_vaddr - upage;
|
---|
[1cc2974] | 344 | else
|
---|
| 345 | pad_lo = 0;
|
---|
| 346 |
|
---|
[c7f8fc5] | 347 | if (start_anon < upage + PAGE_SIZE)
|
---|
| 348 | pad_hi = upage + PAGE_SIZE - start_anon;
|
---|
[1cc2974] | 349 | else
|
---|
| 350 | pad_hi = 0;
|
---|
| 351 |
|
---|
[c7f8fc5] | 352 | kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE);
|
---|
| 353 | memcpy((void *) (kpage + pad_lo),
|
---|
| 354 | (void *) (base + i * PAGE_SIZE + pad_lo),
|
---|
| 355 | PAGE_SIZE - pad_lo - pad_hi);
|
---|
[62cd66f] | 356 | if (entry->p_flags & PF_X) {
|
---|
[c7f8fc5] | 357 | smc_coherence_block((void *) (kpage + pad_lo),
|
---|
| 358 | PAGE_SIZE - pad_lo - pad_hi);
|
---|
[62cd66f] | 359 | }
|
---|
[c7f8fc5] | 360 | memsetb((void *) kpage, pad_lo, 0);
|
---|
| 361 | memsetb((void *) (kpage + PAGE_SIZE - pad_hi), pad_hi, 0);
|
---|
| 362 | km_temporary_page_put(kpage);
|
---|
[454f1da] | 363 | dirty = true;
|
---|
[1cc2974] | 364 | }
|
---|
[00b595b] | 365 |
|
---|
[1cc2974] | 366 | if (dirty && area->sh_info) {
|
---|
| 367 | frame_reference_add(ADDR2PFN(frame));
|
---|
[c7f8fc5] | 368 | btree_insert(&area->sh_info->pagemap, upage - area->base,
|
---|
[1cc2974] | 369 | (void *) frame, leaf);
|
---|
[0ee077ee] | 370 | }
|
---|
[1cc2974] | 371 |
|
---|
[00b595b] | 372 | if (area->sh_info)
|
---|
| 373 | mutex_unlock(&area->sh_info->lock);
|
---|
[1cc2974] | 374 |
|
---|
[c7f8fc5] | 375 | page_mapping_insert(AS, upage, frame, as_area_get_flags(area));
|
---|
| 376 | if (!used_space_insert(area, upage, 1))
|
---|
[f651e80] | 377 | panic("Cannot insert used space.");
|
---|
[0ee077ee] | 378 |
|
---|
| 379 | return AS_PF_OK;
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 | /** Free a frame that is backed by the ELF backend.
|
---|
| 383 | *
|
---|
| 384 | * The address space area and page tables must be already locked.
|
---|
| 385 | *
|
---|
[36e86862] | 386 | * @param area Pointer to the address space area.
|
---|
| 387 | * @param page Page that is mapped to frame. Must be aligned to
|
---|
| 388 | * PAGE_SIZE.
|
---|
| 389 | * @param frame Frame to be released.
|
---|
[0ee077ee] | 390 | *
|
---|
| 391 | */
|
---|
[7f1c620] | 392 | void elf_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
|
---|
[0ee077ee] | 393 | {
|
---|
[127c957b] | 394 | elf_segment_header_t *entry = area->backend_data.segment;
|
---|
[137691a] | 395 | uintptr_t start_anon;
|
---|
[1cc2974] | 396 |
|
---|
[1d432f9] | 397 | ASSERT(page_table_locked(area->as));
|
---|
| 398 | ASSERT(mutex_locked(&area->lock));
|
---|
| 399 |
|
---|
| 400 | ASSERT(page >= ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE));
|
---|
| 401 | ASSERT(page < entry->p_vaddr + entry->p_memsz);
|
---|
| 402 |
|
---|
[1cc2974] | 403 | start_anon = entry->p_vaddr + entry->p_filesz;
|
---|
| 404 |
|
---|
| 405 | if (page >= entry->p_vaddr && page + PAGE_SIZE <= start_anon) {
|
---|
[0ee077ee] | 406 | if (entry->p_flags & PF_W) {
|
---|
| 407 | /*
|
---|
[d5bd8d7] | 408 | * Free the frame with the copy of writable segment
|
---|
| 409 | * data.
|
---|
[0ee077ee] | 410 | */
|
---|
[b838fdf] | 411 | frame_free_noreserve(frame);
|
---|
[0ee077ee] | 412 | }
|
---|
| 413 | } else {
|
---|
| 414 | /*
|
---|
[d5bd8d7] | 415 | * The frame is either anonymous memory or the mixed case (i.e.
|
---|
| 416 | * lower part is backed by the ELF image and the upper is
|
---|
| 417 | * anonymous). In any case, a frame needs to be freed.
|
---|
[137691a] | 418 | */
|
---|
[b838fdf] | 419 | frame_free_noreserve(frame);
|
---|
[0ee077ee] | 420 | }
|
---|
| 421 | }
|
---|
[00b595b] | 422 |
|
---|
[cc73a8a1] | 423 | /** @}
|
---|
[b45c443] | 424 | */
|
---|