vm_map.c (15583) | vm_map.c (15809) |
---|---|
1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 47 unchanged lines hidden (view full) --- 56 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 57 * School of Computer Science 58 * Carnegie Mellon University 59 * Pittsburgh PA 15213-3890 60 * 61 * any improvements or extensions that they make and grant Carnegie the 62 * rights to redistribute these changes. 63 * | 1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 47 unchanged lines hidden (view full) --- 56 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 57 * School of Computer Science 58 * Carnegie Mellon University 59 * Pittsburgh PA 15213-3890 60 * 61 * any improvements or extensions that they make and grant Carnegie the 62 * rights to redistribute these changes. 63 * |
64 * $Id: vm_map.c,v 1.43 1996/04/29 22:04:57 dyson Exp $ | 64 * $Id: vm_map.c,v 1.44 1996/05/03 21:01:49 phk Exp $ |
65 */ 66 67/* 68 * Virtual memory mapping module. 69 */ 70#include "opt_ddb.h" 71 72#include <sys/param.h> --- 79 unchanged lines hidden (view full) --- 152static vm_map_entry_t kentry_free; 153static vm_map_t kmap_free; 154extern char kstack[]; 155 156static int kentry_count; 157static vm_offset_t mapvm_start, mapvm, mapvmmax; 158static int mapvmpgcnt; 159 | 65 */ 66 67/* 68 * Virtual memory mapping module. 69 */ 70#include "opt_ddb.h" 71 72#include <sys/param.h> --- 79 unchanged lines hidden (view full) --- 152static vm_map_entry_t kentry_free; 153static vm_map_t kmap_free; 154extern char kstack[]; 155 156static int kentry_count; 157static vm_offset_t mapvm_start, mapvm, mapvmmax; 158static int mapvmpgcnt; 159 |
160static struct vm_map_entry *mappool; 161static int mappoolcnt; 162#define KENTRY_LOW_WATER 128 163 |
|
160static void _vm_map_clip_end __P((vm_map_t, vm_map_entry_t, vm_offset_t)); 161static void _vm_map_clip_start __P((vm_map_t, vm_map_entry_t, vm_offset_t)); 162static vm_map_entry_t vm_map_entry_create __P((vm_map_t)); 163static void vm_map_entry_delete __P((vm_map_t, vm_map_entry_t)); | 164static void _vm_map_clip_end __P((vm_map_t, vm_map_entry_t, vm_offset_t)); 165static void _vm_map_clip_start __P((vm_map_t, vm_map_entry_t, vm_offset_t)); 166static vm_map_entry_t vm_map_entry_create __P((vm_map_t)); 167static void vm_map_entry_delete __P((vm_map_t, vm_map_entry_t)); |
164static void vm_map_entry_dispose __P((vm_map_t, vm_map_entry_t)); | 168static __inline void vm_map_entry_dispose __P((vm_map_t, vm_map_entry_t)); |
165static void vm_map_entry_unwire __P((vm_map_t, vm_map_entry_t)); 166static void vm_map_copy_entry __P((vm_map_t, vm_map_t, vm_map_entry_t, 167 vm_map_entry_t)); 168static void vm_map_simplify_entry __P((vm_map_t, vm_map_entry_t)); 169 170void 171vm_map_startup() 172{ --- 36 unchanged lines hidden (view full) --- 209 vm_offset_t min, max; 210 int pageable; 211{ 212 register struct vmspace *vm; 213 214 if (mapvmpgcnt == 0 && mapvm == 0) { 215 int s; 216 | 169static void vm_map_entry_unwire __P((vm_map_t, vm_map_entry_t)); 170static void vm_map_copy_entry __P((vm_map_t, vm_map_t, vm_map_entry_t, 171 vm_map_entry_t)); 172static void vm_map_simplify_entry __P((vm_map_t, vm_map_entry_t)); 173 174void 175vm_map_startup() 176{ --- 36 unchanged lines hidden (view full) --- 213 vm_offset_t min, max; 214 int pageable; 215{ 216 register struct vmspace *vm; 217 218 if (mapvmpgcnt == 0 && mapvm == 0) { 219 int s; 220 |
217 mapvmpgcnt = btoc(cnt.v_page_count * sizeof(struct vm_map_entry)); 218 s = splhigh(); 219 mapvm_start = mapvm = kmem_alloc_pageable(kernel_map, mapvmpgcnt * PAGE_SIZE); | 221 mapvmpgcnt = (cnt.v_page_count * sizeof(struct vm_map_entry) + PAGE_SIZE - 1) / PAGE_SIZE; 222 mapvm_start = mapvm = kmem_alloc_pageable(kernel_map, 223 mapvmpgcnt * PAGE_SIZE); |
220 mapvmmax = mapvm_start + mapvmpgcnt * PAGE_SIZE; | 224 mapvmmax = mapvm_start + mapvmpgcnt * PAGE_SIZE; |
221 splx(s); | |
222 if (!mapvm) 223 mapvmpgcnt = 0; 224 } 225 MALLOC(vm, struct vmspace *, sizeof(struct vmspace), M_VMMAP, M_WAITOK); 226 bzero(vm, (caddr_t) &vm->vm_startcopy - (caddr_t) vm); 227 vm_map_init(&vm->vm_map, min, max, pageable); 228 pmap_pinit(&vm->vm_pmap); 229 vm->vm_map.pmap = &vm->vm_pmap; /* XXX */ --- 6 unchanged lines hidden (view full) --- 236vmspace_free(vm) 237 register struct vmspace *vm; 238{ 239 240 if (vm->vm_refcnt == 0) 241 panic("vmspace_free: attempt to free already freed vmspace"); 242 243 if (--vm->vm_refcnt == 0) { | 225 if (!mapvm) 226 mapvmpgcnt = 0; 227 } 228 MALLOC(vm, struct vmspace *, sizeof(struct vmspace), M_VMMAP, M_WAITOK); 229 bzero(vm, (caddr_t) &vm->vm_startcopy - (caddr_t) vm); 230 vm_map_init(&vm->vm_map, min, max, pageable); 231 pmap_pinit(&vm->vm_pmap); 232 vm->vm_map.pmap = &vm->vm_pmap; /* XXX */ --- 6 unchanged lines hidden (view full) --- 239vmspace_free(vm) 240 register struct vmspace *vm; 241{ 242 243 if (vm->vm_refcnt == 0) 244 panic("vmspace_free: attempt to free already freed vmspace"); 245 246 if (--vm->vm_refcnt == 0) { |
244 int s, i; | |
245 246 /* 247 * Lock the map, to wait out all other references to it. 248 * Delete all of the mappings and pages they hold, then call 249 * the pmap module to reclaim anything left. 250 */ 251 vm_map_lock(&vm->vm_map); 252 (void) vm_map_delete(&vm->vm_map, vm->vm_map.min_offset, 253 vm->vm_map.max_offset); 254 vm_map_unlock(&vm->vm_map); | 247 248 /* 249 * Lock the map, to wait out all other references to it. 250 * Delete all of the mappings and pages they hold, then call 251 * the pmap module to reclaim anything left. 252 */ 253 vm_map_lock(&vm->vm_map); 254 (void) vm_map_delete(&vm->vm_map, vm->vm_map.min_offset, 255 vm->vm_map.max_offset); 256 vm_map_unlock(&vm->vm_map); |
257 |
|
255 while( vm->vm_map.ref_count != 1) 256 tsleep(&vm->vm_map.ref_count, PVM, "vmsfre", 0); 257 --vm->vm_map.ref_count; | 258 while( vm->vm_map.ref_count != 1) 259 tsleep(&vm->vm_map.ref_count, PVM, "vmsfre", 0); 260 --vm->vm_map.ref_count; |
261 vm_object_pmap_remove(vm->vm_upages_obj, 262 0, vm->vm_upages_obj->size); 263 vm_object_deallocate(vm->vm_upages_obj); |
|
258 pmap_release(&vm->vm_pmap); 259 FREE(vm, M_VMMAP); | 264 pmap_release(&vm->vm_pmap); 265 FREE(vm, M_VMMAP); |
266 } else { 267 wakeup(&vm->vm_map.ref_count); |
|
260 } 261} 262 263/* 264 * vm_map_create: 265 * 266 * Creates and returns a new empty VM map with 267 * the given physical map structure, and having --- 42 unchanged lines hidden (view full) --- 310 map->entries_pageable = pageable; 311 map->first_free = &map->header; 312 map->hint = &map->header; 313 map->timestamp = 0; 314 lock_init(&map->lock, TRUE); 315} 316 317/* | 268 } 269} 270 271/* 272 * vm_map_create: 273 * 274 * Creates and returns a new empty VM map with 275 * the given physical map structure, and having --- 42 unchanged lines hidden (view full) --- 318 map->entries_pageable = pageable; 319 map->first_free = &map->header; 320 map->hint = &map->header; 321 map->timestamp = 0; 322 lock_init(&map->lock, TRUE); 323} 324 325/* |
326 * vm_map_entry_dispose: [ internal use only ] 327 * 328 * Inverse of vm_map_entry_create. 329 */ 330static __inline void 331vm_map_entry_dispose(map, entry) 332 vm_map_t map; 333 vm_map_entry_t entry; 334{ 335 int s; 336 337 if (kentry_count < KENTRY_LOW_WATER) { 338 s = splvm(); 339 entry->next = kentry_free; 340 kentry_free = entry; 341 ++kentry_count; 342 splx(s); 343 } else { 344 entry->next = mappool; 345 mappool = entry; 346 ++mappoolcnt; 347 } 348} 349 350/* |
|
318 * vm_map_entry_create: [ internal use only ] 319 * 320 * Allocates a VM map entry for insertion. 321 * No entry fields are filled in. This routine is 322 */ | 351 * vm_map_entry_create: [ internal use only ] 352 * 353 * Allocates a VM map entry for insertion. 354 * No entry fields are filled in. This routine is 355 */ |
323static struct vm_map_entry *mappool; 324static int mappoolcnt; 325 | |
326static vm_map_entry_t 327vm_map_entry_create(map) 328 vm_map_t map; 329{ 330 vm_map_entry_t entry; 331 int i; | 356static vm_map_entry_t 357vm_map_entry_create(map) 358 vm_map_t map; 359{ 360 vm_map_entry_t entry; 361 int i; |
362 int s; |
|
332 | 363 |
333#define KENTRY_LOW_WATER 64 334#define MAPENTRY_LOW_WATER 128 335 | |
336 /* 337 * This is a *very* nasty (and sort of incomplete) hack!!!! 338 */ 339 if (kentry_count < KENTRY_LOW_WATER) { | 364 /* 365 * This is a *very* nasty (and sort of incomplete) hack!!!! 366 */ 367 if (kentry_count < KENTRY_LOW_WATER) { |
368 s = splvm(); |
|
340 if (mapvmpgcnt && mapvm) { 341 vm_page_t m; 342 343 m = vm_page_alloc(kernel_object, | 369 if (mapvmpgcnt && mapvm) { 370 vm_page_t m; 371 372 m = vm_page_alloc(kernel_object, |
344 OFF_TO_IDX(mapvm - vm_map_min(kernel_map)), | 373 OFF_TO_IDX(mapvm - VM_MIN_KERNEL_ADDRESS), |
345 (map == kmem_map) ? VM_ALLOC_INTERRUPT : VM_ALLOC_NORMAL); | 374 (map == kmem_map) ? VM_ALLOC_INTERRUPT : VM_ALLOC_NORMAL); |
375 |
|
346 if (m) { 347 int newentries; 348 349 newentries = (PAGE_SIZE / sizeof(struct vm_map_entry)); 350 vm_page_wire(m); | 376 if (m) { 377 int newentries; 378 379 newentries = (PAGE_SIZE / sizeof(struct vm_map_entry)); 380 vm_page_wire(m); |
351 m->flags &= ~PG_BUSY; | 381 PAGE_WAKEUP(m); |
352 m->valid = VM_PAGE_BITS_ALL; | 382 m->valid = VM_PAGE_BITS_ALL; |
353 pmap_enter(vm_map_pmap(kmem_map), mapvm, 354 VM_PAGE_TO_PHYS(m), VM_PROT_DEFAULT, 1); 355 m->flags |= PG_WRITEABLE|PG_MAPPED; | 383 pmap_kenter(mapvm, VM_PAGE_TO_PHYS(m)); 384 m->flags |= PG_WRITEABLE; |
356 357 entry = (vm_map_entry_t) mapvm; 358 mapvm += PAGE_SIZE; 359 --mapvmpgcnt; 360 361 for (i = 0; i < newentries; i++) { 362 vm_map_entry_dispose(kernel_map, entry); 363 entry++; 364 } 365 } 366 } | 385 386 entry = (vm_map_entry_t) mapvm; 387 mapvm += PAGE_SIZE; 388 --mapvmpgcnt; 389 390 for (i = 0; i < newentries; i++) { 391 vm_map_entry_dispose(kernel_map, entry); 392 entry++; 393 } 394 } 395 } |
396 splx(s); |
|
367 } | 397 } |
368 if (map == kernel_map || map == kmem_map || map == pager_map) { | |
369 | 398 |
399 if (map == kernel_map || map == kmem_map || map == pager_map) { 400 s = splvm(); |
|
370 entry = kentry_free; 371 if (entry) { 372 kentry_free = entry->next; 373 --kentry_count; | 401 entry = kentry_free; 402 if (entry) { 403 kentry_free = entry->next; 404 --kentry_count; |
374 return entry; | 405 } else { 406 panic("vm_map_entry_create: out of map entries for kernel"); |
375 } | 407 } |
376 entry = mappool; 377 if (entry) { 378 mappool = entry->next; 379 --mappoolcnt; 380 return entry; 381 } | 408 splx(s); |
382 } else { 383 entry = mappool; 384 if (entry) { 385 mappool = entry->next; 386 --mappoolcnt; | 409 } else { 410 entry = mappool; 411 if (entry) { 412 mappool = entry->next; 413 --mappoolcnt; |
387 return entry; | 414 } else { 415 MALLOC(entry, vm_map_entry_t, sizeof(struct vm_map_entry), 416 M_VMMAPENT, M_WAITOK); |
388 } | 417 } |
389 MALLOC(entry, vm_map_entry_t, sizeof(struct vm_map_entry), 390 M_VMMAPENT, M_WAITOK); | |
391 } | 418 } |
392 if (entry == NULL) 393 panic("vm_map_entry_create: out of map entries"); | |
394 395 return (entry); 396} 397 398/* | 419 420 return (entry); 421} 422 423/* |
399 * vm_map_entry_dispose: [ internal use only ] 400 * 401 * Inverse of vm_map_entry_create. 402 */ 403static void 404vm_map_entry_dispose(map, entry) 405 vm_map_t map; 406 vm_map_entry_t entry; 407{ 408 if ((kentry_count < KENTRY_LOW_WATER) || 409 ((vm_offset_t) entry >= kentry_data && (vm_offset_t) entry < (kentry_data + kentry_data_size)) || 410 ((vm_offset_t) entry >= mapvm_start && (vm_offset_t) entry < mapvmmax)) { 411 entry->next = kentry_free; 412 kentry_free = entry; 413 ++kentry_count; 414 return; 415 } else { 416 if (mappoolcnt < MAPENTRY_LOW_WATER) { 417 entry->next = mappool; 418 mappool = entry; 419 ++mappoolcnt; 420 return; 421 } 422 FREE(entry, M_VMMAPENT); 423 } 424} 425 426/* | |
427 * vm_map_entry_{un,}link: 428 * 429 * Insert/remove entries from maps. 430 */ 431#define vm_map_entry_link(map, after_where, entry) \ 432 { \ 433 (map)->nentries++; \ 434 (entry)->prev = (after_where); \ --- 197 unchanged lines hidden (view full) --- 632 */ 633 634 if ((prev_entry->next != &map->header) && 635 (prev_entry->next->start < end)) 636 return (KERN_NO_SPACE); 637 638 if ((prev_entry != &map->header) && 639 (prev_entry->end == start) && | 424 * vm_map_entry_{un,}link: 425 * 426 * Insert/remove entries from maps. 427 */ 428#define vm_map_entry_link(map, after_where, entry) \ 429 { \ 430 (map)->nentries++; \ 431 (entry)->prev = (after_where); \ --- 197 unchanged lines hidden (view full) --- 629 */ 630 631 if ((prev_entry->next != &map->header) && 632 (prev_entry->next->start < end)) 633 return (KERN_NO_SPACE); 634 635 if ((prev_entry != &map->header) && 636 (prev_entry->end == start) && |
637 ((object == NULL) || (prev_entry->object.vm_object == object)) && |
|
640 (prev_entry->is_a_map == FALSE) && 641 (prev_entry->is_sub_map == FALSE) && | 638 (prev_entry->is_a_map == FALSE) && 639 (prev_entry->is_sub_map == FALSE) && |
642 ((object == NULL) || (prev_entry->object.vm_object == object)) && | |
643 (prev_entry->inheritance == VM_INHERIT_DEFAULT) && 644 (prev_entry->protection == prot) && 645 (prev_entry->max_protection == max) && 646 (prev_entry->wired_count == 0)) { 647 /* 648 * See if we can avoid creating a new entry by extending one of our 649 * neighbors. 650 */ --- 8 unchanged lines hidden (view full) --- 659 * Coalesced the two objects - can extend the 660 * previous map entry to include the new 661 * range. 662 */ 663 map->size += (end - prev_entry->end); 664 prev_entry->end = end; 665 return (KERN_SUCCESS); 666 } | 640 (prev_entry->inheritance == VM_INHERIT_DEFAULT) && 641 (prev_entry->protection == prot) && 642 (prev_entry->max_protection == max) && 643 (prev_entry->wired_count == 0)) { 644 /* 645 * See if we can avoid creating a new entry by extending one of our 646 * neighbors. 647 */ --- 8 unchanged lines hidden (view full) --- 656 * Coalesced the two objects - can extend the 657 * previous map entry to include the new 658 * range. 659 */ 660 map->size += (end - prev_entry->end); 661 prev_entry->end = end; 662 return (KERN_SUCCESS); 663 } |
667 } /* else if ((object == prev_entry->object.vm_object) && 668 (prev_entry->offset + (prev_entry->end - prev_entry->start) == offset)) { 669 map->size += (end - prev_entry->end); 670 prev_entry->end = end; 671 printf("map optim 1\n"); 672 return (KERN_SUCCESS); 673 } */ | 664 } |
674 } 675 /* 676 * Create a new entry 677 */ 678 679 new_entry = vm_map_entry_create(map); 680 new_entry->start = start; 681 new_entry->end = end; --- 24 unchanged lines hidden (view full) --- 706 */ 707 708 vm_map_entry_link(map, prev_entry, new_entry); 709 map->size += new_entry->end - new_entry->start; 710 711 /* 712 * Update the free space hint 713 */ | 665 } 666 /* 667 * Create a new entry 668 */ 669 670 new_entry = vm_map_entry_create(map); 671 new_entry->start = start; 672 new_entry->end = end; --- 24 unchanged lines hidden (view full) --- 697 */ 698 699 vm_map_entry_link(map, prev_entry, new_entry); 700 map->size += new_entry->end - new_entry->start; 701 702 /* 703 * Update the free space hint 704 */ |
714 | |
715 if ((map->first_free == prev_entry) && 716 (prev_entry->end >= new_entry->start)) 717 map->first_free = new_entry; 718 719 return (KERN_SUCCESS); 720} 721 722/* --- 75 unchanged lines hidden (view full) --- 798 int cow; 799{ 800 register vm_offset_t start; 801 int result, s = 0; 802 803 start = *addr; 804 805 if (map == kmem_map) | 705 if ((map->first_free == prev_entry) && 706 (prev_entry->end >= new_entry->start)) 707 map->first_free = new_entry; 708 709 return (KERN_SUCCESS); 710} 711 712/* --- 75 unchanged lines hidden (view full) --- 788 int cow; 789{ 790 register vm_offset_t start; 791 int result, s = 0; 792 793 start = *addr; 794 795 if (map == kmem_map) |
806 s = splhigh(); | 796 s = splvm(); |
807 808 vm_map_lock(map); 809 if (find_space) { 810 if (vm_map_findspace(map, start, length, addr)) { 811 vm_map_unlock(map); 812 if (map == kmem_map) 813 splx(s); 814 return (KERN_NO_SPACE); --- 46 unchanged lines hidden (view full) --- 861 (prev->protection == entry->protection) && 862 (prev->max_protection == entry->max_protection) && 863 (prev->inheritance == entry->inheritance) && 864 (prev->is_a_map == FALSE) && 865 (prev->is_sub_map == FALSE) && 866 (prev->wired_count == 0)) { 867 if (map->first_free == prev) 868 map->first_free = entry; | 797 798 vm_map_lock(map); 799 if (find_space) { 800 if (vm_map_findspace(map, start, length, addr)) { 801 vm_map_unlock(map); 802 if (map == kmem_map) 803 splx(s); 804 return (KERN_NO_SPACE); --- 46 unchanged lines hidden (view full) --- 851 (prev->protection == entry->protection) && 852 (prev->max_protection == entry->max_protection) && 853 (prev->inheritance == entry->inheritance) && 854 (prev->is_a_map == FALSE) && 855 (prev->is_sub_map == FALSE) && 856 (prev->wired_count == 0)) { 857 if (map->first_free == prev) 858 map->first_free = entry; |
859 if (map->hint == prev) 860 map->hint = entry; |
|
869 vm_map_entry_unlink(map, prev); 870 entry->start = prev->start; 871 entry->offset = prev->offset; | 861 vm_map_entry_unlink(map, prev); 862 entry->start = prev->start; 863 entry->offset = prev->offset; |
872 vm_object_deallocate(prev->object.vm_object); | 864 if (prev->object.vm_object) 865 vm_object_deallocate(prev->object.vm_object); |
873 vm_map_entry_dispose(map, prev); 874 } 875 } 876 877 next = entry->next; 878 if (next != &map->header) { 879 nextsize = next->end - next->start; 880 esize = entry->end - entry->start; --- 5 unchanged lines hidden (view full) --- 886 (next->protection == entry->protection) && 887 (next->max_protection == entry->max_protection) && 888 (next->inheritance == entry->inheritance) && 889 (next->is_a_map == FALSE) && 890 (next->is_sub_map == FALSE) && 891 (next->wired_count == 0)) { 892 if (map->first_free == next) 893 map->first_free = entry; | 866 vm_map_entry_dispose(map, prev); 867 } 868 } 869 870 next = entry->next; 871 if (next != &map->header) { 872 nextsize = next->end - next->start; 873 esize = entry->end - entry->start; --- 5 unchanged lines hidden (view full) --- 879 (next->protection == entry->protection) && 880 (next->max_protection == entry->max_protection) && 881 (next->inheritance == entry->inheritance) && 882 (next->is_a_map == FALSE) && 883 (next->is_sub_map == FALSE) && 884 (next->wired_count == 0)) { 885 if (map->first_free == next) 886 map->first_free = entry; |
887 if (map->hint == next) 888 map->hint = entry; |
|
894 vm_map_entry_unlink(map, next); 895 entry->end = next->end; | 889 vm_map_entry_unlink(map, next); 890 entry->end = next->end; |
896 vm_object_deallocate(next->object.vm_object); | 891 if (next->object.vm_object) 892 vm_object_deallocate(next->object.vm_object); |
897 vm_map_entry_dispose(map, next); 898 } 899 } 900} 901 902/* 903 * vm_map_clip_start: [ internal use only ] 904 * --- 221 unchanged lines hidden (view full) --- 1126 current->protection = new_prot; 1127 1128 /* 1129 * Update physical map if necessary. Worry about copy-on-write 1130 * here -- CHECK THIS XXX 1131 */ 1132 1133 if (current->protection != old_prot) { | 893 vm_map_entry_dispose(map, next); 894 } 895 } 896} 897 898/* 899 * vm_map_clip_start: [ internal use only ] 900 * --- 221 unchanged lines hidden (view full) --- 1122 current->protection = new_prot; 1123 1124 /* 1125 * Update physical map if necessary. Worry about copy-on-write 1126 * here -- CHECK THIS XXX 1127 */ 1128 1129 if (current->protection != old_prot) { |
1134 | |
1135#define MASK(entry) ((entry)->copy_on_write ? ~VM_PROT_WRITE : \ 1136 VM_PROT_ALL) 1137#define max(a,b) ((a) > (b) ? (a) : (b)) 1138 1139 if (current->is_a_map) { 1140 vm_map_entry_t share_entry; 1141 vm_offset_t share_end; 1142 --- 437 unchanged lines hidden (view full) --- 1580/* 1581 * vm_map_entry_unwire: [ internal use only ] 1582 * 1583 * Make the region specified by this entry pageable. 1584 * 1585 * The map in question should be locked. 1586 * [This is the reason for this routine's existence.] 1587 */ | 1130#define MASK(entry) ((entry)->copy_on_write ? ~VM_PROT_WRITE : \ 1131 VM_PROT_ALL) 1132#define max(a,b) ((a) > (b) ? (a) : (b)) 1133 1134 if (current->is_a_map) { 1135 vm_map_entry_t share_entry; 1136 vm_offset_t share_end; 1137 --- 437 unchanged lines hidden (view full) --- 1575/* 1576 * vm_map_entry_unwire: [ internal use only ] 1577 * 1578 * Make the region specified by this entry pageable. 1579 * 1580 * The map in question should be locked. 1581 * [This is the reason for this routine's existence.] 1582 */ |
1588static void | 1583static __inline void |
1589vm_map_entry_unwire(map, entry) 1590 vm_map_t map; 1591 register vm_map_entry_t entry; 1592{ 1593 vm_fault_unwire(map, entry->start, entry->end); 1594 entry->wired_count = 0; 1595} 1596 1597/* 1598 * vm_map_entry_delete: [ internal use only ] 1599 * 1600 * Deallocate the given entry from the target map. 1601 */ | 1584vm_map_entry_unwire(map, entry) 1585 vm_map_t map; 1586 register vm_map_entry_t entry; 1587{ 1588 vm_fault_unwire(map, entry->start, entry->end); 1589 entry->wired_count = 0; 1590} 1591 1592/* 1593 * vm_map_entry_delete: [ internal use only ] 1594 * 1595 * Deallocate the given entry from the target map. 1596 */ |
1602static void | 1597static __inline void |
1603vm_map_entry_delete(map, entry) 1604 register vm_map_t map; 1605 register vm_map_entry_t entry; 1606{ 1607 if (entry->wired_count != 0) 1608 vm_map_entry_unwire(map, entry); 1609 1610 vm_map_entry_unlink(map, entry); --- 42 unchanged lines hidden (view full) --- 1653 1654 SAVE_HINT(map, entry->prev); 1655 } 1656 1657 /* 1658 * Save the free space hint 1659 */ 1660 | 1598vm_map_entry_delete(map, entry) 1599 register vm_map_t map; 1600 register vm_map_entry_t entry; 1601{ 1602 if (entry->wired_count != 0) 1603 vm_map_entry_unwire(map, entry); 1604 1605 vm_map_entry_unlink(map, entry); --- 42 unchanged lines hidden (view full) --- 1648 1649 SAVE_HINT(map, entry->prev); 1650 } 1651 1652 /* 1653 * Save the free space hint 1654 */ 1655 |
1661 if (map->first_free->start >= start) | 1656 if (entry == &map->header) { 1657 map->first_free = &map->header; 1658 } else if (map->first_free->start >= start) |
1662 map->first_free = entry->prev; 1663 1664 /* 1665 * Step through all entries in this region 1666 */ 1667 1668 while ((entry != &map->header) && (entry->start < end)) { 1669 vm_map_entry_t next; | 1659 map->first_free = entry->prev; 1660 1661 /* 1662 * Step through all entries in this region 1663 */ 1664 1665 while ((entry != &map->header) && (entry->start < end)) { 1666 vm_map_entry_t next; |
1670 register vm_offset_t s, e; 1671 register vm_object_t object; | 1667 vm_offset_t s, e; 1668 vm_object_t object; 1669 vm_ooffset_t offset; |
1672 1673 vm_map_clip_end(map, entry, end); 1674 1675 next = entry->next; 1676 s = entry->start; 1677 e = entry->end; | 1670 1671 vm_map_clip_end(map, entry, end); 1672 1673 next = entry->next; 1674 s = entry->start; 1675 e = entry->end; |
1676 offset = entry->offset; |
|
1678 1679 /* 1680 * Unwire before removing addresses from the pmap; otherwise, 1681 * unwiring will put the entries back in the pmap. 1682 */ 1683 1684 object = entry->object.vm_object; 1685 if (entry->wired_count != 0) 1686 vm_map_entry_unwire(map, entry); 1687 1688 /* 1689 * If this is a sharing map, we must remove *all* references 1690 * to this data, since we can't find all of the physical maps 1691 * which are sharing it. 1692 */ 1693 | 1677 1678 /* 1679 * Unwire before removing addresses from the pmap; otherwise, 1680 * unwiring will put the entries back in the pmap. 1681 */ 1682 1683 object = entry->object.vm_object; 1684 if (entry->wired_count != 0) 1685 vm_map_entry_unwire(map, entry); 1686 1687 /* 1688 * If this is a sharing map, we must remove *all* references 1689 * to this data, since we can't find all of the physical maps 1690 * which are sharing it. 1691 */ 1692 |
1694 if (object == kernel_object || object == kmem_object) 1695 vm_object_page_remove(object, OFF_TO_IDX(entry->offset), 1696 OFF_TO_IDX(entry->offset + (e - s)), FALSE); 1697 else if (!map->is_main_map) | 1693 if (object == kernel_object || object == kmem_object) { 1694 vm_object_page_remove(object, OFF_TO_IDX(offset), 1695 OFF_TO_IDX(offset + (e - s)), FALSE); 1696 } else if (!map->is_main_map) { |
1698 vm_object_pmap_remove(object, | 1697 vm_object_pmap_remove(object, |
1699 OFF_TO_IDX(entry->offset), 1700 OFF_TO_IDX(entry->offset + (e - s))); 1701 else | 1698 OFF_TO_IDX(offset), 1699 OFF_TO_IDX(offset + (e - s))); 1700 } else { |
1702 pmap_remove(map->pmap, s, e); | 1701 pmap_remove(map->pmap, s, e); |
1702 } |
|
1703 1704 /* 1705 * Delete the entry (which may delete the object) only after 1706 * removing all pmap entries pointing to its pages. 1707 * (Otherwise, its page frames may be reallocated, and any 1708 * modify bits will be set in the wrong object!) 1709 */ 1710 --- 13 unchanged lines hidden (view full) --- 1724vm_map_remove(map, start, end) 1725 register vm_map_t map; 1726 register vm_offset_t start; 1727 register vm_offset_t end; 1728{ 1729 register int result, s = 0; 1730 1731 if (map == kmem_map) | 1703 1704 /* 1705 * Delete the entry (which may delete the object) only after 1706 * removing all pmap entries pointing to its pages. 1707 * (Otherwise, its page frames may be reallocated, and any 1708 * modify bits will be set in the wrong object!) 1709 */ 1710 --- 13 unchanged lines hidden (view full) --- 1724vm_map_remove(map, start, end) 1725 register vm_map_t map; 1726 register vm_offset_t start; 1727 register vm_offset_t end; 1728{ 1729 register int result, s = 0; 1730 1731 if (map == kmem_map) |
1732 s = splhigh(); | 1732 s = splvm(); |
1733 1734 vm_map_lock(map); 1735 VM_MAP_RANGE_CHECK(map, start, end); 1736 result = vm_map_delete(map, start, end); 1737 vm_map_unlock(map); 1738 1739 if (map == kmem_map) 1740 splx(s); --- 60 unchanged lines hidden (view full) --- 1801 vm_map_t src_map, dst_map; 1802 register vm_map_entry_t src_entry, dst_entry; 1803{ 1804 vm_pindex_t temp_pindex; 1805 1806 if (src_entry->is_sub_map || dst_entry->is_sub_map) 1807 return; 1808 | 1733 1734 vm_map_lock(map); 1735 VM_MAP_RANGE_CHECK(map, start, end); 1736 result = vm_map_delete(map, start, end); 1737 vm_map_unlock(map); 1738 1739 if (map == kmem_map) 1740 splx(s); --- 60 unchanged lines hidden (view full) --- 1801 vm_map_t src_map, dst_map; 1802 register vm_map_entry_t src_entry, dst_entry; 1803{ 1804 vm_pindex_t temp_pindex; 1805 1806 if (src_entry->is_sub_map || dst_entry->is_sub_map) 1807 return; 1808 |
1809 if (dst_entry->object.vm_object != NULL) 1810 printf("vm_map_copy_entry: dst_entry object not NULL!\n"); 1811 1812 /* 1813 * If our destination map was wired down, unwire it now. 1814 */ 1815 1816 if (dst_entry->wired_count != 0) 1817 vm_map_entry_unwire(dst_map, dst_entry); 1818 | |
1819 if (src_entry->wired_count == 0) { 1820 1821 boolean_t src_needs_copy; 1822 1823 /* 1824 * If the source entry is marked needs_copy, it is already 1825 * write-protected. 1826 */ --- 15 unchanged lines hidden (view full) --- 1842 src_entry->protection & ~VM_PROT_WRITE); 1843 } else { 1844 vm_object_pmap_copy(src_entry->object.vm_object, 1845 OFF_TO_IDX(src_entry->offset), 1846 OFF_TO_IDX(src_entry->offset + (src_entry->end 1847 - src_entry->start))); 1848 } 1849 } | 1809 if (src_entry->wired_count == 0) { 1810 1811 boolean_t src_needs_copy; 1812 1813 /* 1814 * If the source entry is marked needs_copy, it is already 1815 * write-protected. 1816 */ --- 15 unchanged lines hidden (view full) --- 1832 src_entry->protection & ~VM_PROT_WRITE); 1833 } else { 1834 vm_object_pmap_copy(src_entry->object.vm_object, 1835 OFF_TO_IDX(src_entry->offset), 1836 OFF_TO_IDX(src_entry->offset + (src_entry->end 1837 - src_entry->start))); 1838 } 1839 } |
1840 |
|
1850 /* 1851 * Make a copy of the object. 1852 */ | 1841 /* 1842 * Make a copy of the object. 1843 */ |
1853 temp_pindex = OFF_TO_IDX(dst_entry->offset); 1854 vm_object_copy(src_entry->object.vm_object, 1855 OFF_TO_IDX(src_entry->offset), 1856 &dst_entry->object.vm_object, 1857 &temp_pindex, 1858 &src_needs_copy); 1859 dst_entry->offset = IDX_TO_OFF(temp_pindex); 1860 /* 1861 * If we didn't get a copy-object now, mark the source map 1862 * entry so that a shadow will be created to hold its changed 1863 * pages. 1864 */ 1865 if (src_needs_copy) | 1844 if (src_entry->object.vm_object) { 1845 if ((src_entry->object.vm_object->handle == NULL) && 1846 (src_entry->object.vm_object->type == OBJT_DEFAULT || 1847 src_entry->object.vm_object->type == OBJT_SWAP)) 1848 vm_object_collapse(src_entry->object.vm_object); 1849 ++src_entry->object.vm_object->ref_count; 1850 src_entry->copy_on_write = TRUE; |
1866 src_entry->needs_copy = TRUE; 1867 | 1851 src_entry->needs_copy = TRUE; 1852 |
1868 /* 1869 * The destination always needs to have a shadow created. 1870 */ 1871 dst_entry->needs_copy = TRUE; | 1853 dst_entry->needs_copy = TRUE; 1854 dst_entry->copy_on_write = TRUE; 1855 dst_entry->object.vm_object = 1856 src_entry->object.vm_object; 1857 dst_entry->offset = src_entry->offset; 1858 } else { 1859 dst_entry->object.vm_object = NULL; 1860 dst_entry->offset = 0; 1861 } |
1872 | 1862 |
1873 /* 1874 * Mark the entries copy-on-write, so that write-enabling the 1875 * entry won't make copy-on-write pages writable. 1876 */ 1877 src_entry->copy_on_write = TRUE; 1878 dst_entry->copy_on_write = TRUE; 1879 | |
1880 pmap_copy(dst_map->pmap, src_map->pmap, dst_entry->start, 1881 dst_entry->end - dst_entry->start, src_entry->start); 1882 } else { 1883 /* 1884 * Of course, wired down pages can't be set copy-on-write. 1885 * Cause wired pages to be copied into the new map by 1886 * simulating faults (the new pages are pageable) 1887 */ --- 69 unchanged lines hidden (view full) --- 1957 (old_entry->end - old_entry->start), 1958 old_entry->start); 1959 break; 1960 1961 case VM_INHERIT_COPY: 1962 /* 1963 * Clone the entry and link into the map. 1964 */ | 1863 pmap_copy(dst_map->pmap, src_map->pmap, dst_entry->start, 1864 dst_entry->end - dst_entry->start, src_entry->start); 1865 } else { 1866 /* 1867 * Of course, wired down pages can't be set copy-on-write. 1868 * Cause wired pages to be copied into the new map by 1869 * simulating faults (the new pages are pageable) 1870 */ --- 69 unchanged lines hidden (view full) --- 1940 (old_entry->end - old_entry->start), 1941 old_entry->start); 1942 break; 1943 1944 case VM_INHERIT_COPY: 1945 /* 1946 * Clone the entry and link into the map. 1947 */ |
1965 | |
1966 new_entry = vm_map_entry_create(new_map); 1967 *new_entry = *old_entry; 1968 new_entry->wired_count = 0; 1969 new_entry->object.vm_object = NULL; 1970 new_entry->is_a_map = FALSE; 1971 vm_map_entry_link(new_map, new_map->header.prev, 1972 new_entry); 1973 vm_map_copy_entry(old_map, new_map, old_entry, --- 272 unchanged lines hidden (view full) --- 2246vm_map_simplify(map, start) 2247 vm_map_t map; 2248 vm_offset_t start; 2249{ 2250 vm_map_entry_t this_entry; 2251 vm_map_entry_t prev_entry; 2252 2253 vm_map_lock(map); | 1948 new_entry = vm_map_entry_create(new_map); 1949 *new_entry = *old_entry; 1950 new_entry->wired_count = 0; 1951 new_entry->object.vm_object = NULL; 1952 new_entry->is_a_map = FALSE; 1953 vm_map_entry_link(new_map, new_map->header.prev, 1954 new_entry); 1955 vm_map_copy_entry(old_map, new_map, old_entry, --- 272 unchanged lines hidden (view full) --- 2228vm_map_simplify(map, start) 2229 vm_map_t map; 2230 vm_offset_t start; 2231{ 2232 vm_map_entry_t this_entry; 2233 vm_map_entry_t prev_entry; 2234 2235 vm_map_lock(map); |
2254 if ( 2255 (vm_map_lookup_entry(map, start, &this_entry)) && | 2236 if ((vm_map_lookup_entry(map, start, &this_entry)) && |
2256 ((prev_entry = this_entry->prev) != &map->header) && | 2237 ((prev_entry = this_entry->prev) != &map->header) && |
2257 | |
2258 (prev_entry->end == start) && | 2238 (prev_entry->end == start) && |
2239 (prev_entry->object.vm_object == this_entry->object.vm_object) && 2240 ((prev_entry->offset + (prev_entry->end - prev_entry->start)) 2241 == this_entry->offset) && 2242 |
|
2259 (map->is_main_map) && 2260 2261 (prev_entry->is_a_map == FALSE) && 2262 (prev_entry->is_sub_map == FALSE) && 2263 2264 (this_entry->is_a_map == FALSE) && 2265 (this_entry->is_sub_map == FALSE) && 2266 2267 (prev_entry->inheritance == this_entry->inheritance) && 2268 (prev_entry->protection == this_entry->protection) && 2269 (prev_entry->max_protection == this_entry->max_protection) && 2270 (prev_entry->wired_count == this_entry->wired_count) && 2271 2272 (prev_entry->copy_on_write == this_entry->copy_on_write) && | 2243 (map->is_main_map) && 2244 2245 (prev_entry->is_a_map == FALSE) && 2246 (prev_entry->is_sub_map == FALSE) && 2247 2248 (this_entry->is_a_map == FALSE) && 2249 (this_entry->is_sub_map == FALSE) && 2250 2251 (prev_entry->inheritance == this_entry->inheritance) && 2252 (prev_entry->protection == this_entry->protection) && 2253 (prev_entry->max_protection == this_entry->max_protection) && 2254 (prev_entry->wired_count == this_entry->wired_count) && 2255 2256 (prev_entry->copy_on_write == this_entry->copy_on_write) && |
2273 (prev_entry->needs_copy == this_entry->needs_copy) && 2274 2275 (prev_entry->object.vm_object == this_entry->object.vm_object) && 2276 ((prev_entry->offset + (prev_entry->end - prev_entry->start)) 2277 == this_entry->offset) 2278 ) { | 2257 (prev_entry->needs_copy == this_entry->needs_copy)) { |
2279 if (map->first_free == this_entry) 2280 map->first_free = prev_entry; | 2258 if (map->first_free == this_entry) 2259 map->first_free = prev_entry; |
2281 SAVE_HINT(map, prev_entry); | 2260 if (map->hint == this_entry) 2261 SAVE_HINT(map, prev_entry); |
2282 vm_map_entry_unlink(map, this_entry); 2283 prev_entry->end = this_entry->end; | 2262 vm_map_entry_unlink(map, this_entry); 2263 prev_entry->end = this_entry->end; |
2284 vm_object_deallocate(this_entry->object.vm_object); | 2264 if (this_entry->object.vm_object) 2265 vm_object_deallocate(this_entry->object.vm_object); |
2285 vm_map_entry_dispose(map, this_entry); 2286 } 2287 vm_map_unlock(map); 2288} 2289 2290#ifdef DDB 2291/* 2292 * vm_map_print: [ debug ] --- 71 unchanged lines hidden --- | 2266 vm_map_entry_dispose(map, this_entry); 2267 } 2268 vm_map_unlock(map); 2269} 2270 2271#ifdef DDB 2272/* 2273 * vm_map_print: [ debug ] --- 71 unchanged lines hidden --- |