1
/*********************************************************
2
* Copyright (C) 1998-2008 VMware, Inc. All rights reserved.
4
* The contents of this file are subject to the terms of the Common
5
* Development and Distribution License (the "License") version 1.0
6
* and no later version. You may not use this file except in
7
* compliance with the License.
9
* You can obtain a copy of the License at
10
* http://www.opensource.org/licenses/cddl1.php
12
* See the License for the specific language governing permissions
13
* and limitations under the License.
15
*********************************************************/
25
#ifndef _VM_BASIC_TYPES_H_
26
#define _VM_BASIC_TYPES_H_
28
#define INCLUDE_ALLOW_USERLEVEL
29
#define INCLUDE_ALLOW_VMMEXT
30
#define INCLUDE_ALLOW_MODULE
31
#define INCLUDE_ALLOW_VMMON
32
#define INCLUDE_ALLOW_VMNIXMOD
33
#define INCLUDE_ALLOW_VMKERNEL
34
#define INCLUDE_ALLOW_VMKDRIVERS
35
#define INCLUDE_ALLOW_VMK_MODULE
36
#define INCLUDE_ALLOW_DISTRIBUTE
37
#define INCLUDE_ALLOW_VMCORE
38
#define INCLUDE_ALLOW_VMIROM
39
#include "includeCheck.h"
41
/* STRICT ANSI means the Xserver build and X defines Bool differently. */
42
#if !defined(__STRICT_ANSI__) || defined(__FreeBSD__)
54
#define IsBool(x) (((x) & ~1) == 0)
55
#define IsBool2(x, y) ((((x) | (y)) & ~1) == 0)
58
* Macros __i386__ and __ia64 are intrinsically defined by GCC
79
/* safe assumption for a while */
85
#pragma warning (3 :4505) // unreferenced local function
86
#pragma warning (disable :4018) // signed/unsigned mismatch
87
#pragma warning (disable :4761) // integral size mismatch in argument; conversion supplied
88
#pragma warning (disable :4305) // truncation from 'const int' to 'short'
89
#pragma warning (disable :4244) // conversion from 'unsigned short' to 'unsigned char'
90
#pragma warning (disable :4267) // truncation of 'size_t'
91
#pragma warning (disable :4146) // unary minus operator applied to unsigned type, result still unsigned
92
#pragma warning (disable :4142) // benign redefinition of type
96
#if defined(__APPLE__) || defined(HAVE_STDINT_H)
99
* TODO: This is a C99 standard header. We should be able to test for
100
* #if __STDC_VERSION__ >= 199901L, but that breaks the Netware build
101
* (which doesn't have stdint.h).
106
typedef uint64_t uint64;
107
typedef int64_t int64;
108
typedef uint32_t uint32;
109
typedef int32_t int32;
110
typedef uint16_t uint16;
111
typedef int16_t int16;
112
typedef uint8_t uint8;
115
* XXX: int8_t is defined to be 'signed char' on Mac hosts.
117
* Unfortunately, GCC 4.0.1 warns when doing pointer assignment or
118
* comparison between signed char * and char * (even if char is
121
* If we want to use int8_t to define int8, we need to go through and
122
* replace uses of char * with signed char * to prevent warnings.
126
#else /* !HAVE_STDINT_H */
130
typedef unsigned __int64 uint64;
131
typedef signed __int64 int64;
134
/* The Xserver source compiles with -ansi -pendantic */
135
#ifndef __STRICT_ANSI__
136
#if defined(VM_X86_64)
137
typedef unsigned long uint64;
140
typedef unsigned long long uint64;
141
typedef long long int64;
144
typedef unsigned long long uint64;
145
typedef long long int64;
148
#error - Need compiler define for int64/uint64
149
#endif /* _MSC_VER */
151
typedef unsigned int uint32;
152
typedef unsigned short uint16;
153
typedef unsigned char uint8;
159
#endif /* HAVE_STDINT_H */
162
* FreeBSD (for the tools build) unconditionally defines these in
163
* sys/inttypes.h so don't redefine them if this file has already
164
* been included. [greg]
166
* This applies to Solaris as well.
170
* Before trying to do the includes based on OS defines, see if we can use
171
* feature-based defines to get as much functionality as possible
174
#ifdef HAVE_INTTYPES_H
175
#include <inttypes.h>
177
#ifdef HAVE_SYS_TYPES_H
178
#include <sys/types.h>
180
#ifdef HAVE_SYS_INTTYPES_H
181
#include <sys/inttypes.h>
188
#include <sys/param.h> /* For __FreeBSD_version */
191
#if !defined(USING_AUTOCONF)
192
# if defined(__FreeBSD__) || defined(sun)
194
# include <sys/types.h>
196
# if !defined(VMKERNEL) && (__FreeBSD_version >= 500043)
197
# include <inttypes.h>
198
# include <sys/types.h>
200
# include <sys/inttypes.h>
203
# elif defined __APPLE__
205
# include <sys/unistd.h>
206
# include <sys/types.h> /* mostly for size_t */
210
# include <inttypes.h>
215
# if !defined(__intptr_t_defined) && !defined(intptr_t)
216
# define __intptr_t_defined
217
# define intptr_t intptr_t
220
typedef int64 intptr_t;
222
typedef int32 intptr_t;
230
typedef uint64 uintptr_t;
232
typedef uint32 uintptr_t;
242
* XXX These should be cleaned up. -- edward
245
typedef int64 VmTimeType; /* Time in microseconds */
246
typedef int64 VmTimeRealClock; /* Real clock kept in microseconds */
247
typedef int64 VmTimeVirtualClock; /* Virtual Clock kept in CPU cycles */
250
* Printf format specifiers for size_t and 64-bit number.
251
* Use them like this:
252
* printf("%"FMT64"d\n", big);
254
* FMTH is for handles/fds.
268
#elif defined __APPLE__
269
/* Mac OS hosts use the same formatters for 32- and 64-bit. */
276
#if defined(N_PLAT_NLM) || defined(sun) || \
277
(defined(__FreeBSD__) && (__FreeBSD__ + 0) && ((__FreeBSD__ + 0) < 5))
279
* Why (__FreeBSD__ + 0)? See bug 141008.
280
* Yes, we really need to test both (__FreeBSD__ + 0) and
281
* ((__FreeBSD__ + 0) < 5). No, we can't remove "+ 0" from
282
* ((__FreeBSD__ + 0) < 5).
291
#elif defined(__linux__) \
292
|| (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) \
293
|| (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) \
294
|| (defined(_POSIX2_VERSION) && _POSIX2_VERSION >= 200112L)
298
#if defined(VM_X86_64)
304
/* Systems with a pre-C99 libc */
314
#elif defined(sun) || defined(__FreeBSD__)
320
#error - Need compiler define for FMT64 and FMTSZ
324
* Suffix for 64-bit constants. Use it like this:
325
* CONST64(0x7fffffffffffffff) for signed or
326
* CONST64U(0x7fffffffffffffff) for unsigned.
329
* The vmcore/asm64/gen* programs are compiled as 32-bit
330
* applications, but must handle 64 bit constants. If the
331
* 64-bit-constant defining macros are already defined, the
332
* definition will not be overwritten.
335
#if !defined(CONST64) || !defined(CONST64U)
337
#define CONST64(c) c##I64
338
#define CONST64U(c) c##uI64
339
#elif defined __APPLE__
340
#define CONST64(c) c##LL
341
#define CONST64U(c) c##uLL
344
#define CONST64(c) c##L
345
#define CONST64U(c) c##uL
347
#define CONST64(c) c##LL
348
#define CONST64U(c) c##uLL
351
#error - Need compiler define for CONST64
356
* Use CONST3264/CONST3264U if you want a constant to be
357
* treated as a 32-bit number on 32-bit compiles and
358
* a 64-bit number on 64-bit compiles. Useful in the case
359
* of shifts, like (CONST3264U(1) << x), where x could be
360
* more than 31 on a 64-bit compile.
364
#define CONST3264(a) CONST64(a)
365
#define CONST3264U(a) CONST64U(a)
367
#define CONST3264(a) (a)
368
#define CONST3264U(a) (a)
371
#define MIN_INT32 ((int32)0x80000000)
372
#define MAX_INT32 ((int32)0x7fffffff)
374
#define MIN_UINT32 ((uint32)0)
375
#define MAX_UINT32 ((uint32)0xffffffff)
377
#define MIN_INT64 (CONST64(0x8000000000000000))
378
#define MAX_INT64 (CONST64(0x7fffffffffffffff))
380
#define MIN_UINT64 (CONST64U(0))
381
#define MAX_UINT64 (CONST64U(0xffffffffffffffff))
383
typedef uint8 *TCA; /* Pointer into TC (usually). */
386
* Type big enough to hold an integer between 0..100
388
typedef uint8 Percent;
389
#define AsPercent(v) ((Percent)(v))
390
#define CHOOSE_PERCENT AsPercent(101)
393
typedef uintptr_t VA;
394
typedef uintptr_t VPN;
399
typedef uint64 PhysMemOff;
400
typedef uint64 PhysMemSize;
402
/* The Xserver source compiles with -ansi -pendantic */
403
#ifndef __STRICT_ANSI__
407
typedef uint32 PageNum;
408
typedef unsigned MemHandle;
409
typedef int32 World_ID;
411
#define INVALID_WORLD_ID ((World_ID)-1)
413
typedef World_ID User_CartelID;
414
#define INVALID_CARTEL_ID INVALID_WORLD_ID
416
typedef User_CartelID User_SessionID;
417
#define INVALID_SESSION_ID INVALID_CARTEL_ID
419
typedef User_CartelID User_CartelGroupID;
420
#define INVALID_CARTELGROUP_ID INVALID_CARTEL_ID
422
typedef uint32 Worldlet_ID;
423
#define INVALID_WORLDLET_ID ((Worldlet_ID)-1)
425
/* world page number */
428
/* The Xserver source compiles with -ansi -pendantic */
429
#ifndef __STRICT_ANSI__
435
* This type should be used for variables that contain sector
438
typedef uint64 SectorType;
444
typedef uintptr_t LA;
445
typedef uintptr_t LPN;
446
#define LA_2_LPN(_la) ((_la) >> PAGE_SHIFT)
447
#define LPN_2_LA(_lpn) ((_lpn) << PAGE_SHIFT)
449
#define LAST_LPN ((((LA) 1) << (8 * sizeof(LA) - PAGE_SHIFT)) - 1)
450
#define LAST_LPN32 ((((LA32)1) << (8 * sizeof(LA32) - PAGE_SHIFT)) - 1)
451
#define LAST_LPN64 ((((LA64)1) << (8 * sizeof(LA64) - PAGE_SHIFT)) - 1)
453
/* Valid bits in a LPN. */
454
#define LPN_MASK LAST_LPN
455
#define LPN_MASK32 LAST_LPN32
456
#define LPN_MASK64 LAST_LPN64
459
* On 64 bit platform, address and page number types default
460
* to 64 bit. When we need to represent a 32 bit address, we use
461
* types defined below.
463
* On 32 bit platform, the following types are the same as the
467
typedef uint32 VPN32;
469
typedef uint32 LPN32;
471
typedef uint32 PPN32;
473
typedef uint32 MPN32;
476
* On 64 bit platform, the following types are the same as the
480
typedef uint64 VPN64;
482
typedef uint64 LPN64;
484
typedef uint64 PPN64;
486
typedef uint64 MPN64;
489
* VA typedefs for user world apps.
491
typedef VA32 UserVA32;
492
typedef VA64 UserVA64;
493
typedef UserVA64 UserVAConst; /* Userspace ptr to data that we may only read. */
494
typedef UserVA32 UserVA32Const; /* Userspace ptr to data that we may only read. */
495
typedef UserVA64 UserVA64Const; /* Used by 64-bit syscalls until conversion is finished. */
497
typedef UserVA64 UserVA;
499
typedef void * UserVA;
504
* Maximal possible PPN value (errors too) that PhysMem can handle.
505
* Must be at least as large as MAX_PPN which is the maximum PPN
506
* for any region other than buserror.
508
#define PHYSMEM_MAX_PPN ((PPN)0xffffffff)
509
#define MAX_PPN ((PPN)0x1fffffff) /* Maximal observable PPN value. */
510
#define INVALID_PPN ((PPN)0xffffffff)
512
#define INVALID_BPN ((BPN) 0x1fffffff)
514
#define INVALID_MPN ((MPN)-1)
515
#define MEMREF_MPN ((MPN)-2)
516
#define RESERVED_MPN ((MPN) 0)
517
/* Support 43 bits of address space. */
518
#define MAX_MPN ((MPN)0x7fffffff)
520
#define INVALID_LPN ((LPN)-1)
521
#define INVALID_VPN ((VPN)-1)
522
#define INVALID_LPN64 ((LPN64)-1)
523
#define INVALID_PAGENUM ((PageNum)-1)
524
#define INVALID_WPN ((WPN) -1)
528
* Format modifier for printing VA, LA, and VPN.
529
* Use them like this: Log("%#"FMTLA"x\n", laddr)
532
#if defined(VMM64) || defined(FROBOS64) || vm_x86_64 || defined __APPLE__
543
#define EXTERN extern
550
# define INLINE __inline
552
# define INLINE inline
558
* Annotation for data that may be exported into a DLL and used by other
559
* apps that load that DLL and import the data.
561
#if defined(_WIN32) && defined(VMX86_IMPORT_DLLDATA)
562
# define VMX86_EXTERN_DATA extern __declspec(dllimport)
564
# define VMX86_EXTERN_DATA extern
567
#if defined(_WIN32) && !defined(VMX86_NO_THREADS)
568
#define THREADSPECIFIC __declspec(thread)
570
#define THREADSPECIFIC
574
* Due to the wonderful "registry redirection" feature introduced in
575
* 64-bit Windows, if you access any key under HKLM\Software in 64-bit
576
* code, you need to open/create/delete that key with
577
* VMKEY_WOW64_32KEY if you want a consistent view with 32-bit code.
582
#define VMW_KEY_WOW64_32KEY KEY_WOW64_32KEY
584
#define VMW_KEY_WOW64_32KEY 0x0
590
* Consider the following reasons functions are inlined:
592
* 1) inlined for performance reasons
593
* 2) inlined because it's a single-use function
595
* Functions which meet only condition 2 should be marked with this
596
* inline macro; It is not critical to be inlined (but there is a
597
* code-space & runtime savings by doing so), so when other callers
598
* are added the inline-ness should be removed.
601
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
603
* Starting at version 3.3, gcc does not always inline functions marked
604
* 'inline' (it depends on their size). To force gcc to do so, one must use the
605
* extra __always_inline__ attribute.
607
# define INLINE_SINGLE_CALLER INLINE __attribute__((__always_inline__))
609
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 1))
610
# warning Verify INLINE_SINGLE_CALLER '__always_inline__' attribute (did \
611
monitor size change?)
614
# define INLINE_SINGLE_CALLER INLINE
618
* Used when a hard guaranteed of no inlining is needed. Very few
619
* instances need this since the absence of INLINE is a good hint
620
* that gcc will not do inlining.
623
#if defined(__GNUC__) && defined(VMM)
624
#define ABSOLUTELY_NOINLINE __attribute__((__noinline__))
628
* Attributes placed on function declarations to tell the compiler
629
* that the function never returns.
633
#define NORETURN __declspec(noreturn)
634
#elif __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 9)
635
#define NORETURN __attribute__((__noreturn__))
641
* GCC 3.2 inline asm needs the + constraint for input/ouput memory operands.
642
* Older GCCs don't know about it --hpreg
645
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
646
# define VM_ASM_PLUS 1
648
# define VM_ASM_PLUS 0
652
* Branch prediction hints:
653
* LIKELY(exp) - Expression exp is likely TRUE.
654
* UNLIKELY(exp) - Expression exp is likely FALSE.
656
* if (LIKELY(excCode == EXC_NONE)) {
658
* if (UNLIKELY(REAL_MODE(vc))) {
660
* We know how to predict branches on gcc3 and later (hopefully),
661
* all others we don't so we do nothing.
666
* gcc3 uses __builtin_expect() to inform the compiler of an expected value.
667
* We use this to inform the static branch predictor. The '!!' in LIKELY
668
* will convert any !=0 to a 1.
670
#define LIKELY(_exp) __builtin_expect(!!(_exp), 1)
671
#define UNLIKELY(_exp) __builtin_expect((_exp), 0)
673
#define LIKELY(_exp) (_exp)
674
#define UNLIKELY(_exp) (_exp)
678
* GCC's argument checking for printf-like functions
679
* This is conditional until we have replaced all `"%x", void *'
680
* with `"0x%08x", (uint32) void *'. Note that %p prints different things
681
* on different platforms. Argument checking is enabled for the
682
* vmkernel, which has already been cleansed.
684
* fmtPos is the position of the format string argument, beginning at 1
685
* varPos is the position of the variable argument, beginning at 1
688
#if defined(__GNUC__)
689
# define PRINTF_DECL(fmtPos, varPos) __attribute__((__format__(__printf__, fmtPos, varPos)))
691
# define PRINTF_DECL(fmtPos, varPos)
694
#if defined(__GNUC__)
695
# define SCANF_DECL(fmtPos, varPos) __attribute__((__format__(__scanf__, fmtPos, varPos)))
697
# define SCANF_DECL(fmtPos, varPos)
701
* UNUSED_PARAM should surround the parameter name and type declaration,
702
* e.g. "int MyFunction(int var1, UNUSED_PARAM(int var2))"
707
# if defined(__GNUC__)
708
# define UNUSED_PARAM(_parm) _parm __attribute__((__unused__))
710
# define UNUSED_PARAM(_parm) _parm
715
* REGPARM defaults to REGPARM3, i.e., a requent that gcc
716
* puts the first three arguments in registers. (It is fine
717
* if the function has fewer than three args.) Gcc only.
718
* Syntactically, put REGPARM where you'd put INLINE or NORETURN.
721
#if defined(__GNUC__)
722
# define REGPARM0 __attribute__((regparm(0)))
723
# define REGPARM1 __attribute__((regparm(1)))
724
# define REGPARM2 __attribute__((regparm(2)))
725
# define REGPARM3 __attribute__((regparm(3)))
726
# define REGPARM REGPARM3
736
* ALIGNED specifies minimum alignment in "n" bytes.
740
#define ALIGNED(n) __attribute__((__aligned__(n)))
746
***********************************************************************
747
* STRUCT_OFFSET_CHECK -- */ /**
749
* \brief Check if the actual offsef of a member in a structure
750
* is what is expected
753
* \param[in] STRUCT Structure the member is a part of.
754
* \param[in] MEMBER Member to check the offset of.
755
* \param[in] OFFSET Expected offset of MEMBER in STRUCTURE.
756
* \param[in] DEBUG_EXTRA Additional bytes to be added to OFFSET to
757
* compensate for extra info in debug builds.
759
***********************************************************************
762
#define STRUCT_OFFSET_CHECK(STRUCT, MEMBER, OFFSET, DEBUG_EXTRA) \
763
ASSERT_ON_COMPILE(vmk_offsetof(STRUCT, MEMBER) == (OFFSET + DEBUG_EXTRA))
765
#define STRUCT_OFFSET_CHECK(STRUCT, MEMBER, OFFSET, DEBUG_EXTRA) \
766
ASSERT_ON_COMPILE(vmk_offsetof(STRUCT, MEMBER) == OFFSET)
770
***********************************************************************
771
* STRUCT_SIZE_CHECK -- */ /**
773
* \brief Check if the actual size of a structure is what is expected
776
* \param[in] STRUCT Structure whose size is to be checked.
777
* \param[in] SIZE Expected size of STRUCT.
778
* \param[in] DEBUG_EXTRA Additional bytes to be added to SIZE to
779
* compensate for extra info in debug builds.
781
***********************************************************************
784
#define STRUCT_SIZE_CHECK(STRUCT, SIZE, DEBUG_EXTRA) \
785
ASSERT_ON_COMPILE(sizeof(STRUCT) == (SIZE + DEBUG_EXTRA))
787
#define STRUCT_SIZE_CHECK(STRUCT, SIZE, DEBUG_EXTRA) \
788
ASSERT_ON_COMPILE(sizeof(STRUCT) == SIZE)
792
* __func__ is a stringified function name that is part of the C99 standard. The block
793
* below defines __func__ on older systems where the compiler does not support that
796
#if defined(__GNUC__) \
797
&& ((__GNUC__ == 2 && __GNUC_MINOR < 96) \
799
# define __func__ __FUNCTION__
803
* Once upon a time, this was used to silence compiler warnings that
804
* get generated when the compiler thinks that a function returns
805
* when it is marked noreturn. Don't do it. Use NOT_REACHED().
808
#define INFINITE_LOOP() do { } while (1)
811
* On FreeBSD (for the tools build), size_t is typedef'd if _BSD_SIZE_T_
812
* is defined. Use the same logic here so we don't define it twice. [greg]
819
typedef uint64 size_t;
821
typedef uint32 size_t;
823
# endif /* VM_I386 */
826
# ifdef _BSD_SSIZE_T_
827
# undef _BSD_SSIZE_T_
829
# define __ssize_t_defined
830
# define _SSIZE_T_DECLARED
833
typedef int64 ssize_t;
835
typedef int32 ssize_t;
837
# endif /* VM_I386 */
845
typedef uint64 size_t;
847
typedef uint32 size_t;
849
# endif /* VM_I386 */
852
# if !defined(FROBOS) && !defined(_SSIZE_T) && !defined(ssize_t) && \
853
!defined(__ssize_t_defined) && !defined(_SSIZE_T_DECLARED)
855
# define __ssize_t_defined
856
# define _SSIZE_T_DECLARED
859
typedef int64 ssize_t;
861
typedef int32 ssize_t;
863
# endif /* VM_I386 */
869
* Format modifier for printing pid_t. On sun the pid_t is a ulong, but on
871
* Use this like this: printf("The pid is %"FMTPID".\n", pid);
884
* Format modifier for printing uid_t. On Solaris 10 and earlier, uid_t
885
* is a ulong, but on other platforms it's an unsigned int.
886
* Use this like this: printf("The uid is %"FMTUID".\n", uid);
888
#if defined(sun) && !defined(SOL11)
899
* Format modifier for printing mode_t. On sun the mode_t is a ulong, but on
901
* Use this like this: printf("The mode is %"FMTMODE".\n", mode);
907
# define FMTMODE "lo"
914
* Format modifier for printing time_t. Most platforms define a time_t to be
915
* a long int, but on FreeBSD (as of 5.0, it seems), the time_t is a signed
916
* size quantity. Refer to the definition of FMTSZ to see why we need silly
917
* preprocessor arithmetic.
918
* Use this like this: printf("The mode is %"FMTTIME".\n", time);
920
#if defined(__FreeBSD__) && (__FreeBSD__ + 0) && ((__FreeBSD__ + 0) >= 5)
921
# define FMTTIME FMTSZ"d"
923
# define FMTTIME "ld"
927
* Define MXSemaHandle here so both vmmon and vmx see this definition.
931
typedef uintptr_t MXSemaHandle;
933
typedef int MXSemaHandle;
937
* Define type for poll device handles.
941
typedef uintptr_t PollDevHandle;
943
typedef int PollDevHandle;
947
* Define the utf16_t type.
950
#if defined(_WIN32) && defined(_NATIVE_WCHAR_T_DEFINED)
951
typedef wchar_t utf16_t;
953
typedef uint16 utf16_t;
956
#endif /* _VM_BASIC_TYPES_H_ */