]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/mig.h
xnu-344.21.73.tar.gz
[apple/xnu.git] / osfmk / mach / mig.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28
29 /*
30 * Mach MIG Subsystem Interfaces
31 */
32
33 #ifndef _MACH_MIG_H_
34 #define _MACH_MIG_H_
35
36 #include <stdint.h>
37 #include <mach/port.h>
38 #include <mach/message.h>
39 #include <mach/vm_types.h>
40
41 /*
42 * Definition for MIG-generated server stub routines. These routines
43 * unpack the request message, call the server procedure, and pack the
44 * reply message.
45 */
46 typedef void (*mig_stub_routine_t) (mach_msg_header_t *InHeadP,
47 mach_msg_header_t *OutHeadP);
48
49 typedef mig_stub_routine_t mig_routine_t;
50
51 /*
52 * Definition for MIG-generated server routine. This routine takes a
53 * message, and returns the appropriate stub function for handling that
54 * message.
55 */
56 typedef mig_routine_t (*mig_server_routine_t) (mach_msg_header_t *InHeadP);
57
58 /*
59 * Generic definition for implementation routines. These routines do
60 * the real work associated with this request. This generic type is
61 * used for keeping the pointers in the subsystem array.
62 */
63 typedef kern_return_t (*mig_impl_routine_t)(void);
64
65 typedef mach_msg_type_descriptor_t routine_arg_descriptor;
66 typedef mach_msg_type_descriptor_t *routine_arg_descriptor_t;
67 typedef mach_msg_type_descriptor_t *mig_routine_arg_descriptor_t;
68
69 #define MIG_ROUTINE_ARG_DESCRIPTOR_NULL ((mig_routine_arg_descriptor_t)0)
70
71 struct routine_descriptor {
72 mig_impl_routine_t impl_routine; /* Server work func pointer */
73 mig_stub_routine_t stub_routine; /* Unmarshalling func pointer */
74 unsigned int argc; /* Number of argument words */
75 unsigned int descr_count; /* Number complex descriptors */
76 routine_arg_descriptor_t
77 arg_descr; /* pointer to descriptor array*/
78 unsigned int max_reply_msg; /* Max size for reply msg */
79 };
80 typedef struct routine_descriptor *routine_descriptor_t;
81
82 typedef struct routine_descriptor mig_routine_descriptor;
83 typedef mig_routine_descriptor *mig_routine_descriptor_t;
84
85 #define MIG_ROUTINE_DESCRIPTOR_NULL ((mig_routine_descriptor_t)0)
86
87 typedef struct mig_subsystem {
88 mig_server_routine_t server; /* pointer to demux routine */
89 mach_msg_id_t start; /* Min routine number */
90 mach_msg_id_t end; /* Max routine number + 1 */
91 mach_msg_size_t maxsize; /* Max reply message size */
92 vm_address_t reserved; /* reserved for MIG use */
93 mig_routine_descriptor
94 routine[1]; /* Routine descriptor array */
95 } *mig_subsystem_t;
96
97 #define MIG_SUBSYSTEM_NULL ((mig_subsystem_t)0)
98
99 typedef struct mig_symtab {
100 char *ms_routine_name;
101 int ms_routine_number;
102 void (*ms_routine)(void); /* Since the functions in the
103 * symbol table have unknown
104 * signatures, this is the best
105 * we can do...
106 */
107 } mig_symtab_t;
108
109 /* Client side reply port allocate */
110 extern mach_port_t mig_get_reply_port(void);
111
112 /* Client side reply port deallocate */
113 extern void mig_dealloc_reply_port(mach_port_t reply_port);
114
115 /* Client side reply port "deallocation" */
116 extern void mig_put_reply_port(mach_port_t reply_port);
117
118 /* Bounded string copy */
119 extern int mig_strncpy(char *dest, const char *src, int len);
120
121 #ifdef KERNEL_PRIVATE
122 #include <sys/appleapiopts.h>
123
124 /* Allocate memory for out-of-stack mig structures */
125 extern char *mig_user_allocate(vm_size_t size);
126
127 /* Deallocate memory used for out-of-stack mig structures */
128 extern void mig_user_deallocate(char *data, vm_size_t size);
129
130 #ifdef __APPLE_API_EVOLVING
131 /*
132 * MIG object runtime definitions
133 *
134 * Conforming MIG subsystems may enable this support to get
135 * significant assistance from the base mig_object_t implementation.
136 *
137 * Support includes:
138 * - Transparency from port manipulation.
139 * - Dymanic port allocation on first "remoting" of an object.
140 * - Reference conversions from object to port and vice versa.
141 * - Automatic port deallocation on no-more-senders.
142 * - Support for multiple server implementations in a single space.
143 * - Messaging bypass for local servers.
144 * - Automatic hookup to base dispatch mechanism.
145 * - General notification support
146 * Coming soon:
147 * - User-level support
148 */
149 typedef unsigned int mig_notify_type_t;
150
151 typedef struct MIGIID {
152 unsigned long data1;
153 unsigned short data2;
154 unsigned short data3;
155 unsigned char data4[8];
156 } MIGIID;
157
158 typedef struct IMIGObjectVtbl IMIGObjectVtbl;
159 typedef struct IMIGNotifyObjectVtbl IMIGNotifyObjectVtbl;
160
161 typedef struct IMIGObject {
162 IMIGObjectVtbl *pVtbl;
163 } IMIGObject;
164
165 typedef struct IMIGNotifyObject {
166 IMIGNotifyObjectVtbl *pVtbl;
167 } IMIGNotifyObject;
168
169 struct IMIGObjectVtbl {
170 kern_return_t (*QueryInterface)(
171 IMIGObject *object,
172 const MIGIID *iid,
173 void **ppv);
174
175 unsigned long (*AddRef)(
176 IMIGObject *object);
177
178 unsigned long (*Release)(
179 IMIGObject *object);
180
181 unsigned long (*GetServer)(
182 IMIGObject *object,
183 mig_server_routine_t *server);
184
185 boolean_t (*RaiseNotification)(
186 IMIGObject *object,
187 mig_notify_type_t notify_type);
188
189 boolean_t (*RequestNotification)(
190 IMIGObject *object,
191 IMIGNotifyObject *notify,
192 mig_notify_type_t notify_type);
193 };
194
195 /*
196 * IMIGNotifyObject
197 *
198 * A variant of the IMIGObject interface that is a sink for
199 * MIG notifications.
200 *
201 * A reference is held on both the subject MIGObject and the target
202 * MIGNotifyObject. Because of this, care must be exercised to avoid
203 * reference cycles. Once a notification is raised, the object
204 * reference is returned and the request must be re-requested (if
205 * desired).
206 *
207 * One interesting note: because this interface is itself a MIG
208 * object, one may request notification about state changes in
209 * the MIGNotifyObject itself.
210 */
211 struct IMIGNotifyObjectVtbl {
212 kern_return_t (*QueryInterface)(
213 IMIGNotifyObject *notify,
214 const MIGIID *iid,
215 void **ppv);
216
217 unsigned long (*AddRef)(
218 IMIGNotifyObject *notify);
219
220 unsigned long (*Release)(
221 IMIGNotifyObject *notify);
222
223 unsigned long (*GetServer)(
224 IMIGNotifyObject *notify,
225 mig_server_routine_t *server);
226
227 boolean_t (*RaiseNotification)(
228 IMIGNotifyObject *notify,
229 mig_notify_type_t notify_type);
230
231 boolean_t (*RequestNotification)(
232 IMIGNotifyObject *notify,
233 IMIGNotifyObject *notify_notify,
234 mig_notify_type_t notify_type);
235
236 void (*HandleNotification)(
237 IMIGNotifyObject *notify,
238 IMIGObject *object,
239 mig_notify_type_t notify_type);
240 };
241
242 #endif /* __APPLE_API_EVOLVING */
243
244 #endif /* KERNEL_PRIVATE */
245
246 #endif /* _MACH_MIG_H_ */