1/*
2 * Copyright (c) 1999, 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*  HISTORY
24 * 07-Apr-89  Richard Draves (rpd) at Carnegie-Mellon University
25 * Extensive revamping.  Added polymorphic arguments.
26 * Allow multiple variable-sized inline arguments in messages.
27 *
28 * 16-Nov-87  David Golub (dbg) at Carnegie-Mellon University
29 * Changed itVarArrayDecl to take a 'max' parameter.
30 * Added itDestructor.
31 *
32 *  18-Aug-87 Mary Thompson @ Carnegie Mellon
33 * Added itPortType
34 * Added itTidType
35 */
36
37#ifndef _TYPE_H
38#define _TYPE_H
39
40#include <mach/boolean.h>
41#include "strdefs.h"
42
43#ifdef linux
44#include <linux/types.h>
45#else /* linux */
46#include <sys/types.h>
47#endif /* linux */
48typedef u_int ipc_flags_t;
49
50/*
51 * MIG built-in types
52 */
53#define MACH_MSG_TYPE_UNSTRUCTURED      0
54#define MACH_MSG_TYPE_BIT               0
55#define MACH_MSG_TYPE_BOOLEAN           0
56#define MACH_MSG_TYPE_INTEGER_8         9
57#define MACH_MSG_TYPE_INTEGER_16        1
58#define MACH_MSG_TYPE_INTEGER_32        2
59#define MACH_MSG_TYPE_INTEGER_64        3
60#define MACH_MSG_TYPE_CHAR              8
61#define MACH_MSG_TYPE_BYTE              9
62#define MACH_MSG_TYPE_REAL_32           10
63#define MACH_MSG_TYPE_REAL_64           11
64#define MACH_MSG_TYPE_STRING            12
65#define MACH_MSG_TYPE_STRING_C          12
66
67#define flNone          (0x00)
68#define flPhysicalCopy  (0x01) /* Physical Copy specified */
69#define flOverwrite     (0x02) /* Overwrite mode specified */
70#define flDealloc       (0x04) /* Dealloc specified */
71#define flNotDealloc    (0x08) /* NotDealloc specified */
72#define flMaybeDealloc  (0x10) /* Dealloc[] specified */
73#define flSameCount     (0x20) /* SamCount specified, used by co-bounded arrays */
74#define flCountInOut    (0x40) /* CountInOut specified */
75#define flRetCode       (0x80) /* RetCode specified */
76#define flAuto          (0x100) /* Will not be referenced by server after RPC */
77#define flConst         (0x200) /* Will not be modified by server during RPC */
78
79typedef enum dealloc {
80 d_NO, /* do not deallocate */
81 d_YES, /* always deallocate */
82 d_MAYBE /* deallocate according to parameter */
83} dealloc_t;
84
85/* Convert dealloc_t to TRUE/FALSE */
86#define strdealloc(d) (strbool(d == d_YES))
87
88/*
89 * itName and itNext are internal fields (not used for code generation).
90 * They are only meaningful for types entered into the symbol table.
91 * The symbol table is a simple self-organizing linked list.
92 *
93 * The function itCheckDecl checks & fills in computed information.
94 * Every type actually used (pointed at by argType) is so processed.
95 *
96 * The itInName, itOutName, itSize, itNumber, fields correspond directly
97 * to mach_msg_type_t fields.
98 * For out-of-line variable sized types, itNumber is zero.  For
99 * in-line variable sized types, itNumber is the maximum size of the
100 * array.  itInName is the name value supplied to the kernel,
101 * and itOutName is the name value received from the kernel.
102 * When the type describes a MACH port, either or both may be
103 * MACH_MSG_TYPE_POLYMORPHIC, indicating a "polymorphic" name.
104 * For itInName, this means the user supplies the value with an argument.
105 * For itOutName, this means the value is returned in an argument.
106 *
107 * The itInNameStr and itOutNameStr fields contain "printing" versions
108 * of the itInName and itOutName values.  The mapping from number->string
109 * is not into (eg, MACH_MSG_TYPE_UNSTRUCTURED/MACH_MSG_TYPE_BOOLEAN/
110 * MACH_MSG_TYPE_BIT).  These fields are used for code-generation and
111 * pretty-printing.
112 *
113 * itTypeSize is the calculated size of the C type, in bytes.
114 * itPadSize is the size of any padded needed after the data field.
115 * itMinTypeSize is the minimum size of the data field, including padding.
116 * For variable-length inline data, it is zero.
117 *
118 * itUserType, itServerType, itTransType are the C types used in
119 * code generation.  itUserType is the C type passed to the user-side stub
120 * and used for msg declarations in the user-side stub.  itServerType
121 * is the C type used for msg declarations in the server-side stub.
122 * itTransType is the C type passed to the server function by the
123 * server-side stub.  Normally it differs from itServerType only when
124 * translation functions are defined.
125 *
126 * itInTrans and itOutTrans are translation functions.  itInTrans
127 * takes itServerType values and returns itTransType values.  itOutTrans
128 * takes itTransType vaulues and returns itServerType values.
129 * itDestructor is a finalization function applied to In arguments
130 * after the server-side stub calls the server function.  It takes
131 * itTransType values.  Any combination of these may be defined.
132 *
133 * The following type specification syntax modifies these values:
134 * type new = old
135 * ctype: name // itUserType and itServerType
136 * cusertype: itUserType
137 * cservertype: itServerType
138 * intran: itTransType itInTrans(itServerType)
139 * outtran: itServerType itOutTrans(itTransType)
140 * destructor: itDestructor(itTransType);
141 *
142 * At most one of itStruct and itString should be TRUE.  If both are
143 * false, then this is assumed to be an array type (msg data is passed
144 * by reference).  If itStruct is TRUE, then msg data is passed by value
145 * and can be assigned with =.  If itString is TRUE, then the msg_data
146 * is a null-terminated string, assigned with strncpy.  The itNumber
147 * value is a maximum length for the string; the msg field always
148 * takes up this much space.
149 * NoOptArray has been introduced for the cases where the special
150 * code generated for array assignments would not work (either because
151 * there is  not a ctype (array of automagically generated MiG variables)
152 * or because we need to reference the single elements of the array
153 * (array of variable sized ool regions).
154 *
155 * itVarArray means this is a variable-sized array.  If it is inline,
156 * then itStruct and itString are FALSE.  If it is out-of-line, then
157 * itStruct is TRUE (because pointers can be assigned).
158 *
159 * itMigInLine means this is an indefinite-length array. Although the
160 * argument was not specified as out-of-line, MIG will send it anyway
161 * os an out-of-line.
162 *
163 * itUserKPDType (itServerKPDType) identify the type of Kernel Processed
164 * Data that we must deal with: it can be either "mach_msg_port_descriptor_t"
165 * or "mach_msg_ool_ports_descriptor_t" or "mach_msg_ool_descriptor_t".
166 *
167 * itKPD_Number is used any time a single argument require more than
168 * one Kernel Processed Data entry: i.e., an in-line array of ports, an array
169 * of pointers (out-of-line data)
170 *
171 * itElement points to any substructure that the type may have.
172 * It is only used with variable-sized array types.
173 */
174
175typedef struct ipc_type
176  {
177    identifier_t itName;      /* Mig's name for this type */
178    struct ipc_type *itNext;  /* next type in symbol table */
179
180    u_int itTypeSize;         /* size of the C type */
181    u_int itPadSize;          /* amount of padding after data */
182    u_int itMinTypeSize;      /* minimal amount of space occupied by data */
183
184    u_int itInName;           /* name supplied to kernel in sent msg */
185    u_int itOutName;          /* name in received msg */
186    u_int itSize;
187    u_int itNumber;
188    u_int itKPD_Number;       /* number of Kernel Processed Data entries */
189    boolean_t itInLine;
190    boolean_t itMigInLine;    /* MiG presents data as InLine, although it is sent OOL */
191    boolean_t itPortType;
192
193    string_t itInNameStr;     /* string form of itInName */
194    string_t itOutNameStr;    /* string form of itOutName */
195
196    boolean_t itStruct;
197    boolean_t itString;
198    boolean_t itVarArray;
199    boolean_t itNoOptArray;
200    boolean_t itNative;       /* User specified a native (C) type. */
201    boolean_t itNativePointer;/* The user will pass a pointer to the */
202    /* native C type. */
203
204    struct ipc_type *itElement; /* may be NULL */
205
206    identifier_t itUserType;
207    identifier_t itServerType;
208    identifier_t itTransType;
209
210    identifier_t itKPDType;   /* descriptors for KPD type of arguments */
211
212    identifier_t itInTrans;   /* may be NULL */
213    identifier_t itOutTrans;  /* may be NULL */
214    identifier_t itDestructor;/* may be NULL */
215    identifier_t itBadValue;   /* Excluded value for PointerToIfNot.  May
216     be NULL. */
217  } ipc_type_t;
218
219#define itNULL ((ipc_type_t *) 0)
220
221#define itWordAlign     sizeof(natural_t)
222
223extern ipc_type_t *itLookUp(/* identifier_t name */);
224extern void itInsert(/* identifier_t name, ipc_type_t *it */);
225extern void itTypeDecl(/* identifier_t name, ipc_type_t *it */);
226
227extern ipc_type_t *itShortDecl(/* u_int inname, string_t instr,
228                                  u_int outname, string_t outstr,
229                                  u_int dfault */);
230extern ipc_type_t *itPrevDecl(/* identifier_t name */);
231extern ipc_type_t *itResetType(/* ipc_type_t *it */);
232extern ipc_type_t *itVarArrayDecl(/* u_int number, ipc_type_t *it */);
233extern ipc_type_t *itArrayDecl(/* u_int number, ipc_type_t *it */);
234extern ipc_type_t *itPtrDecl(/* ipc_type_t *it */);
235extern ipc_type_t *itStructDecl(/* u_int number, ipc_type_t *it */);
236extern ipc_type_t *itCStringDecl(/* u_int number, boolean_t varying */);
237extern ipc_type_t *itNativeType(/* identifier_t CType, boolean_t pointer
238                                   identifier_t NotVal */);
239
240extern ipc_type_t *itRetCodeType;
241extern ipc_type_t *itNdrCodeType;
242extern ipc_type_t *itDummyType;
243extern ipc_type_t *itTidType;
244extern ipc_type_t *itRequestPortType;
245extern ipc_type_t *itZeroReplyPortType;
246extern ipc_type_t *itRealReplyPortType;
247extern ipc_type_t *itWaitTimeType;
248extern ipc_type_t *itMsgOptionType;
249extern ipc_type_t *itMakeCountType();
250extern ipc_type_t *itMakeSubCountType();
251extern ipc_type_t *itMakePolyType();
252extern ipc_type_t *itMakeDeallocType();
253
254extern void init_type();
255
256extern void itCheckReturnType(/* identifier_t name, ipc_type_t *it */);
257extern void itCheckRequestPortType(/* identifier_t name, ipc_type_t *it */);
258extern void itCheckReplyPortType(/* identifier_t name, ipc_type_t *it */);
259extern void itCheckIntType(/* identifier_t name, ipc_type_t *it */);
260extern void itCheckTokenType(/* identifier_t name, ipc_type_t *it */);
261
262#endif /* _TYPE_H */
263