2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * File: vm/vm_shared_memory_server.c
25 * Author: Chris Youngworth
27 * Support routines for an in-kernel shared memory allocator
30 #include <ipc/ipc_port.h>
31 #include <kern/thread.h>
32 #include <kern/zalloc.h>
33 #include <mach/kern_return.h>
34 #include <mach/vm_inherit.h>
35 #include <vm/vm_kern.h>
36 #include <vm/vm_map.h>
37 #include <vm/vm_page.h>
39 #include <mach/shared_memory_server.h>
40 #include <vm/vm_shared_memory_server.h>
42 /* forward declarations */
45 ipc_port_t
*shared_text_region_handle
,
46 vm_size_t text_region_size
,
47 ipc_port_t
*shared_data_region_handle
,
48 vm_size_t data_region_size
,
49 vm_offset_t
*shared_file_mapping_array
);
51 static load_struct_t
*
53 queue_head_t
*hash_table
,
57 shared_region_task_mappings_t sm_info
);
59 static load_struct_t
*
62 vm_offset_t base_offset
,
63 shared_region_task_mappings_t sm_info
);
68 shared_region_task_mappings_t sm_info
);
72 vm_offset_t mapped_file
,
73 vm_size_t mapped_file_size
,
74 vm_offset_t
*base_address
,
75 sf_mapping_t
*mappings
,
79 shared_region_task_mappings_t sm_info
);
84 vm_offset_t base_offset
,
85 shared_region_task_mappings_t sm_info
);
88 #define load_file_hash(file_object, size) \
89 ((((natural_t)file_object) & 0xffffff) % size)
92 vm_offset_t shared_file_text_region
;
93 vm_offset_t shared_file_data_region
;
95 ipc_port_t shared_text_region_handle
;
96 ipc_port_t shared_data_region_handle
;
97 vm_offset_t shared_file_mapping_array
= 0;
98 shared_region_mapping_t system_shared_region
= NULL
;
100 ipc_port_t sfma_handle
= NULL
;
103 int shared_file_available_hash_ele
;
106 shared_file_create_system_region(
107 shared_region_mapping_t
*shared_region
)
109 ipc_port_t text_handle
;
110 ipc_port_t data_handle
;
113 vm_offset_t mapping_array
;
116 text_size
= 0x10000000;
117 data_size
= 0x10000000;
119 kret
= shared_file_init(&text_handle
,
120 text_size
, &data_handle
, data_size
, &mapping_array
);
123 kret
= shared_region_mapping_create(text_handle
,
124 text_size
, data_handle
, data_size
, mapping_array
,
125 GLOBAL_SHARED_TEXT_SEGMENT
, shared_region
,
126 0x9000000, 0x9000000);
129 (*shared_region
)->flags
= 0;
133 shared_file_boot_time_init(
136 long shared_text_region_size
;
137 long shared_data_region_size
;
138 shared_region_mapping_t new_system_region
;
139 shared_region_mapping_t old_system_region
;
141 shared_text_region_size
= 0x10000000;
142 shared_data_region_size
= 0x10000000;
143 shared_file_init(&shared_text_region_handle
,
144 shared_text_region_size
, &shared_data_region_handle
,
145 shared_data_region_size
, &shared_file_mapping_array
);
147 shared_region_mapping_create(shared_text_region_handle
,
148 shared_text_region_size
, shared_data_region_handle
,
149 shared_data_region_size
, shared_file_mapping_array
,
150 GLOBAL_SHARED_TEXT_SEGMENT
, &new_system_region
,
151 0x9000000, 0x9000000);
152 old_system_region
= system_shared_region
;
153 system_shared_region
= new_system_region
;
154 system_shared_region
->flags
= SHARED_REGION_SYSTEM
;
155 /* consume the reference held because this is the */
156 /* system shared region */
157 if(old_system_region
) {
158 shared_region_mapping_dealloc(old_system_region
);
160 /* hold an extra reference because these are the system */
161 /* shared regions. */
162 shared_region_mapping_ref(system_shared_region
);
163 vm_set_shared_region(current_task(), system_shared_region
);
168 /* called at boot time, allocates two regions, each 256 megs in size */
169 /* these regions are later mapped into task spaces, allowing them to */
170 /* share the contents of the regions. shared_file_init is part of */
171 /* a shared_memory_server which not only allocates the backing maps */
172 /* but also coordinates requests for space. */
177 ipc_port_t
*shared_text_region_handle
,
178 vm_size_t text_region_size
,
179 ipc_port_t
*shared_data_region_handle
,
180 vm_size_t data_region_size
,
181 vm_offset_t
*mapping_array
)
183 vm_offset_t aligned_address
;
184 shared_file_info_t
*sf_head
;
185 vm_offset_t table_mapping_address
;
191 vm_object_t buf_object
;
192 vm_map_entry_t entry
;
197 /* create text and data maps/regions */
198 if(kret
= vm_region_object_create(kernel_map
,
200 shared_text_region_handle
)) {
204 if(kret
= vm_region_object_create(kernel_map
,
206 shared_data_region_handle
)) {
207 ipc_port_release_send(*shared_text_region_handle
);
211 data_table_size
= data_region_size
>> 9;
212 hash_size
= data_region_size
>> 14;
213 table_mapping_address
= data_region_size
- data_table_size
;
215 if(shared_file_mapping_array
== 0) {
216 buf_object
= vm_object_allocate(data_table_size
);
218 if(vm_map_find_space(kernel_map
, &shared_file_mapping_array
,
219 data_table_size
, 0, &entry
) != KERN_SUCCESS
) {
220 panic("shared_file_init: no space");
222 *mapping_array
= shared_file_mapping_array
;
223 vm_map_unlock(kernel_map
);
224 entry
->object
.vm_object
= buf_object
;
227 for (b
= *mapping_array
, alloced
= 0;
228 alloced
< (hash_size
+
229 round_page(sizeof(struct sf_mapping
)));
230 alloced
+= PAGE_SIZE
, b
+= PAGE_SIZE
) {
231 vm_object_lock(buf_object
);
232 p
= vm_page_alloc(buf_object
, alloced
);
233 if (p
== VM_PAGE_NULL
) {
234 panic("shared_file_init: no space");
237 vm_object_unlock(buf_object
);
238 pmap_enter(kernel_pmap
, b
, p
->phys_addr
,
239 VM_PROT_READ
| VM_PROT_WRITE
,
240 VM_WIMG_USE_DEFAULT
, TRUE
);
244 /* initialize loaded file array */
245 sf_head
= (shared_file_info_t
*)*mapping_array
;
246 sf_head
->hash
= (queue_head_t
*)
247 (((int)*mapping_array
) +
248 sizeof(struct shared_file_info
));
249 sf_head
->hash_size
= hash_size
/sizeof(queue_head_t
);
250 mutex_init(&(sf_head
->lock
), (ETAP_VM_MAP
));
251 sf_head
->hash_init
= FALSE
;
254 mach_make_memory_entry(kernel_map
, &data_table_size
,
255 *mapping_array
, VM_PROT_READ
, &sfma_handle
,
258 if (vm_map_wire(kernel_map
, *mapping_array
,
260 (hash_size
+ round_page(sizeof(struct sf_mapping
))),
261 VM_PROT_DEFAULT
, FALSE
) != KERN_SUCCESS
) {
262 panic("shared_file_init: No memory for data table");
265 lsf_zone
= zinit(sizeof(struct load_file_ele
),
267 (hash_size
+ round_page(sizeof(struct sf_mapping
))),
268 0, "load_file_server");
270 zone_change(lsf_zone
, Z_EXHAUST
, TRUE
);
271 zone_change(lsf_zone
, Z_COLLECT
, FALSE
);
272 zone_change(lsf_zone
, Z_EXPAND
, FALSE
);
273 zone_change(lsf_zone
, Z_FOREIGN
, TRUE
);
275 *mapping_array
= shared_file_mapping_array
;
278 vm_map(((vm_named_entry_t
)
279 (*shared_data_region_handle
)->ip_kobject
)->backing
.map
,
280 &table_mapping_address
,
281 data_table_size
, 0, SHARED_LIB_ALIAS
,
282 sfma_handle
, 0, FALSE
,
283 VM_PROT_READ
, VM_PROT_READ
, VM_INHERIT_NONE
);
287 /* A call made from user space, copyin_shared_file requires the user to */
288 /* provide the address and size of a mapped file, the full path name of */
289 /* that file and a list of offsets to be mapped into shared memory. */
290 /* By requiring that the file be pre-mapped, copyin_shared_file can */
291 /* guarantee that the file is neither deleted nor changed after the user */
292 /* begins the call. */
296 vm_offset_t mapped_file
,
297 vm_size_t mapped_file_size
,
298 vm_offset_t
*base_address
,
300 sf_mapping_t
*mappings
,
301 memory_object_control_t file_control
,
302 shared_region_task_mappings_t sm_info
,
305 vm_object_t file_object
;
306 vm_map_entry_t entry
;
307 shared_file_info_t
*shared_file_header
;
308 load_struct_t
*file_entry
;
309 loaded_mapping_t
*file_mapping
;
314 /* wire hash entry pool only as needed, since we are the only */
315 /* users, we take a few liberties with the population of our */
317 static int allocable_hash_pages
;
318 static vm_offset_t hash_cram_address
;
321 shared_file_header
= (shared_file_info_t
*)sm_info
->region_mappings
;
323 mutex_lock(&shared_file_header
->lock
);
325 /* If this is the first call to this routine, take the opportunity */
326 /* to initialize the hash table which will be used to look-up */
327 /* mappings based on the file object */
329 if(shared_file_header
->hash_init
== FALSE
) {
330 vm_size_t hash_table_size
;
331 vm_size_t hash_table_offset
;
333 hash_table_size
= (shared_file_header
->hash_size
)
334 * sizeof(struct queue_entry
);
335 hash_table_offset
= hash_table_size
+
336 round_page(sizeof(struct sf_mapping
));
337 for (i
= 0; i
< shared_file_header
->hash_size
; i
++)
338 queue_init(&shared_file_header
->hash
[i
]);
340 allocable_hash_pages
=
341 ((hash_table_size
<<5) - hash_table_offset
)/PAGE_SIZE
;
343 sm_info
->region_mappings
+ hash_table_offset
;
344 shared_file_available_hash_ele
= 0;
346 shared_file_header
->hash_init
= TRUE
;
349 if ((shared_file_available_hash_ele
< 20) && (allocable_hash_pages
)) {
352 cram_size
= allocable_hash_pages
> 3 ?
353 3 : allocable_hash_pages
;
354 allocable_hash_pages
-= cram_size
;
355 cram_size
= cram_size
* PAGE_SIZE
;
356 if (vm_map_wire(kernel_map
, hash_cram_address
,
357 hash_cram_address
+cram_size
,
358 VM_PROT_DEFAULT
, FALSE
) != KERN_SUCCESS
) {
359 panic("shared_file_init: No memory for data table");
361 zcram(lsf_zone
, hash_cram_address
, cram_size
);
362 shared_file_available_hash_ele
363 += cram_size
/sizeof(struct load_file_ele
);
364 hash_cram_address
+= cram_size
;
368 /* Find the entry in the map associated with the current mapping */
369 /* of the file object */
370 file_object
= memory_object_control_to_vm_object(file_control
);
371 if(vm_map_lookup_entry(current_map(), mapped_file
, &entry
)) {
372 vm_object_t mapped_object
;
373 if(entry
->is_sub_map
) {
374 mutex_unlock(&shared_file_header
->lock
);
375 return KERN_INVALID_ADDRESS
;
377 mapped_object
= entry
->object
.vm_object
;
378 while(mapped_object
->shadow
!= NULL
) {
379 mapped_object
= mapped_object
->shadow
;
381 /* check to see that the file object passed is indeed the */
382 /* same as the mapped object passed */
383 if(file_object
!= mapped_object
) {
384 if(sm_info
->flags
& SHARED_REGION_SYSTEM
) {
385 mutex_unlock(&shared_file_header
->lock
);
386 return KERN_PROTECTION_FAILURE
;
388 file_object
= mapped_object
;
392 mutex_unlock(&shared_file_header
->lock
);
393 return KERN_INVALID_ADDRESS
;
396 alternate
= (*flags
& ALTERNATE_LOAD_SITE
) ? TRUE
: FALSE
;
398 if (file_entry
= lsf_hash_lookup(shared_file_header
->hash
,
399 (void *) file_object
, shared_file_header
->hash_size
,
400 alternate
, sm_info
)) {
401 /* File is loaded, check the load manifest for exact match */
402 /* we simplify by requiring that the elements be the same */
403 /* size and in the same order rather than checking for */
404 /* semantic equivalence. */
406 /* If the file is being loaded in the alternate */
407 /* area, one load to alternate is allowed per mapped */
408 /* object the base address is passed back to the */
409 /* caller and the mappings field is filled in. If the */
410 /* caller does not pass the precise mappings_cnt */
411 /* and the Alternate is already loaded, an error */
414 file_mapping
= file_entry
->mappings
;
415 while(file_mapping
!= NULL
) {
417 mutex_unlock(&shared_file_header
->lock
);
418 return KERN_INVALID_ARGUMENT
;
420 if(((mappings
[i
].mapping_offset
)
421 & SHARED_DATA_REGION_MASK
) !=
422 file_mapping
->mapping_offset
||
424 file_mapping
->size
||
425 mappings
[i
].file_offset
!=
426 file_mapping
->file_offset
||
427 mappings
[i
].protection
!=
428 file_mapping
->protection
) {
431 file_mapping
= file_mapping
->next
;
435 mutex_unlock(&shared_file_header
->lock
);
436 return KERN_INVALID_ARGUMENT
;
438 *base_address
= (*base_address
& ~SHARED_TEXT_REGION_MASK
)
439 + file_entry
->base_address
;
440 *flags
= SF_PREV_LOADED
;
441 mutex_unlock(&shared_file_header
->lock
);
444 /* File is not loaded, lets attempt to load it */
445 ret
= lsf_load(mapped_file
, mapped_file_size
, base_address
,
450 if(ret
== KERN_NO_SPACE
) {
451 shared_region_mapping_t regions
;
452 regions
= (shared_region_mapping_t
)sm_info
->self
;
453 regions
->flags
|= SHARED_REGION_FULL
;
454 if(regions
== system_shared_region
) {
455 shared_region_mapping_t new_system_shared_regions
;
456 shared_file_boot_time_init();
457 /* current task must stay with its current */
458 /* regions, drop count on system_shared_region */
459 /* and put back our original set */
460 vm_get_shared_region(current_task(), &new_system_shared_regions
);
461 shared_region_mapping_dealloc(new_system_shared_regions
);
462 vm_set_shared_region(current_task(), regions
);
465 mutex_unlock(&shared_file_header
->lock
);
470 /* A hash lookup function for the list of loaded files in */
471 /* shared_memory_server space. */
473 static load_struct_t
*
475 queue_head_t
*hash_table
,
479 shared_region_task_mappings_t sm_info
)
481 register queue_t bucket
;
482 load_struct_t
*entry
;
483 shared_region_mapping_t target_region
;
486 bucket
= &(hash_table
[load_file_hash((int)file_object
, size
)]);
487 for (entry
= (load_struct_t
*)queue_first(bucket
);
488 !queue_end(bucket
, &entry
->links
);
489 entry
= (load_struct_t
*)queue_next(&entry
->links
)) {
490 if (entry
->file_object
== (int)file_object
) {
491 target_region
= (shared_region_mapping_t
)sm_info
->self
;
492 depth
= target_region
->depth
;
493 while(target_region
) {
494 if((!(sm_info
->self
)) ||
495 ((target_region
== entry
->regions_instance
) &&
496 (target_region
->depth
>= entry
->depth
))) {
498 if (entry
->base_address
>=
499 sm_info
->alternate_base
)
502 if (entry
->base_address
<
503 sm_info
->alternate_base
)
507 if(target_region
->object_chain
) {
508 target_region
= (shared_region_mapping_t
)
509 target_region
->object_chain
->object_chain_region
;
510 depth
= target_region
->object_chain
->depth
;
512 target_region
= NULL
;
518 return (load_struct_t
*)0;
522 lsf_remove_regions_mappings(
523 shared_region_mapping_t region
,
524 shared_region_task_mappings_t sm_info
)
527 register queue_t bucket
;
528 shared_file_info_t
*shared_file_header
;
529 load_struct_t
*entry
;
530 load_struct_t
*next_entry
;
531 load_struct_t
*prev_entry
;
533 shared_file_header
= (shared_file_info_t
*)sm_info
->region_mappings
;
535 mutex_lock(&shared_file_header
->lock
);
536 if(shared_file_header
->hash_init
== FALSE
) {
537 mutex_unlock(&shared_file_header
->lock
);
540 for(i
= 0; i
<shared_file_header
->hash_size
; i
++) {
541 bucket
= &shared_file_header
->hash
[i
];
542 for (entry
= (load_struct_t
*)queue_first(bucket
);
543 !queue_end(bucket
, &entry
->links
);) {
544 next_entry
= (load_struct_t
*)queue_next(&entry
->links
);
545 if(region
== entry
->regions_instance
) {
546 lsf_unload((void *)entry
->file_object
,
547 entry
->base_address
, sm_info
);
552 mutex_unlock(&shared_file_header
->lock
);
555 /* Removes a map_list, (list of loaded extents) for a file from */
556 /* the loaded file hash table. */
558 static load_struct_t
*
561 vm_offset_t base_offset
,
562 shared_region_task_mappings_t sm_info
)
564 register queue_t bucket
;
565 shared_file_info_t
*shared_file_header
;
566 load_struct_t
*entry
;
567 load_struct_t
*prev_entry
;
569 shared_file_header
= (shared_file_info_t
*)sm_info
->region_mappings
;
571 bucket
= &shared_file_header
->hash
572 [load_file_hash((int)file_object
, shared_file_header
->hash_size
)];
574 for (entry
= (load_struct_t
*)queue_first(bucket
);
575 !queue_end(bucket
, &entry
->links
);
576 entry
= (load_struct_t
*)queue_next(&entry
->links
)) {
577 if((!(sm_info
->self
)) || ((shared_region_mapping_t
)
578 sm_info
->self
== entry
->regions_instance
)) {
579 if ((entry
->file_object
== (int) file_object
) &&
580 (entry
->base_address
== base_offset
)) {
581 queue_remove(bucket
, entry
,
582 load_struct_ptr_t
, links
);
588 return (load_struct_t
*)0;
591 /* Inserts a new map_list, (list of loaded file extents), into the */
592 /* server loaded file hash table. */
596 load_struct_t
*entry
,
597 shared_region_task_mappings_t sm_info
)
599 shared_file_info_t
*shared_file_header
;
601 shared_file_header
= (shared_file_info_t
*)sm_info
->region_mappings
;
602 queue_enter(&shared_file_header
->hash
603 [load_file_hash(entry
->file_object
,
604 shared_file_header
->hash_size
)],
605 entry
, load_struct_ptr_t
, links
);
608 /* Looks up the file type requested. If already loaded and the */
609 /* file extents are an exact match, returns Success. If not */
610 /* loaded attempts to load the file extents at the given offsets */
611 /* if any extent fails to load or if the file was already loaded */
612 /* in a different configuration, lsf_load fails. */
616 vm_offset_t mapped_file
,
617 vm_size_t mapped_file_size
,
618 vm_offset_t
*base_address
,
619 sf_mapping_t
*mappings
,
623 shared_region_task_mappings_t sm_info
)
626 load_struct_t
*entry
;
627 vm_map_copy_t copy_object
;
628 loaded_mapping_t
*file_mapping
;
629 loaded_mapping_t
**tptr
;
631 ipc_port_t local_map
;
632 vm_offset_t original_alt_load_next
;
633 vm_offset_t alternate_load_next
;
635 entry
= (load_struct_t
*)zalloc(lsf_zone
);
636 shared_file_available_hash_ele
--;
637 entry
->file_object
= (int)file_object
;
638 entry
->mapping_cnt
= map_cnt
;
639 entry
->mappings
= NULL
;
640 entry
->links
.prev
= (queue_entry_t
) 0;
641 entry
->links
.next
= (queue_entry_t
) 0;
642 entry
->regions_instance
= (shared_region_mapping_t
)sm_info
->self
;
643 entry
->depth
=((shared_region_mapping_t
)sm_info
->self
)->depth
;
645 lsf_hash_insert(entry
, sm_info
);
646 tptr
= &(entry
->mappings
);
649 alternate_load_next
= sm_info
->alternate_next
;
650 original_alt_load_next
= alternate_load_next
;
651 if (flags
& ALTERNATE_LOAD_SITE
) {
652 int max_loadfile_offset
;
654 *base_address
= ((*base_address
) & ~SHARED_TEXT_REGION_MASK
) +
655 sm_info
->alternate_next
;
656 max_loadfile_offset
= 0;
657 for(i
= 0; i
<map_cnt
; i
++) {
658 if(((mappings
[i
].mapping_offset
659 & SHARED_TEXT_REGION_MASK
)+ mappings
[i
].size
) >
660 max_loadfile_offset
) {
661 max_loadfile_offset
=
662 (mappings
[i
].mapping_offset
663 & SHARED_TEXT_REGION_MASK
)
667 if((alternate_load_next
+ round_page(max_loadfile_offset
)) >=
668 (sm_info
->data_size
- (sm_info
->data_size
>>9))) {
670 return KERN_NO_SPACE
;
672 alternate_load_next
+= round_page(max_loadfile_offset
);
675 if (((*base_address
) & SHARED_TEXT_REGION_MASK
) >
676 sm_info
->alternate_base
) {
677 entry
->base_address
=
678 (*base_address
) & SHARED_TEXT_REGION_MASK
;
679 lsf_unload(file_object
, entry
->base_address
, sm_info
);
680 return KERN_INVALID_ARGUMENT
;
684 entry
->base_address
= (*base_address
) & SHARED_TEXT_REGION_MASK
;
686 /* copyin mapped file data */
687 for(i
= 0; i
<map_cnt
; i
++) {
688 vm_offset_t target_address
;
689 vm_offset_t region_mask
;
691 if(mappings
[i
].protection
& VM_PROT_COW
) {
692 local_map
= (ipc_port_t
)sm_info
->data_region
;
693 region_mask
= SHARED_DATA_REGION_MASK
;
694 if((mappings
[i
].mapping_offset
695 & GLOBAL_SHARED_SEGMENT_MASK
) != 0x10000000) {
696 lsf_unload(file_object
,
697 entry
->base_address
, sm_info
);
698 return KERN_INVALID_ARGUMENT
;
701 region_mask
= SHARED_TEXT_REGION_MASK
;
702 local_map
= (ipc_port_t
)sm_info
->text_region
;
703 if(mappings
[i
].mapping_offset
704 & GLOBAL_SHARED_SEGMENT_MASK
) {
705 lsf_unload(file_object
,
706 entry
->base_address
, sm_info
);
707 return KERN_INVALID_ARGUMENT
;
710 if(!(mappings
[i
].protection
& VM_PROT_ZF
)
711 && ((mapped_file
+ mappings
[i
].file_offset
+
713 (mapped_file
+ mapped_file_size
))) {
714 lsf_unload(file_object
, entry
->base_address
, sm_info
);
715 return KERN_INVALID_ARGUMENT
;
717 target_address
= ((mappings
[i
].mapping_offset
) & region_mask
)
718 + entry
->base_address
;
719 if(vm_allocate(((vm_named_entry_t
)local_map
->ip_kobject
)
720 ->backing
.map
, &target_address
,
721 mappings
[i
].size
, FALSE
)) {
722 lsf_unload(file_object
, entry
->base_address
, sm_info
);
725 target_address
= ((mappings
[i
].mapping_offset
) & region_mask
)
726 + entry
->base_address
;
727 if(!(mappings
[i
].protection
& VM_PROT_ZF
)) {
728 if(vm_map_copyin(current_map(),
729 mapped_file
+ mappings
[i
].file_offset
,
730 round_page(mappings
[i
].size
), FALSE
, ©_object
)) {
731 vm_deallocate(((vm_named_entry_t
)local_map
->ip_kobject
)
732 ->backing
.map
, target_address
, mappings
[i
].size
);
733 lsf_unload(file_object
, entry
->base_address
, sm_info
);
736 if(vm_map_copy_overwrite(((vm_named_entry_t
)
737 local_map
->ip_kobject
)->backing
.map
, target_address
,
738 copy_object
, FALSE
)) {
739 vm_deallocate(((vm_named_entry_t
)local_map
->ip_kobject
)
740 ->backing
.map
, target_address
, mappings
[i
].size
);
741 lsf_unload(file_object
, entry
->base_address
, sm_info
);
745 vm_map_protect(((vm_named_entry_t
)local_map
->ip_kobject
)
746 ->backing
.map
, target_address
,
747 round_page(target_address
+ mappings
[i
].size
),
748 (mappings
[i
].protection
&
749 (VM_PROT_READ
| VM_PROT_EXECUTE
)),
751 vm_map_protect(((vm_named_entry_t
)local_map
->ip_kobject
)
752 ->backing
.map
, target_address
,
753 round_page(target_address
+ mappings
[i
].size
),
754 (mappings
[i
].protection
&
755 (VM_PROT_READ
| VM_PROT_EXECUTE
)),
757 file_mapping
= (loaded_mapping_t
*)zalloc(lsf_zone
);
758 if(file_mapping
== 0)
759 panic("lsf_load: OUT OF MAPPINGS!");
760 shared_file_available_hash_ele
--;
761 file_mapping
->mapping_offset
= (mappings
[i
].mapping_offset
)
763 file_mapping
->size
= mappings
[i
].size
;
764 file_mapping
->file_offset
= mappings
[i
].file_offset
;
765 file_mapping
->protection
= mappings
[i
].protection
;
766 file_mapping
->next
= NULL
;
767 *tptr
= file_mapping
;
768 tptr
= &(file_mapping
->next
);
770 shared_region_mapping_set_alt_next(sm_info
->self
, alternate_load_next
);
776 /* finds the file_object extent list in the shared memory hash table */
777 /* If one is found the associated extents in shared memory are deallocated */
778 /* and the extent list is freed */
783 vm_offset_t base_offset
,
784 shared_region_task_mappings_t sm_info
)
786 load_struct_t
*entry
;
787 ipc_port_t local_map
;
788 loaded_mapping_t
*map_ele
;
789 loaded_mapping_t
*back_ptr
;
791 entry
= lsf_hash_delete(file_object
, base_offset
, sm_info
);
793 map_ele
= entry
->mappings
;
794 while(map_ele
!= NULL
) {
795 if(map_ele
->protection
& VM_PROT_COW
) {
796 local_map
= (ipc_port_t
)sm_info
->data_region
;
798 local_map
= (ipc_port_t
)sm_info
->text_region
;
800 vm_deallocate(((vm_named_entry_t
)local_map
->ip_kobject
)
801 ->backing
.map
, entry
->base_address
+
802 map_ele
->mapping_offset
,
805 map_ele
= map_ele
->next
;
806 zfree(lsf_zone
, (vm_offset_t
)back_ptr
);
807 shared_file_available_hash_ele
++;
809 zfree(lsf_zone
, (vm_offset_t
)entry
);
810 shared_file_available_hash_ele
++;
814 /* integer is from 1 to 100 and represents percent full */
816 lsf_mapping_pool_gauge()
818 return ((lsf_zone
->count
* lsf_zone
->elem_size
) * 100)/lsf_zone
->max_size
;