1/* 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 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. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 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. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* 29 * @OSF_COPYRIGHT@ 30 */ 31 32/* 33 * Mach MIG Subsystem Interfaces 34 */ 35 36#ifndef _MACH_MIG_H_ 37#define _MACH_MIG_H_ 38 39#include <stdint.h> 40#include <mach/port.h> 41#include <mach/message.h> 42#include <mach/vm_types.h> 43 44#include <sys/cdefs.h> 45 46#if defined(MACH_KERNEL) 47 48#if defined(BSMALL_LATER) 49/* Really small configurations don't need type checking */ 50#define __MigTypeCheck 0 51#else 52/* Turn MIG type checking on by default for kernel */ 53#define __MigTypeCheck 1 54#endif 55#define __MigKernelSpecificCode 1 56#define _MIG_KERNEL_SPECIFIC_CODE_ 1 57 58/* Otherwise check legacy setting (temporary) */ 59#elif defined(TypeCheck) 60 61#define __MigTypeCheck TypeCheck 62 63#elif !defined(__MigTypeCheck) 64 65/* otherwise, default MIG type checking on - except in small configurations */ 66#if defined(BSMALL) 67#define __MigTypeCheck 0 68#else 69#define __MigTypeCheck 1 70#endif 71 72#endif /* !defined(__MigTypeCheck) */ 73 74/* 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. 78 */ 79#define __MigPackStructs 1 80 81/* 82 * Definition for MIG-generated server stub routines. These routines 83 * unpack the request message, call the server procedure, and pack the 84 * reply message. 85 */ 86typedef void (*mig_stub_routine_t) (mach_msg_header_t *InHeadP, 87 mach_msg_header_t *OutHeadP); 88 89typedef mig_stub_routine_t mig_routine_t; 90 91/* 92 * Definition for MIG-generated server routine. This routine takes a 93 * message, and returns the appropriate stub function for handling that 94 * message. 95 */ 96typedef mig_routine_t (*mig_server_routine_t) (mach_msg_header_t *InHeadP); 97 98/* 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. 102 */ 103typedef kern_return_t (*mig_impl_routine_t)(void); 104 105typedef mach_msg_type_descriptor_t routine_arg_descriptor; 106typedef mach_msg_type_descriptor_t *routine_arg_descriptor_t; 107typedef mach_msg_type_descriptor_t *mig_routine_arg_descriptor_t; 108 109#define MIG_ROUTINE_ARG_DESCRIPTOR_NULL ((mig_routine_arg_descriptor_t)0) 110 111struct 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 */ 119}; 120typedef struct routine_descriptor *routine_descriptor_t; 121 122typedef struct routine_descriptor mig_routine_descriptor; 123typedef mig_routine_descriptor *mig_routine_descriptor_t; 124 125#define MIG_ROUTINE_DESCRIPTOR_NULL ((mig_routine_descriptor_t)0) 126 127typedef 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 */ 135} *mig_subsystem_t; 136 137#define MIG_SUBSYSTEM_NULL ((mig_subsystem_t)0) 138 139typedef 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 145 * we can do... 146 */ 147} mig_symtab_t; 148 149#ifdef PRIVATE 150 151/* MIG object runtime - not ready for public consumption */ 152 153#ifdef KERNEL_PRIVATE 154 155/* 156 * MIG object runtime definitions 157 * 158 * Conforming MIG subsystems may enable this support to get 159 * significant assistance from the base mig_object_t implementation. 160 * 161 * Support includes: 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 170 * Coming soon: 171 * - User-level support 172 */ 173typedef unsigned int mig_notify_type_t; 174 175typedef struct MIGIID { 176 unsigned long data1; 177 unsigned short data2; 178 unsigned short data3; 179 unsigned char data4[8]; 180} MIGIID; 181 182typedef struct IMIGObjectVtbl IMIGObjectVtbl; 183typedef struct IMIGNotifyObjectVtbl IMIGNotifyObjectVtbl; 184 185typedef struct IMIGObject { 186 const IMIGObjectVtbl *pVtbl; 187} IMIGObject; 188 189typedef struct IMIGNotifyObject { 190 const IMIGNotifyObjectVtbl *pVtbl; 191} IMIGNotifyObject; 192 193struct IMIGObjectVtbl { 194 kern_return_t (*QueryInterface)( 195 IMIGObject *object, 196 const MIGIID *iid, 197 void **ppv); 198 199 unsigned long (*AddRef)( 200 IMIGObject *object); 201 202 unsigned long (*Release)( 203 IMIGObject *object); 204 205 unsigned long (*GetServer)( 206 IMIGObject *object, 207 mig_server_routine_t *server); 208 209 boolean_t (*RaiseNotification)( 210 IMIGObject *object, 211 mig_notify_type_t notify_type); 212 213 boolean_t (*RequestNotification)( 214 IMIGObject *object, 215 IMIGNotifyObject *notify, 216 mig_notify_type_t notify_type); 217}; 218 219/* 220 * IMIGNotifyObject 221 * 222 * A variant of the IMIGObject interface that is a sink for 223 * MIG notifications. 224 * 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 229 * desired). 230 * 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. 234 */ 235struct IMIGNotifyObjectVtbl { 236 kern_return_t (*QueryInterface)( 237 IMIGNotifyObject *notify, 238 const MIGIID *iid, 239 void **ppv); 240 241 unsigned long (*AddRef)( 242 IMIGNotifyObject *notify); 243 244 unsigned long (*Release)( 245 IMIGNotifyObject *notify); 246 247 unsigned long (*GetServer)( 248 IMIGNotifyObject *notify, 249 mig_server_routine_t *server); 250 251 boolean_t (*RaiseNotification)( 252 IMIGNotifyObject *notify, 253 mig_notify_type_t notify_type); 254 255 boolean_t (*RequestNotification)( 256 IMIGNotifyObject *notify, 257 IMIGNotifyObject *notify_notify, 258 mig_notify_type_t notify_type); 259 260 void (*HandleNotification)( 261 IMIGNotifyObject *notify, 262 IMIGObject *object, 263 mig_notify_type_t notify_type); 264}; 265 266#endif /* KERNEL_PRIVATE */ 267#endif /* PRIVATE */ 268 269__BEGIN_DECLS 270 271/* Client side reply port allocate */ 272extern mach_port_t mig_get_reply_port(void); 273 274/* Client side reply port deallocate */ 275extern void mig_dealloc_reply_port(mach_port_t reply_port); 276 277/* Client side reply port "deallocation" */ 278extern void mig_put_reply_port(mach_port_t reply_port); 279 280/* Bounded string copy */ 281extern int mig_strncpy(char *dest, const char *src, int len); 282 283#ifdef KERNEL_PRIVATE 284 285/* Allocate memory for out-of-stack mig structures */ 286extern char *mig_user_allocate(vm_size_t size); 287 288/* Deallocate memory used for out-of-stack mig structures */ 289extern void mig_user_deallocate(char *data, vm_size_t size); 290 291#else 292 293/* Allocate memory for out-of-line mig structures */ 294extern void mig_allocate(vm_address_t *, vm_size_t); 295 296/* Deallocate memory used for out-of-line mig structures */ 297extern void mig_deallocate(vm_address_t, vm_size_t); 298 299#endif /* KERNEL_PRIVATE */ 300 301__END_DECLS 302 303#endif /* _MACH_MIG_H_ */ 304