]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/ipc_sync.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
33 #include <kern/sync_sema.h>
34 #include <kern/sync_lock.h>
35 #include <kern/ipc_kobject.h>
36 #include <kern/ipc_sync.h>
38 #include <ipc/ipc_space.h>
39 #include <ipc/ipc_port.h>
40 #include <mach/semaphore.h>
41 #include <mach/lock_set_server.h>
42 #include <mach/mach_port_server.h>
43 #include <mach/port.h>
47 port_name_to_semaphore(
48 mach_port_name_t name
,
49 semaphore_t
*semaphorep
)
51 semaphore_t semaphore
;
55 if (!MACH_PORT_VALID(name
)) {
56 *semaphorep
= SEMAPHORE_NULL
;
57 return KERN_INVALID_NAME
;
60 kr
= ipc_object_translate(current_space(), name
, MACH_PORT_RIGHT_SEND
,
61 (ipc_object_t
*) &kern_port
);
62 if (kr
!= KERN_SUCCESS
) {
63 *semaphorep
= SEMAPHORE_NULL
;
66 /* have the port locked */
67 assert(IP_VALID(kern_port
));
69 if (!ip_active(kern_port
) || (ip_kotype(kern_port
) != IKOT_SEMAPHORE
)) {
71 *semaphorep
= SEMAPHORE_NULL
;
72 return KERN_INVALID_ARGUMENT
;
75 semaphore
= (semaphore_t
) kern_port
->ip_kobject
;
76 assert(semaphore
!= SEMAPHORE_NULL
);
77 semaphore_reference(semaphore
);
80 *semaphorep
= semaphore
;
85 convert_port_to_semaphore (ipc_port_t port
)
87 semaphore_t semaphore
= SEMAPHORE_NULL
;
89 if (IP_VALID (port
)) {
91 if (ip_active(port
) && (ip_kotype(port
) == IKOT_SEMAPHORE
)) {
92 semaphore
= (semaphore_t
) port
->ip_kobject
;
93 semaphore_reference(semaphore
);
103 convert_semaphore_to_port (semaphore_t semaphore
)
107 if (semaphore
== SEMAPHORE_NULL
)
110 /* caller is donating a reference */
111 port
= ipc_port_make_send(semaphore
->port
);
112 semaphore_dereference(semaphore
);
117 convert_port_to_lock_set (ipc_port_t port
)
119 lock_set_t lock_set
= LOCK_SET_NULL
;
121 if (IP_VALID (port
)) {
123 if (ip_active(port
) && (ip_kotype(port
) == IKOT_LOCK_SET
)) {
124 lock_set
= (lock_set_t
) port
->ip_kobject
;
125 lock_set_reference(lock_set
);
134 convert_lock_set_to_port (lock_set_t lock_set
)
138 if (lock_set
== LOCK_SET_NULL
)
141 /* caller is donating a reference */
142 port
= ipc_port_make_send(lock_set
->port
);
143 lock_set_dereference(lock_set
);