]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | * | |
31 | */ | |
32 | ||
33 | #include <kern/sync_sema.h> | |
34 | #include <kern/sync_lock.h> | |
35 | #include <kern/ipc_kobject.h> | |
36 | #include <kern/ipc_sync.h> | |
37 | #include <ipc/port.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> | |
44 | ||
45 | ||
46 | kern_return_t | |
47 | port_name_to_semaphore( | |
48 | mach_port_name_t name, | |
49 | semaphore_t *semaphorep) | |
50 | { | |
51 | semaphore_t semaphore; | |
52 | ipc_port_t kern_port; | |
53 | kern_return_t kr; | |
54 | ||
55 | if (!MACH_PORT_VALID(name)) { | |
56 | *semaphorep = SEMAPHORE_NULL; | |
57 | return KERN_INVALID_NAME; | |
58 | } | |
59 | ||
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; | |
64 | return kr; | |
65 | } | |
66 | /* have the port locked */ | |
67 | assert(IP_VALID(kern_port)); | |
68 | ||
69 | if (!ip_active(kern_port) || (ip_kotype(kern_port) != IKOT_SEMAPHORE)) { | |
70 | ip_unlock(kern_port); | |
71 | *semaphorep = SEMAPHORE_NULL; | |
72 | return KERN_INVALID_ARGUMENT; | |
73 | } | |
74 | ||
75 | semaphore = (semaphore_t) kern_port->ip_kobject; | |
76 | assert(semaphore != SEMAPHORE_NULL); | |
77 | semaphore_reference(semaphore); | |
78 | ip_unlock(kern_port); | |
79 | ||
80 | *semaphorep = semaphore; | |
81 | return KERN_SUCCESS; | |
82 | } | |
83 | ||
84 | semaphore_t | |
85 | convert_port_to_semaphore (ipc_port_t port) | |
86 | { | |
87 | semaphore_t semaphore = SEMAPHORE_NULL; | |
88 | ||
89 | if (IP_VALID (port)) { | |
90 | ip_lock(port); | |
91 | if (ip_active(port) && (ip_kotype(port) == IKOT_SEMAPHORE)) { | |
92 | semaphore = (semaphore_t) port->ip_kobject; | |
93 | semaphore_reference(semaphore); | |
94 | } | |
95 | ip_unlock(port); | |
96 | } | |
97 | ||
98 | return (semaphore); | |
99 | } | |
100 | ||
101 | ||
102 | ipc_port_t | |
103 | convert_semaphore_to_port (semaphore_t semaphore) | |
104 | { | |
105 | ipc_port_t port; | |
106 | ||
107 | if (semaphore != SEMAPHORE_NULL) | |
108 | port = ipc_port_make_send(semaphore->port); | |
109 | else | |
110 | port = IP_NULL; | |
111 | ||
112 | return (port); | |
113 | } | |
114 | ||
115 | lock_set_t | |
116 | convert_port_to_lock_set (ipc_port_t port) | |
117 | { | |
118 | lock_set_t lock_set = LOCK_SET_NULL; | |
119 | ||
120 | if (IP_VALID (port)) { | |
121 | ip_lock(port); | |
122 | if (ip_active(port) && (ip_kotype(port) == IKOT_LOCK_SET)) { | |
123 | lock_set = (lock_set_t) port->ip_kobject; | |
124 | lock_set_reference(lock_set); | |
125 | } | |
126 | ip_unlock(port); | |
127 | } | |
128 | ||
129 | return (lock_set); | |
130 | } | |
131 | ||
132 | ipc_port_t | |
133 | convert_lock_set_to_port (lock_set_t lock_set) | |
134 | { | |
135 | ipc_port_t port; | |
136 | ||
137 | if (lock_set != LOCK_SET_NULL) | |
138 | port = ipc_port_make_send(lock_set->port); | |
139 | else | |
140 | port = IP_NULL; | |
141 | ||
142 | return (port); | |
143 | } | |
144 |