2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
35 * Mach MIG Subsystem Interfaces
42 #include <mach/port.h>
43 #include <mach/message.h>
44 #include <mach/vm_types.h>
46 #include <sys/cdefs.h>
48 #if defined(MACH_KERNEL)
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
55 /* Otherwise check legacy setting (temporary) */
56 #elif defined(TypeCheck)
58 #define __MigTypeCheck TypeCheck
60 #endif /* defined(TypeCheck) */
63 * Pack MIG message structs.
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.
67 #define __MigPackStructs 1
70 * Definition for MIG-generated server stub routines. These routines
71 * unpack the request message, call the server procedure, and pack the
74 typedef void (*mig_stub_routine_t
) (mach_msg_header_t
*InHeadP
,
75 mach_msg_header_t
*OutHeadP
);
77 typedef mig_stub_routine_t mig_routine_t
;
80 * Definition for MIG-generated server routine. This routine takes a
81 * message, and returns the appropriate stub function for handling that
84 typedef mig_routine_t (*mig_server_routine_t
) (mach_msg_header_t
*InHeadP
);
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.
91 typedef kern_return_t (*mig_impl_routine_t
)(void);
93 typedef mach_msg_type_descriptor_t routine_arg_descriptor
;
94 typedef mach_msg_type_descriptor_t
*routine_arg_descriptor_t
;
95 typedef mach_msg_type_descriptor_t
*mig_routine_arg_descriptor_t
;
97 #define MIG_ROUTINE_ARG_DESCRIPTOR_NULL ((mig_routine_arg_descriptor_t)0)
99 struct 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 */
108 typedef struct routine_descriptor
*routine_descriptor_t
;
110 typedef struct routine_descriptor mig_routine_descriptor
;
111 typedef mig_routine_descriptor
*mig_routine_descriptor_t
;
113 #define MIG_ROUTINE_DESCRIPTOR_NULL ((mig_routine_descriptor_t)0)
115 typedef struct mig_subsystem
{
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 */
125 #define MIG_SUBSYSTEM_NULL ((mig_subsystem_t)0)
127 typedef 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
139 /* MIG object runtime - not ready for public consumption */
141 #ifdef KERNEL_PRIVATE
144 * MIG object runtime definitions
146 * Conforming MIG subsystems may enable this support to get
147 * significant assistance from the base mig_object_t implementation.
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
159 * - User-level support
161 typedef unsigned int mig_notify_type_t
;
163 typedef struct MIGIID
{
165 unsigned short data2
;
166 unsigned short data3
;
167 unsigned char data4
[8];
170 typedef struct IMIGObjectVtbl IMIGObjectVtbl
;
171 typedef struct IMIGNotifyObjectVtbl IMIGNotifyObjectVtbl
;
173 typedef struct IMIGObject
{
174 const IMIGObjectVtbl
*pVtbl
;
177 typedef struct IMIGNotifyObject
{
178 const IMIGNotifyObjectVtbl
*pVtbl
;
181 struct IMIGObjectVtbl
{
182 kern_return_t (*QueryInterface
)(
187 unsigned long (*AddRef
)(
190 unsigned long (*Release
)(
193 unsigned long (*GetServer
)(
195 mig_server_routine_t
*server
);
197 boolean_t (*RaiseNotification
)(
199 mig_notify_type_t notify_type
);
201 boolean_t (*RequestNotification
)(
203 IMIGNotifyObject
*notify
,
204 mig_notify_type_t notify_type
);
210 * A variant of the IMIGObject interface that is a sink for
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
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.
223 struct IMIGNotifyObjectVtbl
{
224 kern_return_t (*QueryInterface
)(
225 IMIGNotifyObject
*notify
,
229 unsigned long (*AddRef
)(
230 IMIGNotifyObject
*notify
);
232 unsigned long (*Release
)(
233 IMIGNotifyObject
*notify
);
235 unsigned long (*GetServer
)(
236 IMIGNotifyObject
*notify
,
237 mig_server_routine_t
*server
);
239 boolean_t (*RaiseNotification
)(
240 IMIGNotifyObject
*notify
,
241 mig_notify_type_t notify_type
);
243 boolean_t (*RequestNotification
)(
244 IMIGNotifyObject
*notify
,
245 IMIGNotifyObject
*notify_notify
,
246 mig_notify_type_t notify_type
);
248 void (*HandleNotification
)(
249 IMIGNotifyObject
*notify
,
251 mig_notify_type_t notify_type
);
254 #endif /* KERNEL_PRIVATE */
259 /* Client side reply port allocate */
260 extern mach_port_t
mig_get_reply_port(void);
262 /* Client side reply port deallocate */
263 extern void mig_dealloc_reply_port(mach_port_t reply_port
);
265 /* Client side reply port "deallocation" */
266 extern void mig_put_reply_port(mach_port_t reply_port
);
268 /* Bounded string copy */
269 extern int mig_strncpy(char *dest
, const char *src
, int len
);
271 #ifdef KERNEL_PRIVATE
273 /* Allocate memory for out-of-stack mig structures */
274 extern char *mig_user_allocate(vm_size_t size
);
276 /* Deallocate memory used for out-of-stack mig structures */
277 extern void mig_user_deallocate(char *data
, vm_size_t size
);
281 /* Allocate memory for out-of-line mig structures */
282 extern void mig_allocate(vm_address_t
*, vm_size_t
);
284 /* Deallocate memory used for out-of-line mig structures */
285 extern void mig_deallocate(vm_address_t
, vm_size_t
);
287 #endif /* KERNEL_PRIVATE */
291 #endif /* _MACH_MIG_H_ */