]>
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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
27 #include <kern/sync_sema.h>
28 #include <kern/sync_lock.h>
29 #include <kern/ipc_kobject.h>
30 #include <kern/ipc_sync.h>
32 #include <ipc/ipc_space.h>
33 #include <ipc/ipc_port.h>
34 #include <mach/semaphore.h>
35 #include <mach/lock_set_server.h>
36 #include <mach/mach_port_server.h>
37 #include <mach/port.h>
41 port_name_to_semaphore(
42 mach_port_name_t name
,
43 semaphore_t
*semaphorep
)
45 semaphore_t semaphore
;
49 if (!MACH_PORT_VALID(name
)) {
50 *semaphorep
= SEMAPHORE_NULL
;
51 return KERN_INVALID_NAME
;
54 kr
= ipc_object_translate(current_space(), name
, MACH_PORT_RIGHT_SEND
,
55 (ipc_object_t
*) &kern_port
);
56 if (kr
!= KERN_SUCCESS
) {
57 *semaphorep
= SEMAPHORE_NULL
;
60 /* have the port locked */
61 assert(IP_VALID(kern_port
));
63 if (!ip_active(kern_port
) || (ip_kotype(kern_port
) != IKOT_SEMAPHORE
)) {
65 *semaphorep
= SEMAPHORE_NULL
;
66 return KERN_INVALID_ARGUMENT
;
69 semaphore
= (semaphore_t
) kern_port
->ip_kobject
;
70 assert(semaphore
!= SEMAPHORE_NULL
);
71 semaphore_reference(semaphore
);
74 *semaphorep
= semaphore
;
79 convert_port_to_semaphore (ipc_port_t port
)
81 semaphore_t semaphore
= SEMAPHORE_NULL
;
83 if (IP_VALID (port
)) {
85 if (ip_active(port
) && (ip_kotype(port
) == IKOT_SEMAPHORE
)) {
86 semaphore
= (semaphore_t
) port
->ip_kobject
;
87 semaphore_reference(semaphore
);
97 convert_semaphore_to_port (semaphore_t semaphore
)
101 if (semaphore
!= SEMAPHORE_NULL
)
102 port
= ipc_port_make_send(semaphore
->port
);
110 convert_port_to_lock_set (ipc_port_t port
)
112 lock_set_t lock_set
= LOCK_SET_NULL
;
114 if (IP_VALID (port
)) {
116 if (ip_active(port
) && (ip_kotype(port
) == IKOT_LOCK_SET
)) {
117 lock_set
= (lock_set_t
) port
->ip_kobject
;
118 lock_set_reference(lock_set
);
127 convert_lock_set_to_port (lock_set_t lock_set
)
131 if (lock_set
!= LOCK_SET_NULL
)
132 port
= ipc_port_make_send(lock_set
->port
);