]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * HISTORY | |
27 | * | |
28 | * Revision 1.1.1.1 1998/09/22 21:05:34 wsanchez | |
29 | * Import of Mac OS X kernel (~semeria) | |
30 | * | |
31 | * Revision 1.2 1998/04/29 17:35:56 mburg | |
32 | * MK7.3 merger | |
33 | * | |
34 | * Revision 1.1.10.1 1998/02/03 09:28:28 gdt | |
35 | * Merge up to MK7.3 | |
36 | * [1998/02/03 09:13:40 gdt] | |
37 | * | |
38 | * Revision 1.1.8.1 1997/06/17 02:57:46 devrcs | |
39 | * Added `ipc_subsystem_terminate().' | |
40 | * [1997/03/18 18:25:52 rkc] | |
41 | * | |
42 | * Revision 1.1.5.1 1994/09/23 02:19:57 ezf | |
43 | * change marker to not FREE | |
44 | * [1994/09/22 21:33:39 ezf] | |
45 | * | |
46 | * Revision 1.1.3.1 1994/01/20 11:05:46 emcmanus | |
47 | * Copied for submission. | |
48 | * [1994/01/20 11:04:25 emcmanus] | |
49 | * | |
50 | * Revision 1.1.1.2 1994/01/13 02:40:32 condict | |
51 | * IPC support for the RPC subsytem object (server co-location). | |
52 | * | |
53 | * $EndLog$ | |
54 | */ | |
55 | ||
56 | /* | |
57 | * File: kern/ipc_subsystem.c | |
58 | * Purpose: Routines to support ipc semantics of new kernel | |
59 | * RPC subsystem descriptions | |
60 | */ | |
61 | ||
62 | #include <mach/message.h> | |
63 | #include <kern/ipc_kobject.h> | |
64 | #include <kern/task.h> | |
65 | #include <kern/ipc_subsystem.h> | |
66 | #include <kern/subsystem.h> | |
67 | #include <kern/misc_protos.h> | |
68 | #include <ipc/ipc_port.h> | |
69 | #include <ipc/ipc_space.h> | |
70 | ||
71 | /* | |
72 | * Routine: ipc_subsystem_init | |
73 | * Purpose: | |
74 | * Initialize ipc control of a subsystem. | |
75 | */ | |
76 | void | |
77 | ipc_subsystem_init( | |
78 | subsystem_t subsystem) | |
79 | { | |
80 | ipc_port_t port; | |
81 | ||
82 | port = ipc_port_alloc_kernel(); | |
83 | if (port == IP_NULL) | |
84 | panic("ipc_subsystem_init"); | |
85 | subsystem->ipc_self = port; | |
86 | } | |
87 | ||
88 | /* | |
89 | * Routine: ipc_subsystem_enable | |
90 | * Purpose: | |
91 | * Enable ipc access to a subsystem. | |
92 | */ | |
93 | void | |
94 | ipc_subsystem_enable( | |
95 | subsystem_t subsystem) | |
96 | { | |
97 | ipc_kobject_set(subsystem->ipc_self, | |
98 | (ipc_kobject_t) subsystem, IKOT_SUBSYSTEM); | |
99 | } | |
100 | ||
101 | ||
102 | /* | |
103 | * Routine: ipc_subsystem_disable | |
104 | * Purpose: | |
105 | * Disable IPC access to a subsystem. | |
106 | * Conditions: | |
107 | * Nothing locked. | |
108 | */ | |
109 | ||
110 | void | |
111 | ipc_subsystem_disable( | |
112 | subsystem_t subsystem) | |
113 | { | |
114 | ipc_port_t kport; | |
115 | ||
116 | kport = subsystem->ipc_self; | |
117 | if (kport != IP_NULL) | |
118 | ipc_kobject_set(kport, IKO_NULL, IKOT_NONE); | |
119 | } | |
120 | ||
121 | /* | |
122 | * Routine: ipc_subsystem_terminate | |
123 | * Purpose: | |
124 | * Clean up and destroy a subsystem's IPC state. | |
125 | */ | |
126 | void | |
127 | ipc_subsystem_terminate( | |
128 | subsystem_t subsystem) | |
129 | { | |
130 | ipc_port_dealloc_kernel(subsystem->ipc_self); | |
131 | } | |
132 | ||
133 | ||
134 | /* | |
135 | * Routine: convert_port_to_subsystem | |
136 | * Purpose: | |
137 | * Convert from a port to a subsystem. | |
138 | * Doesn't consume the port ref; produces a subsystem ref, | |
139 | * which may be null. | |
140 | * Conditions: | |
141 | * Nothing locked. | |
142 | */ | |
143 | subsystem_t | |
144 | convert_port_to_subsystem( | |
145 | ipc_port_t port) | |
146 | { | |
147 | subsystem_t subsystem = SUBSYSTEM_NULL; | |
148 | ||
149 | if (IP_VALID(port)) { | |
150 | ip_lock(port); | |
151 | if (ip_active(port) && | |
152 | (ip_kotype(port) == IKOT_SUBSYSTEM)) { | |
153 | subsystem = (subsystem_t) port->ip_kobject; | |
154 | } | |
155 | ip_unlock(port); | |
156 | } | |
157 | return (subsystem); | |
158 | } | |
159 | ||
160 | ||
161 | /* | |
162 | * Routine: convert_subsystem_to_port | |
163 | * Purpose: | |
164 | * Convert from a subsystem to a port. | |
165 | * Produces a naked send right which may be invalid. | |
166 | * Conditions: | |
167 | * Nothing locked. | |
168 | */ | |
169 | ipc_port_t | |
170 | convert_subsystem_to_port( | |
171 | subsystem_t subsystem) | |
172 | { | |
173 | ipc_port_t port; | |
174 | ||
175 | port = ipc_port_make_send(subsystem->ipc_self); | |
176 | return (port); | |
177 | } | |
178 |