]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/ndr.h
64ce2a60afd06f282e20aceef9d8c321c09cfd26
[apple/xnu.git] / osfmk / mach / ndr.h
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28
29 #ifndef _MACH_NDR_H_
30 #define _MACH_NDR_H_
31
32 #include <stdint.h>
33
34 typedef struct {
35 unsigned char mig_vers;
36 unsigned char if_vers;
37 unsigned char reserved1;
38 unsigned char mig_encoding;
39 unsigned char int_rep;
40 unsigned char char_rep;
41 unsigned char float_rep;
42 unsigned char reserved2;
43 } NDR_record_t;
44
45 /*
46 * MIG supported protocols for Network Data Representation
47 */
48 #define NDR_PROTOCOL_2_0 0
49
50 /*
51 * NDR 2.0 format flag type definition and values.
52 */
53 #define NDR_INT_BIG_ENDIAN 0
54 #define NDR_INT_LITTLE_ENDIAN 1
55 #define NDR_FLOAT_IEEE 0
56 #define NDR_FLOAT_VAX 1
57 #define NDR_FLOAT_CRAY 2
58 #define NDR_FLOAT_IBM 3
59 #define NDR_CHAR_ASCII 0
60 #define NDR_CHAR_EBCDIC 1
61
62 extern NDR_record_t NDR_record;
63
64 #ifndef __NDR_convert__
65 #define __NDR_convert__ 1
66 #endif /* __NDR_convert__ */
67
68 #ifndef __NDR_convert__int_rep__
69 #define __NDR_convert__int_rep__ 1
70 #endif /* __NDR_convert__int_rep__ */
71
72 #ifndef __NDR_convert__char_rep__
73 #define __NDR_convert__char_rep__ 0
74 #endif /* __NDR_convert__char_rep__ */
75
76 #ifndef __NDR_convert__float_rep__
77 #define __NDR_convert__float_rep__ 0
78 #endif /* __NDR_convert__float_rep__ */
79
80 #if __NDR_convert__
81
82 #define __NDR_convert__NOOP do ; while (0)
83 #define __NDR_convert__UNKNOWN(s) __NDR_convert__NOOP
84 #define __NDR_convert__SINGLE(a, f, r) do { r((a), (f)); } while (0)
85 #define __NDR_convert__ARRAY(a, f, c, r) \
86 do { int __i__, __C__ = (c); \
87 for (__i__ = 0; __i__ < __C__; __i__++) \
88 r(&(a)[__i__], f); } while (0)
89 #define __NDR_convert__2DARRAY(a, f, s, c, r) \
90 do { int __i__, __C__ = (c), __S__ = (s); \
91 for (__i__ = 0; __i__ < __C__; __i__++) \
92 r(&(a)[__i__ * __S__], f, __S__); } while (0)
93
94 #if __NDR_convert__int_rep__
95
96 #include <libkern/OSByteOrder.h>
97
98 #define __NDR_READSWAP_assign(a, rs) do { *(a) = rs(a); } while (0)
99
100 #define __NDR_READSWAP__uint16_t(a) OSReadSwapInt16((void *)a, 0)
101 #define __NDR_READSWAP__int16_t(a) (int16_t)OSReadSwapInt16((void *)a, 0)
102 #define __NDR_READSWAP__uint32_t(a) OSReadSwapInt32((void *)a, 0)
103 #define __NDR_READSWAP__int32_t(a) (int32_t)OSReadSwapInt32((void *)a, 0)
104 #define __NDR_READSWAP__uint64_t(a) OSReadSwapInt64((void *)a, 0)
105 #define __NDR_READSWAP__int64_t(a) (int64_t)OSReadSwapInt64((void *)a, 0)
106
107 static __inline__ float __NDR_READSWAP__float(float *argp) {
108 union {
109 float sv;
110 uint32_t ull;
111 } result;
112 result.ull = __NDR_READSWAP__uint32_t((uint32_t *)argp);
113 return result.sv;
114 }
115
116 static __inline__ double __NDR_READSWAP__double(double *argp) {
117 union {
118 double sv;
119 uint64_t ull;
120 } result;
121 result.ull = __NDR_READSWAP__uint64_t((uint64_t *)argp);
122 return result.sv;
123 }
124
125 #define __NDR_convert__int_rep__int16_t__defined
126 #define __NDR_convert__int_rep__int16_t(v,f) \
127 __NDR_READSWAP_assign(v, __NDR_READSWAP__int16_t)
128
129 #define __NDR_convert__int_rep__uint16_t__defined
130 #define __NDR_convert__int_rep__uint16_t(v,f) \
131 __NDR_READSWAP_assign(v, __NDR_READSWAP__uint16_t)
132
133 #define __NDR_convert__int_rep__int32_t__defined
134 #define __NDR_convert__int_rep__int32_t(v,f) \
135 __NDR_READSWAP_assign(v, __NDR_READSWAP__int32_t)
136
137 #define __NDR_convert__int_rep__uint32_t__defined
138 #define __NDR_convert__int_rep__uint32_t(v,f) \
139 __NDR_READSWAP_assign(v, __NDR_READSWAP__uint32_t)
140
141 #define __NDR_convert__int_rep__int64_t__defined
142 #define __NDR_convert__int_rep__int64_t(v,f) \
143 __NDR_READSWAP_assign(v, __NDR_READSWAP__int64_t)
144
145 #define __NDR_convert__int_rep__uint64_t__defined
146 #define __NDR_convert__int_rep__uint64_t(v,f) \
147 __NDR_READSWAP_assign(v, __NDR_READSWAP__uint64_t)
148
149 #define __NDR_convert__int_rep__float__defined
150 #define __NDR_convert__int_rep__float(v,f) \
151 __NDR_READSWAP_assign(v, __NDR_READSWAP__float)
152
153 #define __NDR_convert__int_rep__double__defined
154 #define __NDR_convert__int_rep__double(v,f) \
155 __NDR_READSWAP_assign(v, __NDR_READSWAP__double)
156
157 #define __NDR_convert__int_rep__boolean_t__defined
158 #define __NDR_convert__int_rep__boolean_t(v, f) \
159 __NDR_convert__int_rep__int32_t(v,f)
160
161 #define __NDR_convert__int_rep__kern_return_t__defined
162 #define __NDR_convert__int_rep__kern_return_t(v,f) \
163 __NDR_convert__int_rep__int32_t(v,f)
164
165 #define __NDR_convert__int_rep__mach_port_name_t__defined
166 #define __NDR_convert__int_rep__mach_port_name_t(v,f) \
167 __NDR_convert__int_rep__uint32_t(v,f)
168
169 #define __NDR_convert__int_rep__mach_msg_type_number_t__defined
170 #define __NDR_convert__int_rep__mach_msg_type_number_t(v,f) \
171 __NDR_convert__int_rep__uint32_t(v,f)
172
173 #endif /* __NDR_convert__int_rep__ */
174
175 #if __NDR_convert__char_rep__
176
177 #warning NDR character representation conversions not implemented yet!
178 #define __NDR_convert__char_rep__char(v,f) __NDR_convert__NOOP
179 #define __NDR_convert__char_rep__string(v,f,l) __NDR_convert__NOOP
180
181 #endif /* __NDR_convert__char_rep__ */
182
183 #if __NDR_convert__float_rep__
184
185 #warning NDR floating point representation conversions not implemented yet!
186 #define __NDR_convert__float_rep__float(v,f) __NDR_convert__NOOP
187 #define __NDR_convert__float_rep__double(v,f) __NDR_convert__NOOP
188
189 #endif /* __NDR_convert__float_rep__ */
190
191 #endif /* __NDR_convert__ */
192
193 #endif /* _MACH_NDR_H_ */