]>
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_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
35 #include <kern/sync_sema.h>
36 #include <kern/sync_lock.h>
37 #include <kern/ipc_kobject.h>
38 #include <kern/ipc_sync.h>
40 #include <ipc/ipc_space.h>
41 #include <ipc/ipc_port.h>
42 #include <mach/semaphore.h>
43 #include <mach/lock_set_server.h>
44 #include <mach/mach_port_server.h>
45 #include <mach/port.h>
49 port_name_to_semaphore(
50 mach_port_name_t name
,
51 semaphore_t
*semaphorep
)
53 semaphore_t semaphore
;
57 if (!MACH_PORT_VALID(name
)) {
58 *semaphorep
= SEMAPHORE_NULL
;
59 return KERN_INVALID_NAME
;
62 kr
= ipc_object_translate(current_space(), name
, MACH_PORT_RIGHT_SEND
,
63 (ipc_object_t
*) &kern_port
);
64 if (kr
!= KERN_SUCCESS
) {
65 *semaphorep
= SEMAPHORE_NULL
;
68 /* have the port locked */
69 assert(IP_VALID(kern_port
));
71 if (!ip_active(kern_port
) || (ip_kotype(kern_port
) != IKOT_SEMAPHORE
)) {
73 *semaphorep
= SEMAPHORE_NULL
;
74 return KERN_INVALID_ARGUMENT
;
77 semaphore
= (semaphore_t
) kern_port
->ip_kobject
;
78 assert(semaphore
!= SEMAPHORE_NULL
);
79 semaphore_reference(semaphore
);
82 *semaphorep
= semaphore
;
87 convert_port_to_semaphore (ipc_port_t port
)
89 semaphore_t semaphore
= SEMAPHORE_NULL
;
91 if (IP_VALID (port
)) {
93 if (ip_active(port
) && (ip_kotype(port
) == IKOT_SEMAPHORE
)) {
94 semaphore
= (semaphore_t
) port
->ip_kobject
;
95 semaphore_reference(semaphore
);
105 convert_semaphore_to_port (semaphore_t semaphore
)
109 if (semaphore
!= SEMAPHORE_NULL
)
110 port
= ipc_port_make_send(semaphore
->port
);
118 convert_port_to_lock_set (ipc_port_t port
)
120 lock_set_t lock_set
= LOCK_SET_NULL
;
122 if (IP_VALID (port
)) {
124 if (ip_active(port
) && (ip_kotype(port
) == IKOT_LOCK_SET
)) {
125 lock_set
= (lock_set_t
) port
->ip_kobject
;
126 lock_set_reference(lock_set
);
135 convert_lock_set_to_port (lock_set_t lock_set
)
139 if (lock_set
!= LOCK_SET_NULL
)
140 port
= ipc_port_make_send(lock_set
->port
);