2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
33 * Mach MIG Subsystem Interfaces
40 #include <mach/port.h>
41 #include <mach/message.h>
42 #include <mach/vm_types.h>
44 #include <sys/cdefs.h>
46 #if defined(MACH_KERNEL)
48 #if !defined(__MigTypeCheck)
49 /* Turn MIG type checking on by default for kernel */
50 #define __MigTypeCheck 1
53 #define __MigKernelSpecificCode 1
54 #define _MIG_KERNEL_SPECIFIC_CODE_ 1
56 #elif !defined(__MigTypeCheck)
58 #if defined(TypeCheck)
59 /* use legacy setting (temporary) */
60 #define __MigTypeCheck TypeCheck
62 /* default MIG type checking on */
63 #define __MigTypeCheck 1
66 #endif /* !defined(MACH_KERNEL) && !defined(__MigTypeCheck) */
69 * Pack MIG message structs.
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.
73 #define __MigPackStructs 1
76 * Definition for MIG-generated server stub routines. These routines
77 * unpack the request message, call the server procedure, and pack the
80 typedef void (*mig_stub_routine_t
) (mach_msg_header_t
*InHeadP
,
81 mach_msg_header_t
*OutHeadP
);
83 typedef mig_stub_routine_t mig_routine_t
;
86 * Definition for MIG-generated server routine. This routine takes a
87 * message, and returns the appropriate stub function for handling that
90 typedef mig_routine_t (*mig_server_routine_t
) (mach_msg_header_t
*InHeadP
);
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.
97 typedef kern_return_t (*mig_impl_routine_t
)(void);
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
;
103 #define MIG_ROUTINE_ARG_DESCRIPTOR_NULL ((mig_routine_arg_descriptor_t)0)
105 struct routine_descriptor
{
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 */
110 routine_arg_descriptor_t
111 arg_descr
; /* pointer to descriptor array*/
112 unsigned int max_reply_msg
; /* Max size for reply msg */
114 typedef struct routine_descriptor
*routine_descriptor_t
;
116 typedef struct routine_descriptor mig_routine_descriptor
;
117 typedef mig_routine_descriptor
*mig_routine_descriptor_t
;
119 #define MIG_ROUTINE_DESCRIPTOR_NULL ((mig_routine_descriptor_t)0)
121 typedef struct mig_subsystem
{
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 */
127 mig_routine_descriptor
128 routine
[1]; /* Routine descriptor array */
131 #define MIG_SUBSYSTEM_NULL ((mig_subsystem_t)0)
133 typedef struct mig_symtab
{
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
145 /* MIG object runtime - not ready for public consumption */
147 #ifdef KERNEL_PRIVATE
150 * MIG object runtime definitions
152 * Conforming MIG subsystems may enable this support to get
153 * significant assistance from the base mig_object_t implementation.
156 * - Transparency from port manipulation.
157 * - Dymanic port allocation on first "remoting" of an object.
158 * - Reference conversions from object to port and vice versa.
159 * - Automatic port deallocation on no-more-senders.
160 * - Support for multiple server implementations in a single space.
161 * - Messaging bypass for local servers.
162 * - Automatic hookup to base dispatch mechanism.
163 * - General notification support
165 * - User-level support
167 typedef unsigned int mig_notify_type_t
;
169 typedef struct MIGIID
{
171 unsigned short data2
;
172 unsigned short data3
;
173 unsigned char data4
[8];
176 typedef struct IMIGObjectVtbl IMIGObjectVtbl
;
177 typedef struct IMIGNotifyObjectVtbl IMIGNotifyObjectVtbl
;
179 typedef struct IMIGObject
{
180 const IMIGObjectVtbl
*pVtbl
;
183 typedef struct IMIGNotifyObject
{
184 const IMIGNotifyObjectVtbl
*pVtbl
;
187 struct IMIGObjectVtbl
{
188 kern_return_t (*QueryInterface
)(
193 unsigned long (*AddRef
)(
196 unsigned long (*Release
)(
199 unsigned long (*GetServer
)(
201 mig_server_routine_t
*server
);
203 boolean_t (*RaiseNotification
)(
205 mig_notify_type_t notify_type
);
207 boolean_t (*RequestNotification
)(
209 IMIGNotifyObject
*notify
,
210 mig_notify_type_t notify_type
);
216 * A variant of the IMIGObject interface that is a sink for
219 * A reference is held on both the subject MIGObject and the target
220 * MIGNotifyObject. Because of this, care must be exercised to avoid
221 * reference cycles. Once a notification is raised, the object
222 * reference is returned and the request must be re-requested (if
225 * One interesting note: because this interface is itself a MIG
226 * object, one may request notification about state changes in
227 * the MIGNotifyObject itself.
229 struct IMIGNotifyObjectVtbl
{
230 kern_return_t (*QueryInterface
)(
231 IMIGNotifyObject
*notify
,
235 unsigned long (*AddRef
)(
236 IMIGNotifyObject
*notify
);
238 unsigned long (*Release
)(
239 IMIGNotifyObject
*notify
);
241 unsigned long (*GetServer
)(
242 IMIGNotifyObject
*notify
,
243 mig_server_routine_t
*server
);
245 boolean_t (*RaiseNotification
)(
246 IMIGNotifyObject
*notify
,
247 mig_notify_type_t notify_type
);
249 boolean_t (*RequestNotification
)(
250 IMIGNotifyObject
*notify
,
251 IMIGNotifyObject
*notify_notify
,
252 mig_notify_type_t notify_type
);
254 void (*HandleNotification
)(
255 IMIGNotifyObject
*notify
,
257 mig_notify_type_t notify_type
);
260 #endif /* KERNEL_PRIVATE */
265 /* Client side reply port allocate */
266 extern mach_port_t
mig_get_reply_port(void);
268 /* Client side reply port deallocate */
269 extern void mig_dealloc_reply_port(mach_port_t reply_port
);
271 /* Client side reply port "deallocation" */
272 extern void mig_put_reply_port(mach_port_t reply_port
);
274 /* Bounded string copy */
275 extern int mig_strncpy(char *dest
, const char *src
, int len
);
276 extern int mig_strncpy_zerofill(char *dest
, const char *src
, int len
);
278 #ifdef KERNEL_PRIVATE
280 /* Allocate memory for out-of-stack mig structures */
281 extern void *mig_user_allocate(vm_size_t size
);
283 /* Deallocate memory used for out-of-stack mig structures */
284 extern void mig_user_deallocate(char *data
, vm_size_t size
);
288 /* Allocate memory for out-of-line mig structures */
289 extern void mig_allocate(vm_address_t
*, vm_size_t
);
291 /* Deallocate memory used for out-of-line mig structures */
292 extern void mig_deallocate(vm_address_t
, vm_size_t
);
294 #endif /* KERNEL_PRIVATE */
298 #endif /* _MACH_MIG_H_ */