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