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