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