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