2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
27 * Mach MIG Subsystem Interfaces
34 #include <mach/port.h>
35 #include <mach/message.h>
36 #include <mach/vm_types.h>
38 #include <sys/cdefs.h>
40 #if defined(MACH_KERNEL)
42 /* Turn MIG type checking on by default for kernel */
43 #define __MigTypeCheck 1
44 #define __MigKernelSpecificCode 1
45 #define _MIG_KERNEL_SPECIFIC_CODE_ 1
47 /* Otherwise check legacy setting (temporary) */
48 #elif defined(TypeCheck)
50 #define __MigTypeCheck TypeCheck
52 #endif /* defined(TypeCheck) */
55 * Pack MIG message structs.
56 * This is an indicator of the need to view shared structs in a
57 * binary-compatible format - and MIG message structs are no different.
59 #define __MigPackStructs 1
62 * Definition for MIG-generated server stub routines. These routines
63 * unpack the request message, call the server procedure, and pack the
66 typedef void (*mig_stub_routine_t
) (mach_msg_header_t
*InHeadP
,
67 mach_msg_header_t
*OutHeadP
);
69 typedef mig_stub_routine_t mig_routine_t
;
72 * Definition for MIG-generated server routine. This routine takes a
73 * message, and returns the appropriate stub function for handling that
76 typedef mig_routine_t (*mig_server_routine_t
) (mach_msg_header_t
*InHeadP
);
79 * Generic definition for implementation routines. These routines do
80 * the real work associated with this request. This generic type is
81 * used for keeping the pointers in the subsystem array.
83 typedef kern_return_t (*mig_impl_routine_t
)(void);
85 typedef mach_msg_type_descriptor_t routine_arg_descriptor
;
86 typedef mach_msg_type_descriptor_t
*routine_arg_descriptor_t
;
87 typedef mach_msg_type_descriptor_t
*mig_routine_arg_descriptor_t
;
89 #define MIG_ROUTINE_ARG_DESCRIPTOR_NULL ((mig_routine_arg_descriptor_t)0)
91 struct routine_descriptor
{
92 mig_impl_routine_t impl_routine
; /* Server work func pointer */
93 mig_stub_routine_t stub_routine
; /* Unmarshalling func pointer */
94 unsigned int argc
; /* Number of argument words */
95 unsigned int descr_count
; /* Number complex descriptors */
96 routine_arg_descriptor_t
97 arg_descr
; /* pointer to descriptor array*/
98 unsigned int max_reply_msg
; /* Max size for reply msg */
100 typedef struct routine_descriptor
*routine_descriptor_t
;
102 typedef struct routine_descriptor mig_routine_descriptor
;
103 typedef mig_routine_descriptor
*mig_routine_descriptor_t
;
105 #define MIG_ROUTINE_DESCRIPTOR_NULL ((mig_routine_descriptor_t)0)
107 typedef struct mig_subsystem
{
108 mig_server_routine_t server
; /* pointer to demux routine */
109 mach_msg_id_t start
; /* Min routine number */
110 mach_msg_id_t end
; /* Max routine number + 1 */
111 mach_msg_size_t maxsize
; /* Max reply message size */
112 vm_address_t reserved
; /* reserved for MIG use */
113 mig_routine_descriptor
114 routine
[1]; /* Routine descriptor array */
117 #define MIG_SUBSYSTEM_NULL ((mig_subsystem_t)0)
119 typedef struct mig_symtab
{
120 char *ms_routine_name
;
121 int ms_routine_number
;
122 void (*ms_routine
)(void); /* Since the functions in the
123 * symbol table have unknown
124 * signatures, this is the best
131 /* MIG object runtime - not ready for public consumption */
133 #ifdef KERNEL_PRIVATE
136 * MIG object runtime definitions
138 * Conforming MIG subsystems may enable this support to get
139 * significant assistance from the base mig_object_t implementation.
142 * - Transparency from port manipulation.
143 * - Dymanic port allocation on first "remoting" of an object.
144 * - Reference conversions from object to port and vice versa.
145 * - Automatic port deallocation on no-more-senders.
146 * - Support for multiple server implementations in a single space.
147 * - Messaging bypass for local servers.
148 * - Automatic hookup to base dispatch mechanism.
149 * - General notification support
151 * - User-level support
153 typedef unsigned int mig_notify_type_t
;
155 typedef struct MIGIID
{
157 unsigned short data2
;
158 unsigned short data3
;
159 unsigned char data4
[8];
162 typedef struct IMIGObjectVtbl IMIGObjectVtbl
;
163 typedef struct IMIGNotifyObjectVtbl IMIGNotifyObjectVtbl
;
165 typedef struct IMIGObject
{
166 const IMIGObjectVtbl
*pVtbl
;
169 typedef struct IMIGNotifyObject
{
170 const IMIGNotifyObjectVtbl
*pVtbl
;
173 struct IMIGObjectVtbl
{
174 kern_return_t (*QueryInterface
)(
179 unsigned long (*AddRef
)(
182 unsigned long (*Release
)(
185 unsigned long (*GetServer
)(
187 mig_server_routine_t
*server
);
189 boolean_t (*RaiseNotification
)(
191 mig_notify_type_t notify_type
);
193 boolean_t (*RequestNotification
)(
195 IMIGNotifyObject
*notify
,
196 mig_notify_type_t notify_type
);
202 * A variant of the IMIGObject interface that is a sink for
205 * A reference is held on both the subject MIGObject and the target
206 * MIGNotifyObject. Because of this, care must be exercised to avoid
207 * reference cycles. Once a notification is raised, the object
208 * reference is returned and the request must be re-requested (if
211 * One interesting note: because this interface is itself a MIG
212 * object, one may request notification about state changes in
213 * the MIGNotifyObject itself.
215 struct IMIGNotifyObjectVtbl
{
216 kern_return_t (*QueryInterface
)(
217 IMIGNotifyObject
*notify
,
221 unsigned long (*AddRef
)(
222 IMIGNotifyObject
*notify
);
224 unsigned long (*Release
)(
225 IMIGNotifyObject
*notify
);
227 unsigned long (*GetServer
)(
228 IMIGNotifyObject
*notify
,
229 mig_server_routine_t
*server
);
231 boolean_t (*RaiseNotification
)(
232 IMIGNotifyObject
*notify
,
233 mig_notify_type_t notify_type
);
235 boolean_t (*RequestNotification
)(
236 IMIGNotifyObject
*notify
,
237 IMIGNotifyObject
*notify_notify
,
238 mig_notify_type_t notify_type
);
240 void (*HandleNotification
)(
241 IMIGNotifyObject
*notify
,
243 mig_notify_type_t notify_type
);
246 #endif /* KERNEL_PRIVATE */
251 /* Client side reply port allocate */
252 extern mach_port_t
mig_get_reply_port(void);
254 /* Client side reply port deallocate */
255 extern void mig_dealloc_reply_port(mach_port_t reply_port
);
257 /* Client side reply port "deallocation" */
258 extern void mig_put_reply_port(mach_port_t reply_port
);
260 /* Bounded string copy */
261 extern int mig_strncpy(char *dest
, const char *src
, int len
);
263 #ifdef KERNEL_PRIVATE
265 /* Allocate memory for out-of-stack mig structures */
266 extern char *mig_user_allocate(vm_size_t size
);
268 /* Deallocate memory used for out-of-stack mig structures */
269 extern void mig_user_deallocate(char *data
, vm_size_t size
);
273 /* Allocate memory for out-of-line mig structures */
274 extern void mig_allocate(vm_address_t
*, vm_size_t
);
276 /* Deallocate memory used for out-of-line mig structures */
277 extern void mig_deallocate(vm_address_t
, vm_size_t
);
279 #endif /* KERNEL_PRIVATE */
283 #endif /* _MACH_MIG_H_ */