]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 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. | |
0a7de745 | 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. | |
0a7de745 | 17 | * |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | ||
32 | /* | |
33 | * Mach MIG Subsystem Interfaces | |
34 | */ | |
35 | ||
0a7de745 | 36 | #ifndef _MACH_MIG_H_ |
1c79356b A |
37 | #define _MACH_MIG_H_ |
38 | ||
9bccf70c | 39 | #include <stdint.h> |
1c79356b A |
40 | #include <mach/port.h> |
41 | #include <mach/message.h> | |
9bccf70c | 42 | #include <mach/vm_types.h> |
1c79356b | 43 | |
91447636 A |
44 | #include <sys/cdefs.h> |
45 | ||
46 | #if defined(MACH_KERNEL) | |
47 | ||
316670eb | 48 | #if !defined(__MigTypeCheck) |
91447636 A |
49 | /* Turn MIG type checking on by default for kernel */ |
50 | #define __MigTypeCheck 1 | |
2d21ac55 | 51 | #endif |
316670eb | 52 | |
91447636 A |
53 | #define __MigKernelSpecificCode 1 |
54 | #define _MIG_KERNEL_SPECIFIC_CODE_ 1 | |
55 | ||
2d21ac55 A |
56 | #elif !defined(__MigTypeCheck) |
57 | ||
316670eb A |
58 | #if defined(TypeCheck) |
59 | /* use legacy setting (temporary) */ | |
60 | #define __MigTypeCheck TypeCheck | |
2d21ac55 | 61 | #else |
316670eb | 62 | /* default MIG type checking on */ |
2d21ac55 A |
63 | #define __MigTypeCheck 1 |
64 | #endif | |
65 | ||
316670eb | 66 | #endif /* !defined(MACH_KERNEL) && !defined(__MigTypeCheck) */ |
91447636 A |
67 | |
68 | /* | |
0c530ab8 | 69 | * Pack MIG message structs. |
91447636 A |
70 | * This is an indicator of the need to view shared structs in a |
71 | * binary-compatible format - and MIG message structs are no different. | |
72 | */ | |
91447636 | 73 | #define __MigPackStructs 1 |
91447636 | 74 | |
1c79356b A |
75 | /* |
76 | * Definition for MIG-generated server stub routines. These routines | |
77 | * unpack the request message, call the server procedure, and pack the | |
78 | * reply message. | |
79 | */ | |
0a7de745 A |
80 | typedef void (*mig_stub_routine_t) (mach_msg_header_t *InHeadP, |
81 | mach_msg_header_t *OutHeadP); | |
1c79356b A |
82 | |
83 | typedef mig_stub_routine_t mig_routine_t; | |
84 | ||
85 | /* | |
0b4e3aa0 A |
86 | * Definition for MIG-generated server routine. This routine takes a |
87 | * message, and returns the appropriate stub function for handling that | |
88 | * message. | |
89 | */ | |
90 | typedef mig_routine_t (*mig_server_routine_t) (mach_msg_header_t *InHeadP); | |
91 | ||
92 | /* | |
93 | * Generic definition for implementation routines. These routines do | |
94 | * the real work associated with this request. This generic type is | |
95 | * used for keeping the pointers in the subsystem array. | |
1c79356b A |
96 | */ |
97 | typedef kern_return_t (*mig_impl_routine_t)(void); | |
98 | ||
9bccf70c A |
99 | typedef mach_msg_type_descriptor_t routine_arg_descriptor; |
100 | typedef mach_msg_type_descriptor_t *routine_arg_descriptor_t; | |
101 | typedef mach_msg_type_descriptor_t *mig_routine_arg_descriptor_t; | |
102 | ||
103 | #define MIG_ROUTINE_ARG_DESCRIPTOR_NULL ((mig_routine_arg_descriptor_t)0) | |
104 | ||
105 | struct routine_descriptor { | |
0a7de745 A |
106 | mig_impl_routine_t impl_routine; /* Server work func pointer */ |
107 | mig_stub_routine_t stub_routine; /* Unmarshalling func pointer */ | |
108 | unsigned int argc; /* Number of argument words */ | |
109 | unsigned int descr_count; /* Number complex descriptors */ | |
9bccf70c | 110 | routine_arg_descriptor_t |
0a7de745 A |
111 | arg_descr; /* pointer to descriptor array*/ |
112 | unsigned int max_reply_msg; /* Max size for reply msg */ | |
9bccf70c A |
113 | }; |
114 | typedef struct routine_descriptor *routine_descriptor_t; | |
115 | ||
116 | typedef struct routine_descriptor mig_routine_descriptor; | |
117 | typedef mig_routine_descriptor *mig_routine_descriptor_t; | |
118 | ||
119 | #define MIG_ROUTINE_DESCRIPTOR_NULL ((mig_routine_descriptor_t)0) | |
0b4e3aa0 A |
120 | |
121 | typedef struct mig_subsystem { | |
0a7de745 A |
122 | mig_server_routine_t server; /* pointer to demux routine */ |
123 | mach_msg_id_t start; /* Min routine number */ | |
124 | mach_msg_id_t end; /* Max routine number + 1 */ | |
125 | mach_msg_size_t maxsize; /* Max reply message size */ | |
126 | vm_address_t reserved; /* reserved for MIG use */ | |
9bccf70c | 127 | mig_routine_descriptor |
0a7de745 | 128 | routine[1]; /* Routine descriptor array */ |
0b4e3aa0 A |
129 | } *mig_subsystem_t; |
130 | ||
0a7de745 | 131 | #define MIG_SUBSYSTEM_NULL ((mig_subsystem_t)0) |
9bccf70c A |
132 | |
133 | typedef struct mig_symtab { | |
0a7de745 A |
134 | char *ms_routine_name; |
135 | int ms_routine_number; | |
136 | void (*ms_routine)(void); /* Since the functions in the | |
137 | * symbol table have unknown | |
138 | * signatures, this is the best | |
139 | * we can do... | |
140 | */ | |
9bccf70c A |
141 | } mig_symtab_t; |
142 | ||
cb323159 A |
143 | /* |
144 | * A compiler attribute for annotating all MIG server routines and other | |
145 | * functions that should behave similarly. Allows the compiler to perform | |
146 | * additional static bug-finding over them. | |
147 | */ | |
148 | #if __has_attribute(mig_server_routine) | |
149 | #define MIG_SERVER_ROUTINE __attribute__((mig_server_routine)) | |
150 | #else | |
151 | #define MIG_SERVER_ROUTINE | |
152 | #endif | |
153 | ||
0a7de745 | 154 | #ifdef PRIVATE |
9bccf70c | 155 | |
91447636 | 156 | /* MIG object runtime - not ready for public consumption */ |
9bccf70c | 157 | |
91447636 | 158 | #ifdef KERNEL_PRIVATE |
9bccf70c | 159 | |
0b4e3aa0 A |
160 | /* |
161 | * MIG object runtime definitions | |
162 | * | |
163 | * Conforming MIG subsystems may enable this support to get | |
164 | * significant assistance from the base mig_object_t implementation. | |
165 | * | |
166 | * Support includes: | |
167 | * - Transparency from port manipulation. | |
168 | * - Dymanic port allocation on first "remoting" of an object. | |
169 | * - Reference conversions from object to port and vice versa. | |
170 | * - Automatic port deallocation on no-more-senders. | |
171 | * - Support for multiple server implementations in a single space. | |
172 | * - Messaging bypass for local servers. | |
173 | * - Automatic hookup to base dispatch mechanism. | |
174 | * - General notification support | |
175 | * Coming soon: | |
176 | * - User-level support | |
177 | */ | |
0a7de745 | 178 | typedef unsigned int mig_notify_type_t; |
0b4e3aa0 A |
179 | |
180 | typedef struct MIGIID { | |
0a7de745 A |
181 | unsigned long data1; |
182 | unsigned short data2; | |
183 | unsigned short data3; | |
184 | unsigned char data4[8]; | |
0b4e3aa0 A |
185 | } MIGIID; |
186 | ||
0a7de745 A |
187 | typedef struct IMIGObjectVtbl IMIGObjectVtbl; |
188 | typedef struct IMIGNotifyObjectVtbl IMIGNotifyObjectVtbl; | |
0b4e3aa0 A |
189 | |
190 | typedef struct IMIGObject { | |
0a7de745 | 191 | const IMIGObjectVtbl *pVtbl; |
0b4e3aa0 A |
192 | } IMIGObject; |
193 | ||
194 | typedef struct IMIGNotifyObject { | |
0a7de745 | 195 | const IMIGNotifyObjectVtbl *pVtbl; |
0b4e3aa0 A |
196 | } IMIGNotifyObject; |
197 | ||
198 | struct IMIGObjectVtbl { | |
199 | kern_return_t (*QueryInterface)( | |
0a7de745 A |
200 | IMIGObject *object, |
201 | const MIGIID *iid, | |
202 | void **ppv); | |
0b4e3aa0 A |
203 | |
204 | unsigned long (*AddRef)( | |
0a7de745 | 205 | IMIGObject *object); |
0b4e3aa0 | 206 | |
0a7de745 A |
207 | unsigned long (*Release)( |
208 | IMIGObject *object); | |
0b4e3aa0 A |
209 | |
210 | unsigned long (*GetServer)( | |
0a7de745 A |
211 | IMIGObject *object, |
212 | mig_server_routine_t *server); | |
213 | ||
0b4e3aa0 | 214 | boolean_t (*RaiseNotification)( |
0a7de745 A |
215 | IMIGObject *object, |
216 | mig_notify_type_t notify_type); | |
0b4e3aa0 A |
217 | |
218 | boolean_t (*RequestNotification)( | |
0a7de745 A |
219 | IMIGObject *object, |
220 | IMIGNotifyObject *notify, | |
221 | mig_notify_type_t notify_type); | |
222 | }; | |
0b4e3aa0 A |
223 | |
224 | /* | |
225 | * IMIGNotifyObject | |
226 | * | |
227 | * A variant of the IMIGObject interface that is a sink for | |
228 | * MIG notifications. | |
229 | * | |
230 | * A reference is held on both the subject MIGObject and the target | |
231 | * MIGNotifyObject. Because of this, care must be exercised to avoid | |
232 | * reference cycles. Once a notification is raised, the object | |
233 | * reference is returned and the request must be re-requested (if | |
234 | * desired). | |
235 | * | |
236 | * One interesting note: because this interface is itself a MIG | |
237 | * object, one may request notification about state changes in | |
238 | * the MIGNotifyObject itself. | |
239 | */ | |
240 | struct IMIGNotifyObjectVtbl { | |
241 | kern_return_t (*QueryInterface)( | |
0a7de745 A |
242 | IMIGNotifyObject *notify, |
243 | const MIGIID *iid, | |
244 | void **ppv); | |
0b4e3aa0 | 245 | |
0a7de745 A |
246 | unsigned long (*AddRef)( |
247 | IMIGNotifyObject *notify); | |
0b4e3aa0 | 248 | |
0a7de745 A |
249 | unsigned long (*Release)( |
250 | IMIGNotifyObject *notify); | |
0b4e3aa0 A |
251 | |
252 | unsigned long (*GetServer)( | |
0a7de745 A |
253 | IMIGNotifyObject *notify, |
254 | mig_server_routine_t *server); | |
0b4e3aa0 A |
255 | |
256 | boolean_t (*RaiseNotification)( | |
0a7de745 A |
257 | IMIGNotifyObject *notify, |
258 | mig_notify_type_t notify_type); | |
0b4e3aa0 A |
259 | |
260 | boolean_t (*RequestNotification)( | |
0a7de745 A |
261 | IMIGNotifyObject *notify, |
262 | IMIGNotifyObject *notify_notify, | |
263 | mig_notify_type_t notify_type); | |
0b4e3aa0 A |
264 | |
265 | void (*HandleNotification)( | |
0a7de745 A |
266 | IMIGNotifyObject *notify, |
267 | IMIGObject *object, | |
268 | mig_notify_type_t notify_type); | |
0b4e3aa0 A |
269 | }; |
270 | ||
0a7de745 | 271 | #endif /* KERNEL_PRIVATE */ |
91447636 A |
272 | #endif /* PRIVATE */ |
273 | ||
274 | __BEGIN_DECLS | |
275 | ||
276 | /* Client side reply port allocate */ | |
277 | extern mach_port_t mig_get_reply_port(void); | |
278 | ||
279 | /* Client side reply port deallocate */ | |
280 | extern void mig_dealloc_reply_port(mach_port_t reply_port); | |
281 | ||
282 | /* Client side reply port "deallocation" */ | |
283 | extern void mig_put_reply_port(mach_port_t reply_port); | |
284 | ||
285 | /* Bounded string copy */ | |
0a7de745 A |
286 | extern int mig_strncpy(char *dest, const char *src, int len); |
287 | extern int mig_strncpy_zerofill(char *dest, const char *src, int len); | |
91447636 A |
288 | |
289 | #ifdef KERNEL_PRIVATE | |
290 | ||
291 | /* Allocate memory for out-of-stack mig structures */ | |
5ba3f43e | 292 | extern void *mig_user_allocate(vm_size_t size); |
91447636 A |
293 | |
294 | /* Deallocate memory used for out-of-stack mig structures */ | |
295 | extern void mig_user_deallocate(char *data, vm_size_t size); | |
296 | ||
297 | #else | |
298 | ||
299 | /* Allocate memory for out-of-line mig structures */ | |
300 | extern void mig_allocate(vm_address_t *, vm_size_t); | |
301 | ||
302 | /* Deallocate memory used for out-of-line mig structures */ | |
303 | extern void mig_deallocate(vm_address_t, vm_size_t); | |
9bccf70c | 304 | |
0b4e3aa0 | 305 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 306 | |
91447636 A |
307 | __END_DECLS |
308 | ||
0a7de745 | 309 | #endif /* _MACH_MIG_H_ */ |