1 | /* $Id: sanity.h 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Setup Sanity Checks, C and C++.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include <iprt/cdefs.h>
|
---|
28 | #include <iprt/types.h>
|
---|
29 | #include <iprt/assert.h>
|
---|
30 |
|
---|
31 | /*
|
---|
32 | * Check that the IN_[RING3|RING0|GC] and [|R3_|R0_|GC_]ARCH_BITS
|
---|
33 | * match up correctly.
|
---|
34 | *
|
---|
35 | * IPRT assumes r0 and r3 to has the same bit count.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #if defined(IN_RING3) && ARCH_BITS != R3_ARCH_BITS
|
---|
39 | # error "defined(IN_RING3) && ARCH_BITS != R3_ARCH_BITS"
|
---|
40 | #endif
|
---|
41 | #if defined(IN_RING0) && ARCH_BITS != R0_ARCH_BITS
|
---|
42 | # error "defined(IN_RING0) && ARCH_BITS != R0_ARCH_BITS"
|
---|
43 | #endif
|
---|
44 | #if defined(IN_RC) && ARCH_BITS != 32
|
---|
45 | # error "defined(IN_RC) && ARCH_BITS != 32"
|
---|
46 | #endif
|
---|
47 | #if (defined(IN_RING0) || defined(IN_RING3)) && HC_ARCH_BITS != ARCH_BITS
|
---|
48 | # error "(defined(IN_RING0) || defined(IN_RING3)) && HC_ARCH_BITS != ARCH_BITS"
|
---|
49 | #endif
|
---|
50 | #if defined(IN_RC) && GC_ARCH_BITS != 64 && GC_ARCH_BITS != ARCH_BITS
|
---|
51 | # error "defined(IN_RC) && GC_ARCH_BITS != ARCH_BITS"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * Check basic host (hc/r0/r3) types.
|
---|
57 | */
|
---|
58 | #if HC_ARCH_BITS == 64
|
---|
59 |
|
---|
60 | AssertCompileSize(RTHCPTR, 8);
|
---|
61 | AssertCompileSize(RTHCINT, 4);
|
---|
62 | AssertCompileSize(RTHCUINT, 4);
|
---|
63 | AssertCompileSize(RTHCINTPTR, 8);
|
---|
64 | AssertCompileSize(RTHCUINTPTR, 8);
|
---|
65 | /*AssertCompileSize(RTHCINTREG, 8);*/
|
---|
66 | AssertCompileSize(RTHCUINTREG, 8);
|
---|
67 | AssertCompileSize(RTR0PTR, 8);
|
---|
68 | /*AssertCompileSize(RTR0INT, 4);*/
|
---|
69 | /*AssertCompileSize(RTR0UINT, 4);*/
|
---|
70 | AssertCompileSize(RTR0INTPTR, 8);
|
---|
71 | AssertCompileSize(RTR0UINTPTR, 8);
|
---|
72 | /*AssertCompileSize(RTR3PTR, 8);*/
|
---|
73 | /*AssertCompileSize(RTR3INT, 4);*/
|
---|
74 | /*AssertCompileSize(RTR3UINT, 4);*/
|
---|
75 | AssertCompileSize(RTR3INTPTR, 8);
|
---|
76 | AssertCompileSize(RTR3UINTPTR, 8);
|
---|
77 | AssertCompileSize(RTUINTPTR, 8);
|
---|
78 |
|
---|
79 | # if defined(IN_RING3) || defined(IN_RING0)
|
---|
80 | /*AssertCompileSize(RTCCINTREG, 8);*/
|
---|
81 | AssertCompileSize(RTCCUINTREG, 8);
|
---|
82 | # endif
|
---|
83 |
|
---|
84 | #else
|
---|
85 |
|
---|
86 | AssertCompileSize(RTHCPTR, 4);
|
---|
87 | AssertCompileSize(RTHCINT, 4);
|
---|
88 | AssertCompileSize(RTHCUINT, 4);
|
---|
89 | /*AssertCompileSize(RTHCINTPTR, 4);*/
|
---|
90 | AssertCompileSize(RTHCUINTPTR, 4);
|
---|
91 | AssertCompileSize(RTR0PTR, 4);
|
---|
92 | /*AssertCompileSize(RTR0INT, 4);*/
|
---|
93 | /*AssertCompileSize(RTR0UINT, 4);*/
|
---|
94 | AssertCompileSize(RTR0INTPTR, 4);
|
---|
95 | AssertCompileSize(RTR0UINTPTR, 4);
|
---|
96 | /*AssertCompileSize(RTR3PTR, 4);*/
|
---|
97 | /*AssertCompileSize(RTR3INT, 4);*/
|
---|
98 | /*AssertCompileSize(RTR3UINT, 4);*/
|
---|
99 | AssertCompileSize(RTR3INTPTR, 4);
|
---|
100 | AssertCompileSize(RTR3UINTPTR, 4);
|
---|
101 | # if GC_ARCH_BITS == 64
|
---|
102 | AssertCompileSize(RTUINTPTR, 8);
|
---|
103 | # else
|
---|
104 | AssertCompileSize(RTUINTPTR, 4);
|
---|
105 | # endif
|
---|
106 |
|
---|
107 | # if defined(IN_RING3) || defined(IN_RING0)
|
---|
108 | /*AssertCompileSize(RTCCINTREG, 4);*/
|
---|
109 | AssertCompileSize(RTCCUINTREG, 4);
|
---|
110 | # endif
|
---|
111 |
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | AssertCompileSize(RTHCPHYS, 8);
|
---|
115 |
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * Check basic guest context types.
|
---|
119 | */
|
---|
120 | #if GC_ARCH_BITS == 64
|
---|
121 |
|
---|
122 | AssertCompileSize(RTGCINT, 8);
|
---|
123 | AssertCompileSize(RTGCUINT, 8);
|
---|
124 | AssertCompileSize(RTGCINTPTR, 8);
|
---|
125 | AssertCompileSize(RTGCUINTPTR, 8);
|
---|
126 | /*AssertCompileSize(RTGCINTREG, 8);*/
|
---|
127 | AssertCompileSize(RTGCUINTREG, 8);
|
---|
128 |
|
---|
129 | # ifdef IN_RC
|
---|
130 | /*AssertCompileSize(RTCCINTREG, 8);*/
|
---|
131 | /* Hack alert: there is no such thing as a GC context when GC_ARCH_BITS == 64; it's still 32 bits */
|
---|
132 | AssertCompileSize(RTCCUINTREG, 4);
|
---|
133 | # endif
|
---|
134 |
|
---|
135 | #else
|
---|
136 |
|
---|
137 | AssertCompileSize(RTGCINT, 4);
|
---|
138 | AssertCompileSize(RTGCUINT, 4);
|
---|
139 | AssertCompileSize(RTGCINTPTR, 4);
|
---|
140 | AssertCompileSize(RTGCUINTPTR, 4);
|
---|
141 | /*AssertCompileSize(RTGCINTREG, 4);*/
|
---|
142 | AssertCompileSize(RTGCUINTREG, 4);
|
---|
143 |
|
---|
144 | # ifdef IN_RC
|
---|
145 | /*AssertCompileSize(RTCCINTREG, 4);*/
|
---|
146 | AssertCompileSize(RTCCUINTREG, 4);
|
---|
147 | # endif
|
---|
148 |
|
---|
149 | #endif
|
---|
150 |
|
---|
151 | AssertCompileSize(RTGCPHYS64, 8);
|
---|
152 | AssertCompileSize(RTGCPHYS32, 4);
|
---|
153 | AssertCompileSize(RTGCPHYS, 8);
|
---|
154 |
|
---|
155 |
|
---|
156 | /*
|
---|
157 | * Check basic current context types.
|
---|
158 | */
|
---|
159 | #if ARCH_BITS == 64
|
---|
160 |
|
---|
161 | AssertCompileSize(void *, 8);
|
---|
162 | AssertCompileSize(intptr_t, 8);
|
---|
163 | AssertCompileSize(uintptr_t, 8);
|
---|
164 | AssertCompileSize(size_t, 8);
|
---|
165 | AssertCompileSize(ssize_t, 8);
|
---|
166 |
|
---|
167 | #else
|
---|
168 |
|
---|
169 | AssertCompileSize(void *, 4);
|
---|
170 | AssertCompileSize(intptr_t, 4);
|
---|
171 | AssertCompileSize(uintptr_t, 4);
|
---|
172 | AssertCompileSize(size_t, 4);
|
---|
173 | AssertCompileSize(ssize_t, 4);
|
---|
174 |
|
---|
175 | #endif
|
---|
176 |
|
---|
177 |
|
---|
178 | /*
|
---|
179 | * Standard sized types.
|
---|
180 | */
|
---|
181 | AssertCompileSize(uint8_t, 1);
|
---|
182 | AssertCompileSize(uint16_t, 2);
|
---|
183 | AssertCompileSize(uint32_t, 4);
|
---|
184 | AssertCompileSize(uint64_t, 8);
|
---|
185 |
|
---|
186 | #define TEST_CONST_MACRO(c,t) \
|
---|
187 | AssertCompile(sizeof(c) == sizeof(t) || (sizeof(c) == sizeof(int) && sizeof(t) < sizeof(int)) )
|
---|
188 |
|
---|
189 | TEST_CONST_MACRO(UINT8_C(1), uint8_t);
|
---|
190 | TEST_CONST_MACRO(UINT16_C(1), uint16_t);
|
---|
191 | TEST_CONST_MACRO(UINT32_C(1), uint32_t);
|
---|
192 | TEST_CONST_MACRO(UINT64_C(1), uint64_t);
|
---|
193 |
|
---|
194 | TEST_CONST_MACRO(INT8_C(1), int8_t);
|
---|
195 | TEST_CONST_MACRO(INT8_C(-1), int8_t);
|
---|
196 | TEST_CONST_MACRO(INT16_C(1), int16_t);
|
---|
197 | TEST_CONST_MACRO(INT16_C(-1), int16_t);
|
---|
198 | TEST_CONST_MACRO(INT32_C(1), int32_t);
|
---|
199 | TEST_CONST_MACRO(INT32_C(-1), int32_t);
|
---|
200 | TEST_CONST_MACRO(INT64_C(1), int64_t);
|
---|
201 | TEST_CONST_MACRO(INT64_C(-1), int64_t);
|
---|
202 |
|
---|
203 |
|
---|
204 | /*
|
---|
205 | * Our union types.
|
---|
206 | */
|
---|
207 | AssertCompileSize(RTUINT16U, 2);
|
---|
208 | AssertCompileSize(RTUINT32U, 4);
|
---|
209 | AssertCompileSize(RTUINT64U, 8);
|
---|
210 | AssertCompileSize(RTUINT128U, 16);
|
---|
211 | /*AssertCompileSize(RTFLOAT32U, 8);*/
|
---|
212 | AssertCompileSize(RTFLOAT64U, 8);
|
---|
213 | AssertCompileSize(RTFLOAT80U, 10);
|
---|
214 | /*AssertCompileSize(RTFLOAT128U, 16);*/
|
---|
215 |
|
---|