]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
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. | |
1c79356b | 11 | * |
37839358 A |
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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | * | |
25 | */ | |
26 | ||
27 | #include <kern/sync_sema.h> | |
28 | #include <kern/sync_lock.h> | |
29 | #include <kern/ipc_kobject.h> | |
30 | #include <kern/ipc_sync.h> | |
31 | #include <ipc/port.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> | |
38 | ||
39 | ||
40 | kern_return_t | |
41 | port_name_to_semaphore( | |
42 | mach_port_name_t name, | |
43 | semaphore_t *semaphorep) | |
44 | { | |
45 | semaphore_t semaphore; | |
46 | ipc_port_t kern_port; | |
47 | kern_return_t kr; | |
48 | ||
49 | if (!MACH_PORT_VALID(name)) { | |
50 | *semaphorep = SEMAPHORE_NULL; | |
51 | return KERN_INVALID_NAME; | |
52 | } | |
53 | ||
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; | |
58 | return kr; | |
59 | } | |
60 | /* have the port locked */ | |
61 | assert(IP_VALID(kern_port)); | |
62 | ||
63 | if (!ip_active(kern_port) || (ip_kotype(kern_port) != IKOT_SEMAPHORE)) { | |
64 | ip_unlock(kern_port); | |
65 | *semaphorep = SEMAPHORE_NULL; | |
66 | return KERN_INVALID_ARGUMENT; | |
67 | } | |
68 | ||
69 | semaphore = (semaphore_t) kern_port->ip_kobject; | |
70 | assert(semaphore != SEMAPHORE_NULL); | |
71 | semaphore_reference(semaphore); | |
72 | ip_unlock(kern_port); | |
73 | ||
74 | *semaphorep = semaphore; | |
75 | return KERN_SUCCESS; | |
76 | } | |
77 | ||
78 | semaphore_t | |
79 | convert_port_to_semaphore (ipc_port_t port) | |
80 | { | |
81 | semaphore_t semaphore = SEMAPHORE_NULL; | |
82 | ||
83 | if (IP_VALID (port)) { | |
84 | ip_lock(port); | |
85 | if (ip_active(port) && (ip_kotype(port) == IKOT_SEMAPHORE)) { | |
86 | semaphore = (semaphore_t) port->ip_kobject; | |
87 | semaphore_reference(semaphore); | |
88 | } | |
89 | ip_unlock(port); | |
90 | } | |
91 | ||
92 | return (semaphore); | |
93 | } | |
94 | ||
95 | ||
96 | ipc_port_t | |
97 | convert_semaphore_to_port (semaphore_t semaphore) | |
98 | { | |
99 | ipc_port_t port; | |
100 | ||
101 | if (semaphore != SEMAPHORE_NULL) | |
102 | port = ipc_port_make_send(semaphore->port); | |
103 | else | |
104 | port = IP_NULL; | |
105 | ||
106 | return (port); | |
107 | } | |
108 | ||
109 | lock_set_t | |
110 | convert_port_to_lock_set (ipc_port_t port) | |
111 | { | |
112 | lock_set_t lock_set = LOCK_SET_NULL; | |
113 | ||
114 | if (IP_VALID (port)) { | |
115 | ip_lock(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); | |
119 | } | |
120 | ip_unlock(port); | |
121 | } | |
122 | ||
123 | return (lock_set); | |
124 | } | |
125 | ||
126 | ipc_port_t | |
127 | convert_lock_set_to_port (lock_set_t lock_set) | |
128 | { | |
129 | ipc_port_t port; | |
130 | ||
131 | if (lock_set != LOCK_SET_NULL) | |
132 | port = ipc_port_make_send(lock_set->port); | |
133 | else | |
134 | port = IP_NULL; | |
135 | ||
136 | return (port); | |
137 | } | |
138 |