]>
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_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
30 #include <kern/sync_sema.h>
31 #include <kern/sync_lock.h>
32 #include <kern/ipc_kobject.h>
33 #include <kern/ipc_sync.h>
35 #include <ipc/ipc_space.h>
36 #include <ipc/ipc_port.h>
37 #include <mach/semaphore.h>
38 #include <mach/lock_set_server.h>
39 #include <mach/mach_port_server.h>
40 #include <mach/port.h>
44 port_name_to_semaphore(
45 mach_port_name_t name
,
46 semaphore_t
*semaphorep
)
48 semaphore_t semaphore
;
52 if (!MACH_PORT_VALID(name
)) {
53 *semaphorep
= SEMAPHORE_NULL
;
54 return KERN_INVALID_NAME
;
57 kr
= ipc_object_translate(current_space(), name
, MACH_PORT_RIGHT_SEND
,
58 (ipc_object_t
*) &kern_port
);
59 if (kr
!= KERN_SUCCESS
) {
60 *semaphorep
= SEMAPHORE_NULL
;
63 /* have the port locked */
64 assert(IP_VALID(kern_port
));
66 if (!ip_active(kern_port
) || (ip_kotype(kern_port
) != IKOT_SEMAPHORE
)) {
68 *semaphorep
= SEMAPHORE_NULL
;
69 return KERN_INVALID_ARGUMENT
;
72 semaphore
= (semaphore_t
) kern_port
->ip_kobject
;
73 assert(semaphore
!= SEMAPHORE_NULL
);
74 semaphore_reference(semaphore
);
77 *semaphorep
= semaphore
;
82 convert_port_to_semaphore (ipc_port_t port
)
84 semaphore_t semaphore
= SEMAPHORE_NULL
;
86 if (IP_VALID (port
)) {
88 if (ip_active(port
) && (ip_kotype(port
) == IKOT_SEMAPHORE
)) {
89 semaphore
= (semaphore_t
) port
->ip_kobject
;
90 semaphore_reference(semaphore
);
100 convert_semaphore_to_port (semaphore_t semaphore
)
104 if (semaphore
!= SEMAPHORE_NULL
)
105 port
= ipc_port_make_send(semaphore
->port
);
113 convert_port_to_lock_set (ipc_port_t port
)
115 lock_set_t lock_set
= LOCK_SET_NULL
;
117 if (IP_VALID (port
)) {
119 if (ip_active(port
) && (ip_kotype(port
) == IKOT_LOCK_SET
)) {
120 lock_set
= (lock_set_t
) port
->ip_kobject
;
121 lock_set_reference(lock_set
);
130 convert_lock_set_to_port (lock_set_t lock_set
)
134 if (lock_set
!= LOCK_SET_NULL
)
135 port
= ipc_port_make_send(lock_set
->port
);