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(__MigTypeCheck) |
49 | /* Turn MIG type checking on by default for kernel */ |
50 | #define __MigTypeCheck 1 |
51 | #endif |
52 | |
53 | #define __MigKernelSpecificCode 1 |
54 | #define _MIG_KERNEL_SPECIFIC_CODE_ 1 |
55 | |
56 | #elif !defined(__MigTypeCheck) |
57 | |
58 | #if defined(TypeCheck) |
59 | /* use legacy setting (temporary) */ |
60 | #define __MigTypeCheck TypeCheck |
61 | #else |
62 | /* default MIG type checking on */ |
63 | #define __MigTypeCheck 1 |
64 | #endif |
65 | |
66 | #endif /* !defined(MACH_KERNEL) && !defined(__MigTypeCheck) */ |
67 | |
68 | /* |
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. |
72 | */ |
73 | #define __MigPackStructs 1 |
74 | |
75 | /* |
76 | * Definition for MIG-generated server stub routines. These routines |
77 | * unpack the request message, call the server procedure, and pack the |
78 | * reply message. |
79 | */ |
80 | typedef void (*mig_stub_routine_t) (mach_msg_header_t *InHeadP, |
81 | mach_msg_header_t *OutHeadP); |
82 | |
83 | typedef mig_stub_routine_t mig_routine_t; |
84 | |
85 | /* |
86 | * Definition for MIG-generated server routine. This routine takes a |
87 | * message, and returns the appropriate stub function for handling that |
88 | * message. |
89 | */ |
90 | typedef mig_routine_t (*mig_server_routine_t) (mach_msg_header_t *InHeadP); |
91 | |
92 | /* |
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. |
96 | */ |
97 | typedef kern_return_t (*mig_impl_routine_t)(void); |
98 | |
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; |
102 | |
103 | #define MIG_ROUTINE_ARG_DESCRIPTOR_NULL ((mig_routine_arg_descriptor_t)0) |
104 | |
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 */ |
113 | }; |
114 | typedef struct routine_descriptor *routine_descriptor_t; |
115 | |
116 | typedef struct routine_descriptor mig_routine_descriptor; |
117 | typedef mig_routine_descriptor *mig_routine_descriptor_t; |
118 | |
119 | #define MIG_ROUTINE_DESCRIPTOR_NULL ((mig_routine_descriptor_t)0) |
120 | |
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 */ |
129 | } *mig_subsystem_t; |
130 | |
131 | #ifdef XNU_KERNEL_PRIVATE |
132 | /* KernelServer MIG routine/subsystem types */ |
133 | typedef void (*mig_stub_kern_routine_t) (mach_msg_header_t *InHeadP, void *InDataP, |
134 | mach_msg_max_trailer_t *InTrailerP, mach_msg_header_t *OutHeadP, void *OutDataP); |
135 | |
136 | typedef mig_stub_kern_routine_t mig_kern_routine_t; |
137 | |
138 | typedef mig_kern_routine_t (*mig_kern_server_routine_t) (mach_msg_header_t *InHeadP); |
139 | |
140 | struct kern_routine_descriptor { |
141 | mig_impl_routine_t impl_routine; /* Server work func pointer */ |
142 | mig_stub_kern_routine_t kstub_routine; /* Unmarshalling func pointer */ |
143 | unsigned int argc; /* Number of argument words */ |
144 | unsigned int descr_count; /* Number complex descriptors */ |
145 | unsigned int reply_descr_count; /* Number descriptors in reply */ |
146 | unsigned int max_reply_msg; /* Max size for reply msg */ |
147 | }; |
148 | |
149 | typedef struct kern_routine_descriptor mig_kern_routine_descriptor; |
150 | typedef struct kern_routine_descriptor *kern_routine_descriptor_t; |
151 | |
152 | typedef struct mig_kern_subsystem { |
153 | mig_kern_server_routine_t kserver; /* pointer to kernel demux routine */ |
154 | mach_msg_id_t start; /* Min routine number */ |
155 | mach_msg_id_t end; /* Max routine number + 1 */ |
156 | mach_msg_size_t maxsize; /* Max reply message size */ |
157 | vm_address_t reserved; /* reserved for MIG use */ |
158 | mig_kern_routine_descriptor |
159 | kroutine[1]; /* Kernel routine descriptor array */ |
160 | } *mig_kern_subsystem_t; |
161 | #endif /* XNU_KERNEL_PRIVATE */ |
162 | |
163 | #define MIG_SUBSYSTEM_NULL ((mig_subsystem_t)0) |
164 | |
165 | typedef struct mig_symtab { |
166 | char *ms_routine_name; |
167 | int ms_routine_number; |
168 | void (*ms_routine)(void); /* Since the functions in the |
169 | * symbol table have unknown |
170 | * signatures, this is the best |
171 | * we can do... |
172 | */ |
173 | } mig_symtab_t; |
174 | |
175 | /* |
176 | * A compiler attribute for annotating all MIG server routines and other |
177 | * functions that should behave similarly. Allows the compiler to perform |
178 | * additional static bug-finding over them. |
179 | */ |
180 | #if __has_attribute(mig_server_routine) |
181 | #define MIG_SERVER_ROUTINE __attribute__((mig_server_routine)) |
182 | #else |
183 | #define MIG_SERVER_ROUTINE |
184 | #endif |
185 | |
186 | __BEGIN_DECLS |
187 | |
188 | /* Client side reply port allocate */ |
189 | extern mach_port_t mig_get_reply_port(void); |
190 | |
191 | /* Client side reply port deallocate */ |
192 | extern void mig_dealloc_reply_port(mach_port_t reply_port); |
193 | |
194 | /* Client side reply port "deallocation" */ |
195 | extern void mig_put_reply_port(mach_port_t reply_port); |
196 | |
197 | /* Bounded string copy */ |
198 | extern int mig_strncpy(char *dest, const char *src, int len); |
199 | extern int mig_strncpy_zerofill(char *dest, const char *src, int len); |
200 | |
201 | #ifdef KERNEL_PRIVATE |
202 | |
203 | /* Allocate memory for out-of-stack mig structures */ |
204 | extern void *mig_user_allocate(vm_size_t size); |
205 | |
206 | /* Deallocate memory used for out-of-stack mig structures */ |
207 | extern void mig_user_deallocate(char *data, vm_size_t size); |
208 | |
209 | #else |
210 | |
211 | /* Allocate memory for out-of-line mig structures */ |
212 | extern void mig_allocate(vm_address_t *, vm_size_t); |
213 | |
214 | /* Deallocate memory used for out-of-line mig structures */ |
215 | extern void mig_deallocate(vm_address_t, vm_size_t); |
216 | |
217 | #endif /* KERNEL_PRIVATE */ |
218 | |
219 | __END_DECLS |
220 | |
221 | #endif /* _MACH_MIG_H_ */ |
222 | |