VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/misc/sanity.h@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.0 KB
Line 
1/* $Id: sanity.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * IPRT - Setup Sanity Checks, C and C++.
4 */
5
6/*
7 * Copyright (C) 2007-2022 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
70AssertCompileSize(RTHCPTR, 8);
71AssertCompileSize(RTHCINT, 4);
72AssertCompileSize(RTHCUINT, 4);
73AssertCompileSize(RTHCINTPTR, 8);
74AssertCompileSize(RTHCUINTPTR, 8);
75/*AssertCompileSize(RTHCINTREG, 8);*/
76AssertCompileSize(RTHCUINTREG, 8);
77AssertCompileSize(RTR0PTR, 8);
78/*AssertCompileSize(RTR0INT, 4);*/
79/*AssertCompileSize(RTR0UINT, 4);*/
80AssertCompileSize(RTR0INTPTR, 8);
81AssertCompileSize(RTR0UINTPTR, 8);
82/*AssertCompileSize(RTR3PTR, 8);*/
83/*AssertCompileSize(RTR3INT, 4);*/
84/*AssertCompileSize(RTR3UINT, 4);*/
85AssertCompileSize(RTR3INTPTR, 8);
86AssertCompileSize(RTR3UINTPTR, 8);
87AssertCompileSize(RTUINTPTR, 8);
88
89# if defined(IN_RING3) || defined(IN_RING0)
90/*AssertCompileSize(RTCCINTREG, 8);*/
91AssertCompileSize(RTCCUINTREG, 8);
92# endif
93
94#else
95
96AssertCompileSize(RTHCPTR, 4);
97AssertCompileSize(RTHCINT, 4);
98AssertCompileSize(RTHCUINT, 4);
99/*AssertCompileSize(RTHCINTPTR, 4);*/
100AssertCompileSize(RTHCUINTPTR, 4);
101AssertCompileSize(RTR0PTR, 4);
102/*AssertCompileSize(RTR0INT, 4);*/
103/*AssertCompileSize(RTR0UINT, 4);*/
104AssertCompileSize(RTR0INTPTR, 4);
105AssertCompileSize(RTR0UINTPTR, 4);
106/*AssertCompileSize(RTR3PTR, 4);*/
107/*AssertCompileSize(RTR3INT, 4);*/
108/*AssertCompileSize(RTR3UINT, 4);*/
109AssertCompileSize(RTR3INTPTR, 4);
110AssertCompileSize(RTR3UINTPTR, 4);
111# if GC_ARCH_BITS == 64
112AssertCompileSize(RTUINTPTR, 8);
113# else
114AssertCompileSize(RTUINTPTR, 4);
115# endif
116
117# if defined(IN_RING3) || defined(IN_RING0)
118/*AssertCompileSize(RTCCINTREG, 4);*/
119AssertCompileSize(RTCCUINTREG, 4);
120# endif
121
122#endif
123
124AssertCompileSize(RTHCPHYS, 8);
125
126
127/*
128 * Check basic guest context types.
129 */
130#if GC_ARCH_BITS == 64
131
132AssertCompileSize(RTGCINT, 8);
133AssertCompileSize(RTGCUINT, 8);
134AssertCompileSize(RTGCINTPTR, 8);
135AssertCompileSize(RTGCUINTPTR, 8);
136/*AssertCompileSize(RTGCINTREG, 8);*/
137AssertCompileSize(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 */
142AssertCompileSize(RTCCUINTREG, 4);
143# endif
144
145#else
146
147AssertCompileSize(RTGCINT, 4);
148AssertCompileSize(RTGCUINT, 4);
149AssertCompileSize(RTGCINTPTR, 4);
150AssertCompileSize(RTGCUINTPTR, 4);
151/*AssertCompileSize(RTGCINTREG, 4);*/
152AssertCompileSize(RTGCUINTREG, 4);
153
154# ifdef IN_RC
155/*AssertCompileSize(RTCCINTREG, 4);*/
156AssertCompileSize(RTCCUINTREG, 4);
157# endif
158
159#endif
160
161AssertCompileSize(RTGCPHYS64, 8);
162AssertCompileSize(RTGCPHYS32, 4);
163AssertCompileSize(RTGCPHYS, 8);
164
165
166/*
167 * Check basic current context types.
168 */
169#if ARCH_BITS == 64
170
171AssertCompileSize(void *, 8);
172AssertCompileSize(intptr_t, 8);
173AssertCompileSize(uintptr_t, 8);
174AssertCompileSize(size_t, 8);
175AssertCompileSize(ssize_t, 8);
176
177#else
178
179AssertCompileSize(void *, 4);
180AssertCompileSize(intptr_t, 4);
181AssertCompileSize(uintptr_t, 4);
182AssertCompileSize(size_t, 4);
183AssertCompileSize(ssize_t, 4);
184
185#endif
186
187
188/*
189 * Standard sized types.
190 */
191AssertCompileSize(uint8_t, 1);
192AssertCompileSize(uint16_t, 2);
193AssertCompileSize(uint32_t, 4);
194AssertCompileSize(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
199TEST_CONST_MACRO(UINT8_C(1), uint8_t);
200TEST_CONST_MACRO(UINT16_C(1), uint16_t);
201TEST_CONST_MACRO(UINT32_C(1), uint32_t);
202TEST_CONST_MACRO(UINT64_C(1), uint64_t);
203
204TEST_CONST_MACRO(INT8_C(1), int8_t);
205TEST_CONST_MACRO(INT8_C(-1), int8_t);
206TEST_CONST_MACRO(INT16_C(1), int16_t);
207TEST_CONST_MACRO(INT16_C(-1), int16_t);
208TEST_CONST_MACRO(INT32_C(1), int32_t);
209TEST_CONST_MACRO(INT32_C(-1), int32_t);
210TEST_CONST_MACRO(INT64_C(1), int64_t);
211TEST_CONST_MACRO(INT64_C(-1), int64_t);
212
213
214/*
215 * Our union types.
216 */
217AssertCompileSize(RTUINT16U, 2);
218AssertCompileSize(RTUINT32U, 4);
219AssertCompileSize(RTUINT64U, 8);
220AssertCompileSize(RTUINT128U, 16);
221/*AssertCompileSize(RTFLOAT32U, 8);*/
222AssertCompileSize(RTFLOAT64U, 8);
223AssertCompileSize(RTFLOAT80U, 10);
224/*AssertCompileSize(RTFLOAT128U, 16);*/
225
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette