]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ipc_host.c
xnu-517.tar.gz
[apple/xnu.git] / osfmk / kern / ipc_host.c
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53 /*
54 */
55
56 /*
57 * kern/ipc_host.c
58 *
59 * Routines to implement host ports.
60 */
61 #include <mach/message.h>
62 #include <mach/mach_traps.h>
63 #include <mach/etap_events.h>
64 #include <mach/mach_host_server.h>
65 #include <kern/host.h>
66 #include <kern/processor.h>
67 #include <kern/lock.h>
68 #include <kern/task.h>
69 #include <kern/thread.h>
70 #include <kern/ipc_host.h>
71 #include <kern/ipc_kobject.h>
72 #include <kern/misc_protos.h>
73 #include <kern/spl.h>
74 #include <ipc/ipc_port.h>
75 #include <ipc/ipc_space.h>
76
77 /*
78 * Forward declarations
79 */
80
81 void
82 ipc_processor_terminate(
83 processor_t processor);
84
85 void
86 ipc_processor_disable(
87 processor_t processor);
88
89 boolean_t
90 ref_pset_port_locked(
91 ipc_port_t port, boolean_t matchn, processor_set_t *ppset);
92
93 /*
94 * ipc_host_init: set up various things.
95 */
96
97 void ipc_host_init(void)
98 {
99 ipc_port_t port;
100 int i;
101
102 mutex_init(&realhost.lock, ETAP_MISC_MASTER);
103
104 /*
105 * Allocate and set up the two host ports.
106 */
107 port = ipc_port_alloc_kernel();
108 if (port == IP_NULL)
109 panic("ipc_host_init");
110
111 ipc_kobject_set(port, (ipc_kobject_t) &realhost, IKOT_HOST_SECURITY);
112 kernel_set_special_port(&realhost, HOST_SECURITY_PORT,
113 ipc_port_make_send(port));
114
115 port = ipc_port_alloc_kernel();
116 if (port == IP_NULL)
117 panic("ipc_host_init");
118
119 ipc_kobject_set(port, (ipc_kobject_t) &realhost, IKOT_HOST);
120 kernel_set_special_port(&realhost, HOST_PORT,
121 ipc_port_make_send(port));
122
123 port = ipc_port_alloc_kernel();
124 if (port == IP_NULL)
125 panic("ipc_host_init");
126
127 ipc_kobject_set(port, (ipc_kobject_t) &realhost, IKOT_HOST_PRIV);
128 kernel_set_special_port(&realhost, HOST_PRIV_PORT,
129 ipc_port_make_send(port));
130
131 /* the rest of the special ports will be set up later */
132
133 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
134 realhost.exc_actions[i].port = IP_NULL;
135 }/* for */
136
137 /*
138 * Set up ipc for default processor set.
139 */
140 ipc_pset_init(&default_pset);
141 ipc_pset_enable(&default_pset);
142
143 /*
144 * And for master processor
145 */
146 ipc_processor_init(master_processor);
147 ipc_processor_enable(master_processor);
148 }
149
150 /*
151 * Routine: host_self_trap [mach trap]
152 * Purpose:
153 * Give the caller send rights for his own host port.
154 * Conditions:
155 * Nothing locked.
156 * Returns:
157 * MACH_PORT_NULL if there are any resource failures
158 * or other errors.
159 */
160
161 mach_port_name_t
162 host_self_trap(void)
163 {
164 ipc_port_t sright;
165
166 sright = ipc_port_copy_send(current_task()->itk_host);
167 return ipc_port_copyout_send(sright, current_space());
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 register int i,
730 j,
731 count;
732
733 if (host_priv == HOST_PRIV_NULL)
734 return KERN_INVALID_ARGUMENT;
735
736 if (exception_mask & ~EXC_MASK_ALL) {
737 return KERN_INVALID_ARGUMENT;
738 }
739
740 assert (host_priv == &realhost);
741
742 host_lock(host_priv);
743
744 count = 0;
745
746 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
747 if (exception_mask & (1 << i)) {
748 for (j = 0; j < count; j++) {
749 /*
750 * search for an identical entry, if found
751 * set corresponding mask for this exception.
752 */
753 if (host_priv->exc_actions[i].port == ports[j] &&
754 host_priv->exc_actions[i].behavior == behaviors[j]
755 && host_priv->exc_actions[i].flavor == flavors[j])
756 {
757 masks[j] |= (1 << i);
758 break;
759 }
760 }/* for */
761 if (j == count) {
762 masks[j] = (1 << i);
763 ports[j] =
764 ipc_port_copy_send(host_priv->exc_actions[i].port);
765 behaviors[j] = host_priv->exc_actions[i].behavior;
766 flavors[j] = host_priv->exc_actions[i].flavor;
767 count++;
768 if (count > *CountCnt) {
769 break;
770 }
771 }
772 }
773 }/* for */
774 host_unlock(host_priv);
775
776 *CountCnt = count;
777 return KERN_SUCCESS;
778 }
779
780 kern_return_t
781 host_swap_exception_ports(
782 host_priv_t host_priv,
783 exception_mask_t exception_mask,
784 ipc_port_t new_port,
785 exception_behavior_t new_behavior,
786 thread_state_flavor_t new_flavor,
787 exception_mask_array_t masks,
788 mach_msg_type_number_t * CountCnt,
789 exception_port_array_t ports,
790 exception_behavior_array_t behaviors,
791 thread_state_flavor_array_t flavors )
792 {
793 register int i,
794 j,
795 count;
796 ipc_port_t old_port[EXC_TYPES_COUNT];
797
798 if (host_priv == HOST_PRIV_NULL)
799 return KERN_INVALID_ARGUMENT;
800
801 if (exception_mask & ~EXC_MASK_ALL) {
802 return KERN_INVALID_ARGUMENT;
803 }
804
805 if (IP_VALID(new_port)) {
806 switch (new_behavior) {
807 case EXCEPTION_DEFAULT:
808 case EXCEPTION_STATE:
809 case EXCEPTION_STATE_IDENTITY:
810 break;
811 default:
812 return KERN_INVALID_ARGUMENT;
813 }
814 }
815 /* Cannot easily check "new_flavor", but that just means that
816 * the flavor in the generated exception message might be garbage:
817 * GIGO */
818
819 host_lock(host_priv);
820
821 count = 0;
822
823 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++) {
824 if (exception_mask & (1 << i)) {
825 for (j = 0; j < count; j++) {
826 /*
827 * search for an identical entry, if found
828 * set corresponding mask for this exception.
829 */
830 if (host_priv->exc_actions[i].port == ports[j] &&
831 host_priv->exc_actions[i].behavior == behaviors[j]
832 && host_priv->exc_actions[i].flavor == flavors[j])
833 {
834 masks[j] |= (1 << i);
835 break;
836 }
837 }/* for */
838 if (j == count) {
839 masks[j] = (1 << i);
840 ports[j] =
841 ipc_port_copy_send(host_priv->exc_actions[i].port);
842 behaviors[j] = host_priv->exc_actions[i].behavior;
843 flavors[j] = host_priv->exc_actions[i].flavor;
844 count++;
845 }
846 old_port[i] = host_priv->exc_actions[i].port;
847 host_priv->exc_actions[i].port =
848 ipc_port_copy_send(new_port);
849 host_priv->exc_actions[i].behavior = new_behavior;
850 host_priv->exc_actions[i].flavor = new_flavor;
851 if (count > *CountCnt) {
852 break;
853 }
854 } else
855 old_port[i] = IP_NULL;
856 }/* for */
857 host_unlock(host_priv);
858
859 /*
860 * Consume send rights without any lock held.
861 */
862 for (i = FIRST_EXCEPTION; i < EXC_TYPES_COUNT; i++)
863 if (IP_VALID(old_port[i]))
864 ipc_port_release_send(old_port[i]);
865 if (IP_VALID(new_port)) /* consume send right */
866 ipc_port_release_send(new_port);
867 *CountCnt = count;
868
869 return KERN_SUCCESS;
870 }