~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201207201942

« back to all changes in this revision

Viewing changes to modules/solaris/vmxnet/vm_basic_types.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-03-20 10:19:00 UTC
  • mfrom: (1.1.4 upstream) (2.4.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090320101900-1o604camiubq2de8
Tags: 2009.03.18-154848-2
Correcting patch system depends (Closes: #520493).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 1998-2008 VMware, Inc. All rights reserved.
 
3
 *
 
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.
 
8
 *
 
9
 * You can obtain a copy of the License at
 
10
 *         http://www.opensource.org/licenses/cddl1.php
 
11
 *
 
12
 * See the License for the specific language governing permissions
 
13
 * and limitations under the License.
 
14
 *
 
15
 *********************************************************/
 
16
 
 
17
/*
 
18
 *
 
19
 * vm_basic_types.h --
 
20
 *
 
21
 *    basic data types.
 
22
 */
 
23
 
 
24
 
 
25
#ifndef _VM_BASIC_TYPES_H_
 
26
#define _VM_BASIC_TYPES_H_
 
27
 
 
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"
 
40
 
 
41
/* STRICT ANSI means the Xserver build and X defines Bool differently. */
 
42
#if !defined(__STRICT_ANSI__) || defined(__FreeBSD__)
 
43
typedef char           Bool;
 
44
#endif
 
45
 
 
46
#ifndef FALSE
 
47
#define FALSE          0
 
48
#endif
 
49
 
 
50
#ifndef TRUE
 
51
#define TRUE           1
 
52
#endif
 
53
 
 
54
#define IsBool(x)      (((x) & ~1) == 0)
 
55
#define IsBool2(x, y)  ((((x) | (y)) & ~1) == 0)
 
56
 
 
57
/*
 
58
 * Macros __i386__ and __ia64 are intrinsically defined by GCC
 
59
 */
 
60
#ifdef __i386__
 
61
#define VM_I386
 
62
#endif
 
63
 
 
64
#ifdef _WIN64
 
65
#define __x86_64__
 
66
#endif
 
67
 
 
68
#ifdef __x86_64__
 
69
#define VM_X86_64
 
70
#define VM_I386
 
71
#define vm_x86_64 (1)
 
72
#else
 
73
#define vm_x86_64 (0)
 
74
#endif
 
75
 
 
76
 
 
77
 
 
78
#ifdef _WIN32
 
79
/* safe assumption for a while */
 
80
#define VM_I386
 
81
#endif
 
82
 
 
83
#ifdef _MSC_VER
 
84
 
 
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
 
93
 
 
94
#endif
 
95
 
 
96
#if defined(__APPLE__) || defined(HAVE_STDINT_H)
 
97
 
 
98
/*
 
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).
 
102
 */
 
103
 
 
104
#include <stdint.h>
 
105
 
 
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;
 
113
 
 
114
/*
 
115
 * XXX: int8_t is defined to be 'signed char' on Mac hosts.
 
116
 *
 
117
 * Unfortunately, GCC 4.0.1 warns when doing pointer assignment or
 
118
 * comparison between signed char * and char * (even if char is
 
119
 * signed).
 
120
 *
 
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.
 
123
 */
 
124
typedef char int8;
 
125
 
 
126
#else /* !HAVE_STDINT_H */
 
127
 
 
128
#ifdef _MSC_VER
 
129
 
 
130
typedef unsigned __int64 uint64;
 
131
typedef signed __int64 int64;
 
132
 
 
133
#elif __GNUC__
 
134
/* The Xserver source compiles with -ansi -pendantic */
 
135
#ifndef __STRICT_ANSI__
 
136
#if defined(VM_X86_64)
 
137
typedef unsigned long uint64;
 
138
typedef long int64;
 
139
#else
 
140
typedef unsigned long long uint64;
 
141
typedef long long int64;
 
142
#endif
 
143
#elif __FreeBSD__
 
144
typedef unsigned long long uint64;
 
145
typedef long long int64;
 
146
#endif
 
147
#else
 
148
#error - Need compiler define for int64/uint64
 
149
#endif /* _MSC_VER */
 
150
 
 
151
typedef unsigned int       uint32;
 
152
typedef unsigned short     uint16;
 
153
typedef unsigned char      uint8;
 
154
 
 
155
typedef int       int32;
 
156
typedef short     int16;
 
157
typedef char      int8;
 
158
 
 
159
#endif /* HAVE_STDINT_H */
 
160
 
 
161
/*
 
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]
 
165
 *
 
166
 * This applies to Solaris as well.
 
167
 */
 
168
 
 
169
/*
 
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
 
172
 */
 
173
 
 
174
#ifdef HAVE_INTTYPES_H
 
175
#include <inttypes.h>
 
176
#endif
 
177
#ifdef HAVE_SYS_TYPES_H
 
178
#include <sys/types.h>
 
179
#endif
 
180
#ifdef HAVE_SYS_INTTYPES_H
 
181
#include <sys/inttypes.h>
 
182
#endif
 
183
#ifdef HAVE_STDLIB_H
 
184
#include <stdlib.h>
 
185
#endif
 
186
 
 
187
#ifdef __FreeBSD__
 
188
#include <sys/param.h> /* For __FreeBSD_version */         
 
189
#endif
 
190
 
 
191
#if !defined(USING_AUTOCONF)
 
192
#   if defined(__FreeBSD__) || defined(sun)
 
193
#      ifdef KLD_MODULE
 
194
#         include <sys/types.h>
 
195
#      else
 
196
#         if !defined(VMKERNEL) && (__FreeBSD_version >= 500043)
 
197
#            include <inttypes.h>
 
198
#            include <sys/types.h>
 
199
#         else
 
200
#            include <sys/inttypes.h>
 
201
#         endif
 
202
#      endif
 
203
#   elif defined __APPLE__
 
204
#      if KERNEL
 
205
#         include <sys/unistd.h>
 
206
#         include <sys/types.h> /* mostly for size_t */
 
207
#         include <stdint.h>
 
208
#      else
 
209
#         include <unistd.h>
 
210
#         include <inttypes.h>
 
211
#         include <stdlib.h>
 
212
#         include <stdint.h>
 
213
#      endif
 
214
#   else
 
215
#      if !defined(__intptr_t_defined) && !defined(intptr_t)
 
216
#         define __intptr_t_defined
 
217
#         define intptr_t  intptr_t
 
218
#         ifdef VM_I386
 
219
#            ifdef VM_X86_64
 
220
typedef int64     intptr_t;
 
221
#            else
 
222
typedef int32     intptr_t;
 
223
#            endif
 
224
#         endif
 
225
#      endif
 
226
 
 
227
#      ifndef _STDINT_H
 
228
#         ifdef VM_I386
 
229
#            ifdef VM_X86_64
 
230
typedef uint64    uintptr_t;
 
231
#            else
 
232
typedef uint32    uintptr_t;
 
233
#            endif
 
234
#         endif
 
235
#      endif
 
236
#   endif
 
237
#endif
 
238
 
 
239
 
 
240
/*
 
241
 * Time
 
242
 * XXX These should be cleaned up.  -- edward
 
243
 */
 
244
 
 
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 */
 
248
 
 
249
/*
 
250
 * Printf format specifiers for size_t and 64-bit number.
 
251
 * Use them like this:
 
252
 *    printf("%"FMT64"d\n", big);
 
253
 *
 
254
 * FMTH is for handles/fds.
 
255
 */
 
256
 
 
257
#ifdef _MSC_VER
 
258
   #define FMT64      "I64"
 
259
   #ifdef VM_X86_64
 
260
      #define FMTSZ      "I64"
 
261
      #define FMTPD      "I64"
 
262
      #define FMTH       "I64"
 
263
   #else
 
264
      #define FMTSZ      "I"
 
265
      #define FMTPD      "I"
 
266
      #define FMTH       "I"
 
267
   #endif
 
268
#elif defined __APPLE__
 
269
   /* Mac OS hosts use the same formatters for 32- and 64-bit. */
 
270
   #define FMT64 "ll"
 
271
   #define FMTSZ "z"
 
272
   #define FMTPD "l"
 
273
   #define FMTH ""
 
274
#elif __GNUC__
 
275
   #define FMTH ""
 
276
   #if defined(N_PLAT_NLM) || defined(sun) || \
 
277
       (defined(__FreeBSD__) && (__FreeBSD__ + 0) && ((__FreeBSD__ + 0) < 5))
 
278
      /*
 
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).
 
283
       */
 
284
      #ifdef VM_X86_64
 
285
         #define FMTSZ  "l"
 
286
         #define FMTPD  "l"
 
287
      #else
 
288
         #define FMTSZ  ""
 
289
         #define FMTPD  ""
 
290
      #endif
 
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)
 
295
      /* BSD, Linux */
 
296
      #define FMTSZ     "z"
 
297
 
 
298
      #if defined(VM_X86_64)
 
299
         #define FMTPD  "l"
 
300
      #else
 
301
         #define FMTPD  ""
 
302
      #endif
 
303
   #else
 
304
      /* Systems with a pre-C99 libc */
 
305
      #define FMTSZ     "Z"
 
306
      #ifdef VM_X86_64
 
307
         #define FMTPD  "l"
 
308
      #else
 
309
         #define FMTPD  ""
 
310
      #endif
 
311
   #endif
 
312
   #ifdef VM_X86_64
 
313
      #define FMT64     "l"
 
314
   #elif defined(sun) || defined(__FreeBSD__)
 
315
      #define FMT64     "ll"
 
316
   #else
 
317
      #define FMT64     "L"
 
318
   #endif
 
319
#else
 
320
   #error - Need compiler define for FMT64 and FMTSZ
 
321
#endif
 
322
 
 
323
/*
 
324
 * Suffix for 64-bit constants.  Use it like this:
 
325
 *    CONST64(0x7fffffffffffffff) for signed or
 
326
 *    CONST64U(0x7fffffffffffffff) for unsigned.
 
327
 *
 
328
 * 2004.08.30(thutt):
 
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.
 
333
 */
 
334
 
 
335
#if !defined(CONST64) || !defined(CONST64U)
 
336
#ifdef _MSC_VER
 
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
 
342
#elif __GNUC__
 
343
#ifdef VM_X86_64
 
344
#define CONST64(c) c##L
 
345
#define CONST64U(c) c##uL
 
346
#else
 
347
#define CONST64(c) c##LL
 
348
#define CONST64U(c) c##uLL
 
349
#endif
 
350
#else
 
351
#error - Need compiler define for CONST64
 
352
#endif
 
353
#endif
 
354
 
 
355
/*
 
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.
 
361
 */
 
362
 
 
363
#ifdef VM_X86_64
 
364
    #define CONST3264(a) CONST64(a)
 
365
    #define CONST3264U(a) CONST64U(a)
 
366
#else
 
367
    #define CONST3264(a) (a)
 
368
    #define CONST3264U(a) (a)
 
369
#endif
 
370
 
 
371
#define MIN_INT32  ((int32)0x80000000)
 
372
#define MAX_INT32  ((int32)0x7fffffff)
 
373
 
 
374
#define MIN_UINT32 ((uint32)0)
 
375
#define MAX_UINT32 ((uint32)0xffffffff)
 
376
 
 
377
#define MIN_INT64  (CONST64(0x8000000000000000))
 
378
#define MAX_INT64  (CONST64(0x7fffffffffffffff))
 
379
 
 
380
#define MIN_UINT64 (CONST64U(0))
 
381
#define MAX_UINT64 (CONST64U(0xffffffffffffffff))
 
382
 
 
383
typedef uint8 *TCA;  /* Pointer into TC (usually). */
 
384
 
 
385
/*
 
386
 * Type big enough to hold an integer between 0..100
 
387
 */
 
388
typedef uint8 Percent;
 
389
#define AsPercent(v)    ((Percent)(v))
 
390
#define CHOOSE_PERCENT  AsPercent(101)
 
391
 
 
392
 
 
393
typedef uintptr_t VA;
 
394
typedef uintptr_t VPN;
 
395
 
 
396
typedef uint64    PA;
 
397
typedef uint32    PPN;
 
398
 
 
399
typedef uint64    PhysMemOff;
 
400
typedef uint64    PhysMemSize;
 
401
 
 
402
/* The Xserver source compiles with -ansi -pendantic */
 
403
#ifndef __STRICT_ANSI__
 
404
typedef uint64    BA;
 
405
#endif
 
406
typedef uint32    BPN;
 
407
typedef uint32    PageNum;
 
408
typedef unsigned  MemHandle;
 
409
typedef int32     World_ID;
 
410
 
 
411
#define INVALID_WORLD_ID ((World_ID)-1)
 
412
 
 
413
typedef World_ID User_CartelID;
 
414
#define INVALID_CARTEL_ID INVALID_WORLD_ID
 
415
 
 
416
typedef User_CartelID User_SessionID;
 
417
#define INVALID_SESSION_ID INVALID_CARTEL_ID
 
418
 
 
419
typedef User_CartelID User_CartelGroupID;
 
420
#define INVALID_CARTELGROUP_ID INVALID_CARTEL_ID
 
421
 
 
422
typedef uint32 Worldlet_ID;
 
423
#define INVALID_WORLDLET_ID ((Worldlet_ID)-1)
 
424
 
 
425
/* world page number */
 
426
typedef uint32    WPN;
 
427
 
 
428
/* The Xserver source compiles with -ansi -pendantic */
 
429
#ifndef __STRICT_ANSI__
 
430
typedef uint64     MA;
 
431
typedef uint32     MPN;
 
432
#endif
 
433
 
 
434
/*
 
435
 * This type should be used for variables that contain sector
 
436
 * position/quantity.
 
437
 */
 
438
typedef uint64 SectorType;
 
439
 
 
440
/*
 
441
 * Linear address
 
442
 */
 
443
 
 
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)
 
448
 
 
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)
 
452
 
 
453
/* Valid bits in a LPN. */
 
454
#define LPN_MASK   LAST_LPN
 
455
#define LPN_MASK32 LAST_LPN32
 
456
#define LPN_MASK64 LAST_LPN64
 
457
 
 
458
/*
 
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.
 
462
 *
 
463
 * On 32 bit platform, the following types are the same as the
 
464
 * default types.
 
465
 */
 
466
typedef uint32 VA32;
 
467
typedef uint32 VPN32;
 
468
typedef uint32 LA32;
 
469
typedef uint32 LPN32;
 
470
typedef uint32 PA32;
 
471
typedef uint32 PPN32;
 
472
typedef uint32 MA32;
 
473
typedef uint32 MPN32;
 
474
 
 
475
/*
 
476
 * On 64 bit platform, the following types are the same as the
 
477
 * default types.
 
478
 */
 
479
typedef uint64 VA64;
 
480
typedef uint64 VPN64;
 
481
typedef uint64 LA64;
 
482
typedef uint64 LPN64;
 
483
typedef uint64 PA64;
 
484
typedef uint64 PPN64;
 
485
typedef uint64 MA64;
 
486
typedef uint64 MPN64;
 
487
 
 
488
/*
 
489
 * VA typedefs for user world apps.
 
490
 */
 
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. */
 
496
#ifdef VMKERNEL
 
497
typedef UserVA64 UserVA;
 
498
#else
 
499
typedef void * UserVA;
 
500
#endif
 
501
 
 
502
 
 
503
/*
 
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.
 
507
 */
 
508
#define PHYSMEM_MAX_PPN ((PPN)0xffffffff)
 
509
#define MAX_PPN         ((PPN)0x1fffffff)   /* Maximal observable PPN value. */
 
510
#define INVALID_PPN     ((PPN)0xffffffff)
 
511
 
 
512
#define INVALID_BPN  ((BPN) 0x1fffffff)
 
513
 
 
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)
 
519
 
 
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)
 
525
 
 
526
 
 
527
/*
 
528
 * Format modifier for printing VA, LA, and VPN.
 
529
 * Use them like this: Log("%#"FMTLA"x\n", laddr)
 
530
 */
 
531
 
 
532
#if defined(VMM64) || defined(FROBOS64) || vm_x86_64 || defined __APPLE__
 
533
#   define FMTLA "l"
 
534
#   define FMTVA "l"
 
535
#   define FMTVPN "l"
 
536
#else
 
537
#   define FMTLA ""
 
538
#   define FMTVA ""
 
539
#   define FMTVPN ""
 
540
#endif
 
541
 
 
542
#ifndef EXTERN
 
543
#define EXTERN        extern
 
544
#endif
 
545
#define CONST         const
 
546
 
 
547
 
 
548
#ifndef INLINE
 
549
#   ifdef _MSC_VER
 
550
#      define INLINE        __inline
 
551
#   else
 
552
#      define INLINE        inline
 
553
#   endif
 
554
#endif
 
555
 
 
556
 
 
557
/*
 
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.
 
560
 */
 
561
#if defined(_WIN32) && defined(VMX86_IMPORT_DLLDATA)
 
562
#  define VMX86_EXTERN_DATA       extern __declspec(dllimport)
 
563
#else // !_WIN32
 
564
#  define VMX86_EXTERN_DATA       extern
 
565
#endif
 
566
 
 
567
#if defined(_WIN32) && !defined(VMX86_NO_THREADS)
 
568
#define THREADSPECIFIC __declspec(thread)
 
569
#else
 
570
#define THREADSPECIFIC
 
571
#endif
 
572
 
 
573
/*
 
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.
 
578
 */
 
579
 
 
580
#ifdef _WIN32
 
581
#ifdef _WIN64
 
582
#define VMW_KEY_WOW64_32KEY KEY_WOW64_32KEY
 
583
#else
 
584
#define VMW_KEY_WOW64_32KEY 0x0
 
585
#endif
 
586
#endif
 
587
 
 
588
 
 
589
/*
 
590
 * Consider the following reasons functions are inlined:
 
591
 *
 
592
 *  1) inlined for performance reasons
 
593
 *  2) inlined because it's a single-use function
 
594
 *
 
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.
 
599
 */
 
600
 
 
601
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
 
602
/*
 
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.
 
606
 */
 
607
#   define INLINE_SINGLE_CALLER INLINE __attribute__((__always_inline__))
 
608
#   if    defined(VMM) \
 
609
       && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 1))
 
610
#      warning Verify INLINE_SINGLE_CALLER '__always_inline__' attribute (did \
 
611
             monitor size change?)
 
612
#   endif
 
613
#else
 
614
#   define INLINE_SINGLE_CALLER INLINE
 
615
#endif
 
616
 
 
617
/*
 
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.
 
621
 */
 
622
 
 
623
#if defined(__GNUC__) && defined(VMM)
 
624
#define ABSOLUTELY_NOINLINE __attribute__((__noinline__))
 
625
#endif
 
626
 
 
627
/*
 
628
 * Attributes placed on function declarations to tell the compiler
 
629
 * that the function never returns.
 
630
 */
 
631
 
 
632
#ifdef _MSC_VER
 
633
#define NORETURN __declspec(noreturn)
 
634
#elif __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 9)
 
635
#define NORETURN __attribute__((__noreturn__))
 
636
#else
 
637
#define NORETURN
 
638
#endif
 
639
 
 
640
/*
 
641
 * GCC 3.2 inline asm needs the + constraint for input/ouput memory operands.
 
642
 * Older GCCs don't know about it --hpreg
 
643
 */
 
644
 
 
645
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
 
646
#   define VM_ASM_PLUS 1
 
647
#else
 
648
#   define VM_ASM_PLUS 0
 
649
#endif
 
650
 
 
651
/*
 
652
 * Branch prediction hints:
 
653
 *     LIKELY(exp)   - Expression exp is likely TRUE.
 
654
 *     UNLIKELY(exp) - Expression exp is likely FALSE.
 
655
 *   Usage example:
 
656
 *        if (LIKELY(excCode == EXC_NONE)) {
 
657
 *               or
 
658
 *        if (UNLIKELY(REAL_MODE(vc))) {
 
659
 *
 
660
 * We know how to predict branches on gcc3 and later (hopefully),
 
661
 * all others we don't so we do nothing.
 
662
 */
 
663
 
 
664
#if (__GNUC__ >= 3)
 
665
/*
 
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.
 
669
 */
 
670
#define LIKELY(_exp)     __builtin_expect(!!(_exp), 1)
 
671
#define UNLIKELY(_exp)   __builtin_expect((_exp), 0)
 
672
#else
 
673
#define LIKELY(_exp)      (_exp)
 
674
#define UNLIKELY(_exp)    (_exp)
 
675
#endif
 
676
 
 
677
/*
 
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.
 
683
 *
 
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
 
686
 */
 
687
 
 
688
#if defined(__GNUC__)
 
689
# define PRINTF_DECL(fmtPos, varPos) __attribute__((__format__(__printf__, fmtPos, varPos)))
 
690
#else
 
691
# define PRINTF_DECL(fmtPos, varPos)
 
692
#endif
 
693
 
 
694
#if defined(__GNUC__)
 
695
# define SCANF_DECL(fmtPos, varPos) __attribute__((__format__(__scanf__, fmtPos, varPos)))
 
696
#else
 
697
# define SCANF_DECL(fmtPos, varPos)
 
698
#endif
 
699
 
 
700
/*
 
701
 * UNUSED_PARAM should surround the parameter name and type declaration,
 
702
 * e.g. "int MyFunction(int var1, UNUSED_PARAM(int var2))"
 
703
 *
 
704
 */
 
705
 
 
706
#ifndef UNUSED_PARAM
 
707
# if defined(__GNUC__)
 
708
#  define UNUSED_PARAM(_parm) _parm  __attribute__((__unused__))
 
709
# else
 
710
#  define UNUSED_PARAM(_parm) _parm
 
711
# endif
 
712
#endif
 
713
 
 
714
/*
 
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.
 
719
 */
 
720
 
 
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
 
727
#else
 
728
# define REGPARM0
 
729
# define REGPARM1
 
730
# define REGPARM2
 
731
# define REGPARM3
 
732
# define REGPARM
 
733
#endif
 
734
 
 
735
/*
 
736
 * ALIGNED specifies minimum alignment in "n" bytes.
 
737
 */
 
738
 
 
739
#ifdef __GNUC__
 
740
#define ALIGNED(n) __attribute__((__aligned__(n)))
 
741
#else
 
742
#define ALIGNED(n)
 
743
#endif
 
744
 
 
745
/*
 
746
 ***********************************************************************
 
747
 * STRUCT_OFFSET_CHECK --                                    */ /**
 
748
 *
 
749
 * \brief Check if the actual offsef of a member in a structure 
 
750
 *        is what is expected
 
751
 * 
 
752
 *
 
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.
 
758
 *
 
759
 ***********************************************************************
 
760
 */
 
761
#ifdef VMX86_DEBUG
 
762
#define STRUCT_OFFSET_CHECK(STRUCT, MEMBER, OFFSET, DEBUG_EXTRA) \
 
763
  ASSERT_ON_COMPILE(vmk_offsetof(STRUCT, MEMBER) == (OFFSET + DEBUG_EXTRA))
 
764
#else
 
765
#define STRUCT_OFFSET_CHECK(STRUCT, MEMBER, OFFSET, DEBUG_EXTRA) \
 
766
  ASSERT_ON_COMPILE(vmk_offsetof(STRUCT, MEMBER) == OFFSET)
 
767
#endif
 
768
 
 
769
/*
 
770
 ***********************************************************************
 
771
 * STRUCT_SIZE_CHECK --                                      */ /**
 
772
 *
 
773
 * \brief Check if the actual size of a structure is what is expected
 
774
 * 
 
775
 *
 
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.
 
780
 *
 
781
 ***********************************************************************
 
782
 */
 
783
#ifdef VMX86_DEBUG
 
784
#define STRUCT_SIZE_CHECK(STRUCT, SIZE, DEBUG_EXTRA) \
 
785
  ASSERT_ON_COMPILE(sizeof(STRUCT) == (SIZE + DEBUG_EXTRA))
 
786
#else
 
787
#define STRUCT_SIZE_CHECK(STRUCT, SIZE, DEBUG_EXTRA) \
 
788
  ASSERT_ON_COMPILE(sizeof(STRUCT) == SIZE)
 
789
#endif
 
790
 
 
791
/*
 
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
 
794
 * macro.
 
795
 */
 
796
#if defined(__GNUC__) \
 
797
   && ((__GNUC__ == 2 && __GNUC_MINOR < 96) \
 
798
       || (__GNUC__ < 2))
 
799
#   define __func__ __FUNCTION__
 
800
#endif
 
801
 
 
802
/*
 
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().
 
806
 */
 
807
 
 
808
#define INFINITE_LOOP()           do { } while (1)
 
809
 
 
810
/*
 
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]
 
813
 */
 
814
#ifdef __FreeBSD__
 
815
#   ifdef _BSD_SIZE_T_
 
816
#      undef _BSD_SIZE_T_
 
817
#      ifdef VM_I386
 
818
#         ifdef VM_X86_64
 
819
             typedef uint64 size_t;
 
820
#         else
 
821
             typedef uint32 size_t;
 
822
#         endif
 
823
#      endif /* VM_I386 */
 
824
#   endif
 
825
 
 
826
#   ifdef _BSD_SSIZE_T_
 
827
#      undef _BSD_SSIZE_T_
 
828
#      define _SSIZE_T
 
829
#      define __ssize_t_defined
 
830
#      define _SSIZE_T_DECLARED
 
831
#      ifdef VM_I386
 
832
#         ifdef VM_X86_64
 
833
             typedef int64 ssize_t;
 
834
#         else
 
835
             typedef int32 ssize_t;
 
836
#         endif
 
837
#      endif /* VM_I386 */
 
838
#   endif
 
839
 
 
840
#else
 
841
#   ifndef _SIZE_T
 
842
#      define _SIZE_T
 
843
#      ifdef VM_I386
 
844
#         ifdef VM_X86_64
 
845
             typedef uint64 size_t;
 
846
#         else
 
847
             typedef uint32 size_t;
 
848
#         endif
 
849
#      endif /* VM_I386 */
 
850
#   endif
 
851
 
 
852
#   if !defined(FROBOS) && !defined(_SSIZE_T) && !defined(ssize_t) && \
 
853
       !defined(__ssize_t_defined) && !defined(_SSIZE_T_DECLARED)
 
854
#      define _SSIZE_T
 
855
#      define __ssize_t_defined
 
856
#      define _SSIZE_T_DECLARED
 
857
#      ifdef VM_I386
 
858
#         ifdef VM_X86_64
 
859
             typedef int64 ssize_t;
 
860
#         else
 
861
             typedef int32 ssize_t;
 
862
#         endif
 
863
#      endif /* VM_I386 */
 
864
#   endif
 
865
 
 
866
#endif
 
867
 
 
868
/*
 
869
 * Format modifier for printing pid_t.  On sun the pid_t is a ulong, but on
 
870
 * Linux it's an int.
 
871
 * Use this like this: printf("The pid is %"FMTPID".\n", pid);
 
872
 */
 
873
#ifdef sun
 
874
#   ifdef VM_X86_64
 
875
#      define FMTPID "d"
 
876
#   else
 
877
#      define FMTPID "lu"
 
878
#   endif
 
879
#else
 
880
# define FMTPID "d"
 
881
#endif
 
882
 
 
883
/*
 
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);
 
887
 */
 
888
#if defined(sun) && !defined(SOL11)
 
889
#   ifdef VM_X86_64
 
890
#      define FMTUID "u"
 
891
#   else
 
892
#      define FMTUID "lu"
 
893
#   endif
 
894
#else
 
895
# define FMTUID "u"
 
896
#endif
 
897
 
 
898
/*
 
899
 * Format modifier for printing mode_t.  On sun the mode_t is a ulong, but on
 
900
 * Linux it's an int.
 
901
 * Use this like this: printf("The mode is %"FMTMODE".\n", mode);
 
902
 */
 
903
#ifdef sun
 
904
#   ifdef VM_X86_64
 
905
#      define FMTMODE "o"
 
906
#   else
 
907
#      define FMTMODE "lo"
 
908
#   endif
 
909
#else
 
910
# define FMTMODE "o"
 
911
#endif
 
912
 
 
913
/*
 
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);
 
919
 */
 
920
#if defined(__FreeBSD__) && (__FreeBSD__ + 0) && ((__FreeBSD__ + 0) >= 5)
 
921
#   define FMTTIME FMTSZ"d"
 
922
#else
 
923
#   define FMTTIME "ld"
 
924
#endif
 
925
 
 
926
/*
 
927
 * Define MXSemaHandle here so both vmmon and vmx see this definition.
 
928
 */
 
929
 
 
930
#ifdef _WIN32
 
931
typedef uintptr_t MXSemaHandle;
 
932
#else
 
933
typedef int MXSemaHandle;
 
934
#endif
 
935
 
 
936
/*
 
937
 * Define type for poll device handles.
 
938
 */
 
939
 
 
940
#ifdef _WIN32
 
941
typedef uintptr_t PollDevHandle;
 
942
#else
 
943
typedef int PollDevHandle;
 
944
#endif
 
945
 
 
946
/*
 
947
 * Define the utf16_t type.
 
948
 */
 
949
 
 
950
#if defined(_WIN32) && defined(_NATIVE_WCHAR_T_DEFINED)
 
951
typedef wchar_t utf16_t;
 
952
#else
 
953
typedef uint16 utf16_t;
 
954
#endif
 
955
 
 
956
#endif  /* _VM_BASIC_TYPES_H_ */