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(BSMALL_LATER)
49 /* Really small configurations don't need type checking */
50 #define __MigTypeCheck 0
52 /* Turn MIG type checking on by default for kernel */
53 #define __MigTypeCheck 1
55 #define __MigKernelSpecificCode 1
56 #define _MIG_KERNEL_SPECIFIC_CODE_ 1
58 /* Otherwise check legacy setting (temporary) */
59 #elif defined(TypeCheck)
61 #define __MigTypeCheck TypeCheck
63 #elif !defined(__MigTypeCheck)
65 /* otherwise, default MIG type checking on - except in small configurations */
67 #define __MigTypeCheck 0
69 #define __MigTypeCheck 1
72 #endif /* !defined(__MigTypeCheck) */
75 * Pack MIG message structs.
76 * This is an indicator of the need to view shared structs in a
77 * binary-compatible format - and MIG message structs are no different.
79 #define __MigPackStructs 1
82 * Definition for MIG-generated server stub routines. These routines
83 * unpack the request message, call the server procedure, and pack the
86 typedef void (*mig_stub_routine_t
) (mach_msg_header_t
*InHeadP
,
87 mach_msg_header_t
*OutHeadP
);
89 typedef mig_stub_routine_t mig_routine_t
;
92 * Definition for MIG-generated server routine. This routine takes a
93 * message, and returns the appropriate stub function for handling that
96 typedef mig_routine_t (*mig_server_routine_t
) (mach_msg_header_t
*InHeadP
);
99 * Generic definition for implementation routines. These routines do
100 * the real work associated with this request. This generic type is
101 * used for keeping the pointers in the subsystem array.
103 typedef kern_return_t (*mig_impl_routine_t
)(void);
105 typedef mach_msg_type_descriptor_t routine_arg_descriptor
;
106 typedef mach_msg_type_descriptor_t
*routine_arg_descriptor_t
;
107 typedef mach_msg_type_descriptor_t
*mig_routine_arg_descriptor_t
;
109 #define MIG_ROUTINE_ARG_DESCRIPTOR_NULL ((mig_routine_arg_descriptor_t)0)
111 struct routine_descriptor
{
112 mig_impl_routine_t impl_routine
; /* Server work func pointer */
113 mig_stub_routine_t stub_routine
; /* Unmarshalling func pointer */
114 unsigned int argc
; /* Number of argument words */
115 unsigned int descr_count
; /* Number complex descriptors */
116 routine_arg_descriptor_t
117 arg_descr
; /* pointer to descriptor array*/
118 unsigned int max_reply_msg
; /* Max size for reply msg */
120 typedef struct routine_descriptor
*routine_descriptor_t
;
122 typedef struct routine_descriptor mig_routine_descriptor
;
123 typedef mig_routine_descriptor
*mig_routine_descriptor_t
;
125 #define MIG_ROUTINE_DESCRIPTOR_NULL ((mig_routine_descriptor_t)0)
127 typedef struct mig_subsystem
{
128 mig_server_routine_t server
; /* pointer to demux routine */
129 mach_msg_id_t start
; /* Min routine number */
130 mach_msg_id_t end
; /* Max routine number + 1 */
131 mach_msg_size_t maxsize
; /* Max reply message size */
132 vm_address_t reserved
; /* reserved for MIG use */
133 mig_routine_descriptor
134 routine
[1]; /* Routine descriptor array */
137 #define MIG_SUBSYSTEM_NULL ((mig_subsystem_t)0)
139 typedef struct mig_symtab
{
140 char *ms_routine_name
;
141 int ms_routine_number
;
142 void (*ms_routine
)(void); /* Since the functions in the
143 * symbol table have unknown
144 * signatures, this is the best
151 /* MIG object runtime - not ready for public consumption */
153 #ifdef KERNEL_PRIVATE
156 * MIG object runtime definitions
158 * Conforming MIG subsystems may enable this support to get
159 * significant assistance from the base mig_object_t implementation.
162 * - Transparency from port manipulation.
163 * - Dymanic port allocation on first "remoting" of an object.
164 * - Reference conversions from object to port and vice versa.
165 * - Automatic port deallocation on no-more-senders.
166 * - Support for multiple server implementations in a single space.
167 * - Messaging bypass for local servers.
168 * - Automatic hookup to base dispatch mechanism.
169 * - General notification support
171 * - User-level support
173 typedef unsigned int mig_notify_type_t
;
175 typedef struct MIGIID
{
177 unsigned short data2
;
178 unsigned short data3
;
179 unsigned char data4
[8];
182 typedef struct IMIGObjectVtbl IMIGObjectVtbl
;
183 typedef struct IMIGNotifyObjectVtbl IMIGNotifyObjectVtbl
;
185 typedef struct IMIGObject
{
186 const IMIGObjectVtbl
*pVtbl
;
189 typedef struct IMIGNotifyObject
{
190 const IMIGNotifyObjectVtbl
*pVtbl
;
193 struct IMIGObjectVtbl
{
194 kern_return_t (*QueryInterface
)(
199 unsigned long (*AddRef
)(
202 unsigned long (*Release
)(
205 unsigned long (*GetServer
)(
207 mig_server_routine_t
*server
);
209 boolean_t (*RaiseNotification
)(
211 mig_notify_type_t notify_type
);
213 boolean_t (*RequestNotification
)(
215 IMIGNotifyObject
*notify
,
216 mig_notify_type_t notify_type
);
222 * A variant of the IMIGObject interface that is a sink for
225 * A reference is held on both the subject MIGObject and the target
226 * MIGNotifyObject. Because of this, care must be exercised to avoid
227 * reference cycles. Once a notification is raised, the object
228 * reference is returned and the request must be re-requested (if
231 * One interesting note: because this interface is itself a MIG
232 * object, one may request notification about state changes in
233 * the MIGNotifyObject itself.
235 struct IMIGNotifyObjectVtbl
{
236 kern_return_t (*QueryInterface
)(
237 IMIGNotifyObject
*notify
,
241 unsigned long (*AddRef
)(
242 IMIGNotifyObject
*notify
);
244 unsigned long (*Release
)(
245 IMIGNotifyObject
*notify
);
247 unsigned long (*GetServer
)(
248 IMIGNotifyObject
*notify
,
249 mig_server_routine_t
*server
);
251 boolean_t (*RaiseNotification
)(
252 IMIGNotifyObject
*notify
,
253 mig_notify_type_t notify_type
);
255 boolean_t (*RequestNotification
)(
256 IMIGNotifyObject
*notify
,
257 IMIGNotifyObject
*notify_notify
,
258 mig_notify_type_t notify_type
);
260 void (*HandleNotification
)(
261 IMIGNotifyObject
*notify
,
263 mig_notify_type_t notify_type
);
266 #endif /* KERNEL_PRIVATE */
271 /* Client side reply port allocate */
272 extern mach_port_t
mig_get_reply_port(void);
274 /* Client side reply port deallocate */
275 extern void mig_dealloc_reply_port(mach_port_t reply_port
);
277 /* Client side reply port "deallocation" */
278 extern void mig_put_reply_port(mach_port_t reply_port
);
280 /* Bounded string copy */
281 extern int mig_strncpy(char *dest
, const char *src
, int len
);
283 #ifdef KERNEL_PRIVATE
285 /* Allocate memory for out-of-stack mig structures */
286 extern char *mig_user_allocate(vm_size_t size
);
288 /* Deallocate memory used for out-of-stack mig structures */
289 extern void mig_user_deallocate(char *data
, vm_size_t size
);
293 /* Allocate memory for out-of-line mig structures */
294 extern void mig_allocate(vm_address_t
*, vm_size_t
);
296 /* Deallocate memory used for out-of-line mig structures */
297 extern void mig_deallocate(vm_address_t
, vm_size_t
);
299 #endif /* KERNEL_PRIVATE */
303 #endif /* _MACH_MIG_H_ */