Changes in kernel/generic/src/mm/backend_anon.c [0705fc5:2fc3b2d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/backend_anon.c
r0705fc5 r2fc3b2d 48 48 #include <synch/mutex.h> 49 49 #include <adt/list.h> 50 #include <adt/btree.h>51 50 #include <errno.h> 52 51 #include <typedefs.h> … … 122 121 */ 123 122 mutex_lock(&area->sh_info->lock); 124 list_foreach(area->used_space.leaf_list, leaf_link, btree_node_t, 125 node) { 126 unsigned int i; 127 128 for (i = 0; i < node->keys; i++) { 129 uintptr_t base = node->key[i]; 130 size_t count = (size_t) node->value[i]; 131 unsigned int j; 132 133 for (j = 0; j < count; j++) { 134 pte_t pte; 135 bool found; 136 137 page_table_lock(area->as, false); 138 found = page_mapping_find(area->as, 139 base + P2SZ(j), false, &pte); 140 141 (void)found; 142 assert(found); 143 assert(PTE_VALID(&pte)); 144 assert(PTE_PRESENT(&pte)); 145 146 btree_insert(&area->sh_info->pagemap, 147 (base + P2SZ(j)) - area->base, 148 (void *) PTE_GET_FRAME(&pte), NULL); 149 page_table_unlock(area->as, false); 150 151 pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(&pte)); 152 frame_reference_add(pfn); 153 } 154 123 used_space_ival_t *ival = used_space_first(&area->used_space); 124 while (ival != NULL) { 125 uintptr_t base = ival->page; 126 size_t count = ival->count; 127 unsigned int j; 128 129 for (j = 0; j < count; j++) { 130 pte_t pte; 131 bool found; 132 133 page_table_lock(area->as, false); 134 found = page_mapping_find(area->as, base + P2SZ(j), 135 false, &pte); 136 137 (void)found; 138 assert(found); 139 assert(PTE_VALID(&pte)); 140 assert(PTE_PRESENT(&pte)); 141 142 as_pagemap_insert(&area->sh_info->pagemap, 143 (base + P2SZ(j)) - area->base, PTE_GET_FRAME(&pte)); 144 page_table_unlock(area->as, false); 145 146 pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(&pte)); 147 frame_reference_add(pfn); 155 148 } 149 150 ival = used_space_next(ival); 156 151 } 157 152 mutex_unlock(&area->sh_info->lock); … … 201 196 mutex_lock(&area->sh_info->lock); 202 197 if (area->sh_info->shared) { 203 btree_node_t *leaf;204 205 198 /* 206 199 * The area is shared, chances are that the mapping can be found … … 210 203 * mapping, a new frame is allocated and the mapping is created. 211 204 */ 212 frame = (uintptr_t) btree_search(&area->sh_info->pagemap, 213 upage - area->base, &leaf); 214 if (!frame) { 215 bool allocate = true; 216 unsigned int i; 205 errno_t rc = as_pagemap_find(&area->sh_info->pagemap, 206 upage - area->base, &frame); 207 if (rc != EOK) { 208 /* Need to allocate the frame */ 209 kpage = km_temporary_page_get(&frame, 210 FRAME_NO_RESERVE); 211 memsetb((void *) kpage, PAGE_SIZE, 0); 212 km_temporary_page_put(kpage); 217 213 218 214 /* 219 * Zero can be returned as a valid frame address.220 * Just a small workaround.215 * Insert the address of the newly allocated 216 * frame to the pagemap. 221 217 */ 222 for (i = 0; i < leaf->keys; i++) { 223 if (leaf->key[i] == upage - area->base) { 224 allocate = false; 225 break; 226 } 227 } 228 if (allocate) { 229 kpage = km_temporary_page_get(&frame, 230 FRAME_NO_RESERVE); 231 memsetb((void *) kpage, PAGE_SIZE, 0); 232 km_temporary_page_put(kpage); 233 234 /* 235 * Insert the address of the newly allocated 236 * frame to the pagemap. 237 */ 238 btree_insert(&area->sh_info->pagemap, 239 upage - area->base, (void *) frame, leaf); 240 } 218 as_pagemap_insert(&area->sh_info->pagemap, 219 upage - area->base, frame); 241 220 } 242 221 frame_reference_add(ADDR2PFN(frame)); … … 280 259 */ 281 260 page_mapping_insert(AS, upage, frame, as_area_get_flags(area)); 282 if (!used_space_insert( area, upage, 1))261 if (!used_space_insert(&area->used_space, upage, 1)) 283 262 panic("Cannot insert used space."); 284 263
Note:
See TracChangeset
for help on using the changeset viewer.