VirtualBox

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

Last change on this file since 82968 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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