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