]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ipc_host.c
xnu-792.12.6.tar.gz
[apple/xnu.git] / osfmk / kern / ipc_host.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
36 * All Rights Reserved.
37 *
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
57 */
58 /*
59 */
60
61 /*
62 * kern/ipc_host.c
63 *
64 * Routines to implement host ports.
65 */
66 #include <mach/message.h>
67 #include <mach/mach_traps.h>
68 #include <mach/mach_host_server.h>
69 #include <mach/host_priv_server.h>
70 #include <kern/host.h>
71 #include <kern/processor.h>
72 #include <kern/lock.h>
73 #include <kern/task.h>
74 #include <kern/thread.h>
75 #include <kern/ipc_host.h>
76 #include <kern/ipc_kobject.h>
77 #include <kern/misc_protos.h>
78 #include <kern/spl.h>
79 #include <ipc/ipc_port.h>
80 #include <ipc/ipc_space.h>
81
82 /*
83 * Forward declarations
84 */
85
86 void
87 ipc_processor_terminate(
88 processor_t processor);
89
90 void
91 ipc_processor_disable(
92 processor_t processor);
93
94 boolean_t
95 ref_pset_port_locked(
96 ipc_port_t port, boolean_t matchn, processor_set_t *ppset);
97
98 /*
99 * ipc_host_init: set up various things.
100 */
101
102 void ipc_host_init(void)
103 {
104 ipc_port_t port;
105 int i;
106
107 mutex_init(&realhost.lock, 0);
108
109 /*
110 * Allocate and set up the two host ports.
111 */
112 port = ipc_port_alloc_kernel();
113 if (port == IP_NULL)
114 panic("ipc_host_init");
115
116 ipc_kobject_set(port, (ipc_kobject_t) &realhost, IKOT_HOST_SECURITY);
117 kernel_set_special_port(&realhost, HOST_SECURITY_PORT,
118 ipc_port_make_send(port));
119
120 port = ipc_port_alloc_kernel();
121 if (port == IP_NULL)
122 panic("ipc_host_init");
123
124 ipc_kobject_set(port, (ipc_kobject_t) &realhost, IKOT_HOST);
125 kernel_set_special_port(&realhost, HOST_PORT,
126 ipc_port_make_send(port));
127
128 port = ipc_port_alloc_kernel();
129 if (port == IP_NULL)
130 panic("ipc_host_init");
131
132 ipc_kobject_set(port, (ipc_kobject_t) &realhost, IKOT_HOST_PRIV);
133 kernel_set_special_port(&realhost, HOST_PRIV_PORT,
134 ipc_port_make_send(port));
135
136 /* the rest of the special ports will be set up later */
137
138 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
139 realhost.exc_actions[i].port = IP_NULL;
140 }/* for */
141
142 /*
143 * Set up ipc for default processor set.
144 */
145 ipc_pset_init(&default_pset);
146 ipc_pset_enable(&default_pset);
147
148 /*
149 * And for master processor
150 */
151 ipc_processor_init(master_processor);
152 ipc_processor_enable(master_processor);
153 }
154
155 /*
156 * Routine: host_self_trap [mach trap]
157 * Purpose:
158 * Give the caller send rights for his own host port.
159 * Conditions:
160 * Nothing locked.
161 * Returns:
162 * MACH_PORT_NULL if there are any resource failures
163 * or other errors.
164 */
165
166 mach_port_name_t
167 host_self_trap(
168 __unused struct host_self_trap_args *args)
169 {
170 ipc_port_t sright;
171 mach_port_name_t name;
172
173 sright = ipc_port_copy_send(current_task()->itk_host);
174 name = ipc_port_copyout_send(sright, current_space());
175 return name;
176 }
177
178 /*
179 * ipc_processor_init:
180 *
181 * Initialize ipc access to processor by allocating port.
182 */
183
184 void
185 ipc_processor_init(
186 processor_t processor)
187 {
188 ipc_port_t port;
189
190 port = ipc_port_alloc_kernel();
191 if (port == IP_NULL)
192 panic("ipc_processor_init");
193 processor->processor_self = port;
194 }
195
196 /*
197 * ipc_processor_enable:
198 *
199 * Enable ipc control of processor by setting port object.
200 */
201 void
202 ipc_processor_enable(
203 processor_t processor)
204 {
205 ipc_port_t myport;
206
207 myport = processor->processor_self;
208 ipc_kobject_set(myport, (ipc_kobject_t) processor, IKOT_PROCESSOR);
209 }
210
211 /*
212 * ipc_processor_disable:
213 *
214 * Disable ipc control of processor by clearing port object.
215 */
216 void
217 ipc_processor_disable(
218 processor_t processor)
219 {
220 ipc_port_t myport;
221
222 myport = processor->processor_self;
223 if (myport == IP_NULL)
224 return;
225 ipc_kobject_set(myport, IKO_NULL, IKOT_NONE);
226 }
227
228 /*
229 * ipc_processor_terminate:
230 *
231 * Processor is off-line. Destroy ipc control port.
232 */
233 void
234 ipc_processor_terminate(
235 processor_t processor)
236 {
237 ipc_port_t myport;
238 spl_t s;
239
240 s = splsched();
241 processor_lock(processor);
242 myport = processor->processor_self;
243 if (myport == IP_NULL) {
244 processor_unlock(processor);
245 splx(s);
246 return;
247 }
248
249 processor->processor_self = IP_NULL;
250 processor_unlock(processor);
251 splx(s);
252
253 ipc_port_dealloc_kernel(myport);
254 }
255
256 /*
257 * ipc_pset_init:
258 *
259 * Initialize ipc control of a processor set by allocating its ports.
260 */
261
262 void
263 ipc_pset_init(
264 processor_set_t pset)
265 {
266 ipc_port_t port;
267
268 port = ipc_port_alloc_kernel();
269 if (port == IP_NULL)
270 panic("ipc_pset_init");
271 pset->pset_self = port;
272
273 port = ipc_port_alloc_kernel();
274 if (port == IP_NULL)
275 panic("ipc_pset_init");
276 pset->pset_name_self = port;
277 }
278
279 /*
280 * ipc_pset_enable:
281 *
282 * Enable ipc access to a processor set.
283 */
284 void
285 ipc_pset_enable(
286 processor_set_t pset)
287 {
288 pset_lock(pset);
289 if (pset->active) {
290 ipc_kobject_set(pset->pset_self,
291 (ipc_kobject_t) pset, IKOT_PSET);
292 ipc_kobject_set(pset->pset_name_self,
293 (ipc_kobject_t) pset, IKOT_PSET_NAME);
294 pset->ref_count += 2;
295 }
296 pset_unlock(pset);
297 }
298
299 /*
300 * ipc_pset_disable:
301 *
302 * Disable ipc access to a processor set by clearing the port objects.
303 * Caller must hold pset lock and a reference to the pset. Ok to
304 * just decrement pset reference count as a result.
305 */
306 void
307 ipc_pset_disable(
308 processor_set_t pset)
309 {
310 ipc_kobject_set(pset->pset_self, IKO_NULL, IKOT_NONE);
311 ipc_kobject_set(pset->pset_name_self, IKO_NULL, IKOT_NONE);
312 pset->ref_count -= 2;
313 }
314
315 /*
316 * ipc_pset_terminate:
317 *
318 * Processor set is dead. Deallocate the ipc control structures.
319 */
320 void
321 ipc_pset_terminate(
322 processor_set_t pset)
323 {
324 ipc_port_dealloc_kernel(pset->pset_self);
325 ipc_port_dealloc_kernel(pset->pset_name_self);
326 }
327
328 /*
329 * processor_set_default, processor_set_default_priv:
330 *
331 * Return ports for manipulating default_processor set. MiG code
332 * differentiates between these two routines.
333 */
334 kern_return_t
335 processor_set_default(
336 host_t host,
337 processor_set_t *pset)
338 {
339 if (host == HOST_NULL)
340 return(KERN_INVALID_ARGUMENT);
341
342 *pset = &default_pset;
343 pset_reference(*pset);
344 return(KERN_SUCCESS);
345 }
346
347 /*
348 * Routine: convert_port_to_host
349 * Purpose:
350 * Convert from a port to a host.
351 * Doesn't consume the port ref; the host produced may be null.
352 * Conditions:
353 * Nothing locked.
354 */
355
356 host_t
357 convert_port_to_host(
358 ipc_port_t port)
359 {
360 host_t host = HOST_NULL;
361
362 if (IP_VALID(port)) {
363 ip_lock(port);
364 if (ip_active(port) &&
365 ((ip_kotype(port) == IKOT_HOST) ||
366 (ip_kotype(port) == IKOT_HOST_PRIV)
367 ))
368 host = (host_t) port->ip_kobject;
369 ip_unlock(port);
370 }
371
372 return host;
373 }
374
375 /*
376 * Routine: convert_port_to_host_priv
377 * Purpose:
378 * Convert from a port to a host.
379 * Doesn't consume the port ref; the host produced may be null.
380 * Conditions:
381 * Nothing locked.
382 */
383
384 host_t
385 convert_port_to_host_priv(
386 ipc_port_t port)
387 {
388 host_t host = HOST_NULL;
389
390 if (IP_VALID(port)) {
391 ip_lock(port);
392 if (ip_active(port) &&
393 (ip_kotype(port) == IKOT_HOST_PRIV))
394 host = (host_t) port->ip_kobject;
395 ip_unlock(port);
396 }
397
398 return host;
399 }
400
401 /*
402 * Routine: convert_port_to_processor
403 * Purpose:
404 * Convert from a port to a processor.
405 * Doesn't consume the port ref;
406 * the processor produced may be null.
407 * Conditions:
408 * Nothing locked.
409 */
410
411 processor_t
412 convert_port_to_processor(
413 ipc_port_t port)
414 {
415 processor_t processor = PROCESSOR_NULL;
416
417 if (IP_VALID(port)) {
418 ip_lock(port);
419 if (ip_active(port) &&
420 (ip_kotype(port) == IKOT_PROCESSOR))
421 processor = (processor_t) port->ip_kobject;
422 ip_unlock(port);
423 }
424
425 return processor;
426 }
427
428 /*
429 * Routine: convert_port_to_pset
430 * Purpose:
431 * Convert from a port to a pset.
432 * Doesn't consume the port ref; produces a pset ref,
433 * which may be null.
434 * Conditions:
435 * Nothing locked.
436 */
437
438 processor_set_t
439 convert_port_to_pset(
440 ipc_port_t port)
441 {
442 boolean_t r;
443 processor_set_t pset = PROCESSOR_SET_NULL;
444
445 r = FALSE;
446 while (!r && IP_VALID(port)) {
447 ip_lock(port);
448 r = ref_pset_port_locked(port, FALSE, &pset);
449 /* port unlocked */
450 }
451 return pset;
452 }
453
454 /*
455 * Routine: convert_port_to_pset_name
456 * Purpose:
457 * Convert from a port to a pset.
458 * Doesn't consume the port ref; produces a pset ref,
459 * which may be null.
460 * Conditions:
461 * Nothing locked.
462 */
463
464 processor_set_name_t
465 convert_port_to_pset_name(
466 ipc_port_t port)
467 {
468 boolean_t r;
469 processor_set_t pset = PROCESSOR_SET_NULL;
470
471 r = FALSE;
472 while (!r && IP_VALID(port)) {
473 ip_lock(port);
474 r = ref_pset_port_locked(port, TRUE, &pset);
475 /* port unlocked */
476 }
477 return pset;
478 }
479
480 boolean_t
481 ref_pset_port_locked(ipc_port_t port, boolean_t matchn, processor_set_t *ppset)
482 {
483 processor_set_t pset;
484
485 pset = PROCESSOR_SET_NULL;
486 if (ip_active(port) &&
487 ((ip_kotype(port) == IKOT_PSET) ||
488 (matchn && (ip_kotype(port) == IKOT_PSET_NAME)))) {
489 pset = (processor_set_t) port->ip_kobject;
490 if (!pset_lock_try(pset)) {
491 ip_unlock(port);
492 mutex_pause();
493 return (FALSE);
494 }
495 pset->ref_count++;
496 pset_unlock(pset);
497 }
498 *ppset = pset;
499 ip_unlock(port);
500 return (TRUE);
501 }
502
503 /*
504 * Routine: convert_host_to_port
505 * Purpose:
506 * Convert from a host to a port.
507 * Produces a naked send right which may be invalid.
508 * Conditions:
509 * Nothing locked.
510 */
511
512 ipc_port_t
513 convert_host_to_port(
514 host_t host)
515 {
516 ipc_port_t port;
517
518 host_get_host_port(host, &port);
519 return port;
520 }
521
522 /*
523 * Routine: convert_processor_to_port
524 * Purpose:
525 * Convert from a processor to a port.
526 * Produces a naked send right which may be invalid.
527 * Conditions:
528 * Nothing locked.
529 */
530
531 ipc_port_t
532 convert_processor_to_port(
533 processor_t processor)
534 {
535 ipc_port_t port;
536 spl_t s;
537
538 s = splsched();
539 processor_lock(processor);
540
541 if (processor->processor_self != IP_NULL)
542 port = ipc_port_make_send(processor->processor_self);
543 else
544 port = IP_NULL;
545
546 processor_unlock(processor);
547 splx(s);
548
549 return port;
550 }
551
552 /*
553 * Routine: convert_pset_to_port
554 * Purpose:
555 * Convert from a pset to a port.
556 * Consumes a pset ref; produces a naked send right
557 * which may be invalid.
558 * Conditions:
559 * Nothing locked.
560 */
561
562 ipc_port_t
563 convert_pset_to_port(
564 processor_set_t pset)
565 {
566 ipc_port_t port;
567
568 pset_lock(pset);
569 if (pset->active)
570 port = ipc_port_make_send(pset->pset_self);
571 else
572 port = IP_NULL;
573 pset_unlock(pset);
574
575 pset_deallocate(pset);
576 return port;
577 }
578
579 /*
580 * Routine: convert_pset_name_to_port
581 * Purpose:
582 * Convert from a pset to a port.
583 * Consumes a pset ref; produces a naked send right
584 * which may be invalid.
585 * Conditions:
586 * Nothing locked.
587 */
588
589 ipc_port_t
590 convert_pset_name_to_port(
591 processor_set_name_t pset)
592 {
593 ipc_port_t port;
594
595 pset_lock(pset);
596 if (pset->active)
597 port = ipc_port_make_send(pset->pset_name_self);
598 else
599 port = IP_NULL;
600 pset_unlock(pset);
601
602 pset_deallocate(pset);
603 return port;
604 }
605
606 /*
607 * Routine: convert_port_to_host_security
608 * Purpose:
609 * Convert from a port to a host security.
610 * Doesn't consume the port ref; the port produced may be null.
611 * Conditions:
612 * Nothing locked.
613 */
614
615 host_t
616 convert_port_to_host_security(
617 ipc_port_t port)
618 {
619 host_t host = HOST_NULL;
620
621 if (IP_VALID(port)) {
622 ip_lock(port);
623 if (ip_active(port) &&
624 (ip_kotype(port) == IKOT_HOST_SECURITY))
625 host = (host_t) port->ip_kobject;
626 ip_unlock(port);
627 }
628
629 return host;
630 }
631
632 /*
633 * Routine: host_set_exception_ports [kernel call]
634 * Purpose:
635 * Sets the host exception port, flavor and
636 * behavior for the exception types specified by the mask.
637 * There will be one send right per exception per valid
638 * port.
639 * Conditions:
640 * Nothing locked. If successful, consumes
641 * the supplied send right.
642 * Returns:
643 * KERN_SUCCESS Changed the special port.
644 * KERN_INVALID_ARGUMENT The host_priv is not valid,
645 * Illegal mask bit set.
646 * Illegal exception behavior
647 */
648 kern_return_t
649 host_set_exception_ports(
650 host_priv_t host_priv,
651 exception_mask_t exception_mask,
652 ipc_port_t new_port,
653 exception_behavior_t new_behavior,
654 thread_state_flavor_t new_flavor)
655 {
656 register int i;
657 ipc_port_t old_port[EXC_TYPES_COUNT];
658
659 if (host_priv == HOST_PRIV_NULL) {
660 return KERN_INVALID_ARGUMENT;
661 }
662
663 assert(host_priv == &realhost);
664
665 if (exception_mask & ~EXC_MASK_ALL) {
666 return KERN_INVALID_ARGUMENT;
667 }
668
669 if (IP_VALID(new_port)) {
670 switch (new_behavior) {
671 case EXCEPTION_DEFAULT:
672 case EXCEPTION_STATE:
673 case EXCEPTION_STATE_IDENTITY:
674 break;
675 default:
676 return KERN_INVALID_ARGUMENT;
677 }
678 }
679 /* Cannot easily check "new_flavor", but that just means that
680 * the flavor in the generated exception message might be garbage:
681 * GIGO
682 */
683 host_lock(host_priv);
684
685 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
686 if (exception_mask & (1 << i)) {
687 old_port[i] = host_priv->exc_actions[i].port;
688 host_priv->exc_actions[i].port =
689 ipc_port_copy_send(new_port);
690 host_priv->exc_actions[i].behavior = new_behavior;
691 host_priv->exc_actions[i].flavor = new_flavor;
692 } else
693 old_port[i] = IP_NULL;
694 }/* for */
695
696 /*
697 * Consume send rights without any lock held.
698 */
699 host_unlock(host_priv);
700 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++)
701 if (IP_VALID(old_port[i]))
702 ipc_port_release_send(old_port[i]);
703 if (IP_VALID(new_port)) /* consume send right */
704 ipc_port_release_send(new_port);
705
706 return KERN_SUCCESS;
707 }
708
709 /*
710 * Routine: host_get_exception_ports [kernel call]
711 * Purpose:
712 * Clones a send right for each of the host's exception
713 * ports specified in the mask and returns the behaviour
714 * and flavor of said port.
715 *
716 * Returns upto [in} CountCnt elements.
717 *
718 * Conditions:
719 * Nothing locked.
720 * Returns:
721 * KERN_SUCCESS Extracted a send right.
722 * KERN_INVALID_ARGUMENT Invalid host_priv specified,
723 * Invalid special port,
724 * Illegal mask bit set.
725 * KERN_FAILURE The thread is dead.
726 */
727 kern_return_t
728 host_get_exception_ports(
729 host_priv_t host_priv,
730 exception_mask_t exception_mask,
731 exception_mask_array_t masks,
732 mach_msg_type_number_t * CountCnt,
733 exception_port_array_t ports,
734 exception_behavior_array_t behaviors,
735 thread_state_flavor_array_t flavors )
736 {
737 unsigned int i, j, count;
738
739 if (host_priv == HOST_PRIV_NULL)
740 return KERN_INVALID_ARGUMENT;
741
742 if (exception_mask & ~EXC_MASK_ALL) {
743 return KERN_INVALID_ARGUMENT;
744 }
745
746 assert (host_priv == &realhost);
747
748 host_lock(host_priv);
749
750 count = 0;
751
752 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
753 if (exception_mask & (1 << i)) {
754 for (j = 0; j < count; j++) {
755 /*
756 * search for an identical entry, if found
757 * set corresponding mask for this exception.
758 */
759 if (host_priv->exc_actions[i].port == ports[j] &&
760 host_priv->exc_actions[i].behavior == behaviors[j]
761 && host_priv->exc_actions[i].flavor == flavors[j])
762 {
763 masks[j] |= (1 << i);
764 break;
765 }
766 }/* for */
767 if (j == count) {
768 masks[j] = (1 << i);
769 ports[j] =
770 ipc_port_copy_send(host_priv->exc_actions[i].port);
771 behaviors[j] = host_priv->exc_actions[i].behavior;
772 flavors[j] = host_priv->exc_actions[i].flavor;
773 count++;
774 if (count > *CountCnt) {
775 break;
776 }
777 }
778 }
779 }/* for */
780 host_unlock(host_priv);
781
782 *CountCnt = count;
783 return KERN_SUCCESS;
784 }
785
786 kern_return_t
787 host_swap_exception_ports(
788 host_priv_t host_priv,
789 exception_mask_t exception_mask,
790 ipc_port_t new_port,
791 exception_behavior_t new_behavior,
792 thread_state_flavor_t new_flavor,
793 exception_mask_array_t masks,
794 mach_msg_type_number_t * CountCnt,
795 exception_port_array_t ports,
796 exception_behavior_array_t behaviors,
797 thread_state_flavor_array_t flavors )
798 {
799 unsigned int i,
800 j,
801 count;
802 ipc_port_t old_port[EXC_TYPES_COUNT];
803
804 if (host_priv == HOST_PRIV_NULL)
805 return KERN_INVALID_ARGUMENT;
806
807 if (exception_mask & ~EXC_MASK_ALL) {
808 return KERN_INVALID_ARGUMENT;
809 }
810
811 if (IP_VALID(new_port)) {
812 switch (new_behavior) {
813 case EXCEPTION_DEFAULT:
814 case EXCEPTION_STATE:
815 case EXCEPTION_STATE_IDENTITY:
816 break;
817 default:
818 return KERN_INVALID_ARGUMENT;
819 }
820 }
821 /* Cannot easily check "new_flavor", but that just means that
822 * the flavor in the generated exception message might be garbage:
823 * GIGO */
824
825 host_lock(host_priv);
826
827 count = 0;
828
829 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
830 if (exception_mask & (1 << i)) {
831 for (j = 0; j < count; j++) {
832 /*
833 * search for an identical entry, if found
834 * set corresponding mask for this exception.
835 */
836 if (host_priv->exc_actions[i].port == ports[j] &&
837 host_priv->exc_actions[i].behavior == behaviors[j]
838 && host_priv->exc_actions[i].flavor == flavors[j])
839 {
840 masks[j] |= (1 << i);
841 break;
842 }
843 }/* for */
844 if (j == count) {
845 masks[j] = (1 << i);
846 ports[j] =
847 ipc_port_copy_send(host_priv->exc_actions[i].port);
848 behaviors[j] = host_priv->exc_actions[i].behavior;
849 flavors[j] = host_priv->exc_actions[i].flavor;
850 count++;
851 }
852 old_port[i] = host_priv->exc_actions[i].port;
853 host_priv->exc_actions[i].port =
854 ipc_port_copy_send(new_port);
855 host_priv->exc_actions[i].behavior = new_behavior;
856 host_priv->exc_actions[i].flavor = new_flavor;
857 if (count > *CountCnt) {
858 break;
859 }
860 } else
861 old_port[i] = IP_NULL;
862 }/* for */
863 host_unlock(host_priv);
864
865 /*
866 * Consume send rights without any lock held.
867 */
868 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++)
869 if (IP_VALID(old_port[i]))
870 ipc_port_release_send(old_port[i]);
871 if (IP_VALID(new_port)) /* consume send right */
872 ipc_port_release_send(new_port);
873 *CountCnt = count;
874
875 return KERN_SUCCESS;
876 }