Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
6.3 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. basetsd.h
  5. Abstract:
  6. Type definitions for the basic sized types.
  7. Author:
  8. Revision History:
  9. --*/
  10. #ifndef _BASETSD_H_
  11. #define _BASETSD_H_
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. typedef signed char INT8, *PINT8;
  19. typedef signed short INT16, *PINT16;
  20. typedef signed int INT32, *PINT32;
  21. typedef signed __int64 INT64, *PINT64;
  22. typedef unsigned char UINT8, *PUINT8;
  23. typedef unsigned short UINT16, *PUINT16;
  24. typedef unsigned int UINT32, *PUINT32;
  25. typedef unsigned __int64 UINT64, *PUINT64;
  26. //
  27. // The following types are guaranteed to be signed and 32 bits wide.
  28. //
  29. typedef signed int LONG32, *PLONG32;
  30. //
  31. // The following types are guaranteed to be unsigned and 32 bits wide.
  32. //
  33. typedef unsigned int ULONG32, *PULONG32;
  34. typedef unsigned int DWORD32, *PDWORD32;
  35. #if !defined(_W64)
  36. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
  37. #define _W64 __w64
  38. #else
  39. #define _W64
  40. #endif
  41. #endif
  42. //
  43. // The INT_PTR is guaranteed to be the same size as a pointer. Its
  44. // size with change with pointer size (32/64). It should be used
  45. // anywhere that a pointer is cast to an integer type. UINT_PTR is
  46. // the unsigned variation.
  47. //
  48. // __int3264 is intrinsic to 64b MIDL but not to old MIDL or to C compiler.
  49. //
  50. #if ( 501 < __midl )
  51. typedef [public] __int3264 INT_PTR, *PINT_PTR;
  52. typedef [public] unsigned __int3264 UINT_PTR, *PUINT_PTR;
  53. typedef [public] __int3264 LONG_PTR, *PLONG_PTR;
  54. typedef [public] unsigned __int3264 ULONG_PTR, *PULONG_PTR;
  55. #else // midl64
  56. // old midl and C++ compiler
  57. #if defined(_WIN64)
  58. typedef __int64 INT_PTR, *PINT_PTR;
  59. typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
  60. typedef __int64 LONG_PTR, *PLONG_PTR;
  61. typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
  62. #define __int3264 __int64
  63. #else
  64. typedef _W64 int INT_PTR, *PINT_PTR;
  65. typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
  66. typedef _W64 long LONG_PTR, *PLONG_PTR;
  67. typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
  68. #define __int3264 __int32
  69. #endif
  70. #endif // midl64
  71. //
  72. // HALF_PTR is half the size of a pointer it intended for use with
  73. // within strcuture which contain a pointer and two small fields.
  74. // UHALF_PTR is the unsigned variation.
  75. //
  76. #ifdef _WIN64
  77. #define ADDRESS_TAG_BIT 0x40000000000UI64
  78. typedef __int64 SHANDLE_PTR;
  79. typedef unsigned __int64 HANDLE_PTR;
  80. typedef unsigned int UHALF_PTR, *PUHALF_PTR;
  81. typedef int HALF_PTR, *PHALF_PTR;
  82. #if !defined(__midl)
  83. __inline
  84. unsigned long
  85. HandleToULong(
  86. const void *h
  87. )
  88. {
  89. return((unsigned long) (ULONG_PTR) h );
  90. }
  91. __inline
  92. long
  93. HandleToLong(
  94. const void *h
  95. )
  96. {
  97. return((long) (LONG_PTR) h );
  98. }
  99. __inline
  100. void *
  101. ULongToHandle(
  102. const unsigned long h
  103. )
  104. {
  105. return((void *) (UINT_PTR) h );
  106. }
  107. __inline
  108. void *
  109. LongToHandle(
  110. const long h
  111. )
  112. {
  113. return((void *) (INT_PTR) h );
  114. }
  115. __inline
  116. unsigned long
  117. PtrToUlong(
  118. const void *p
  119. )
  120. {
  121. return((unsigned long) (ULONG_PTR) p );
  122. }
  123. __inline
  124. unsigned int
  125. PtrToUint(
  126. const void *p
  127. )
  128. {
  129. return((unsigned int) (UINT_PTR) p );
  130. }
  131. __inline
  132. unsigned short
  133. PtrToUshort(
  134. const void *p
  135. )
  136. {
  137. return((unsigned short) (unsigned long) (ULONG_PTR) p );
  138. }
  139. __inline
  140. long
  141. PtrToLong(
  142. const void *p
  143. )
  144. {
  145. return((long) (LONG_PTR) p );
  146. }
  147. __inline
  148. int
  149. PtrToInt(
  150. const void *p
  151. )
  152. {
  153. return((int) (INT_PTR) p );
  154. }
  155. __inline
  156. short
  157. PtrToShort(
  158. const void *p
  159. )
  160. {
  161. return((short) (long) (LONG_PTR) p );
  162. }
  163. __inline
  164. void *
  165. IntToPtr(
  166. const int i
  167. )
  168. // Caution: IntToPtr() sign-extends the int value.
  169. {
  170. return( (void *)(INT_PTR)i );
  171. }
  172. __inline
  173. void *
  174. UIntToPtr(
  175. const unsigned int ui
  176. )
  177. // Caution: UIntToPtr() zero-extends the unsigned int value.
  178. {
  179. return( (void *)(UINT_PTR)ui );
  180. }
  181. __inline
  182. void *
  183. LongToPtr(
  184. const long l
  185. )
  186. // Caution: LongToPtr() sign-extends the long value.
  187. {
  188. return( (void *)(LONG_PTR)l );
  189. }
  190. __inline
  191. void *
  192. ULongToPtr(
  193. const unsigned long ul
  194. )
  195. // Caution: ULongToPtr() zero-extends the unsigned long value.
  196. {
  197. return( (void *)(ULONG_PTR)ul );
  198. }
  199. #endif // !_midl
  200. #else // !_WIN64
  201. #define ADDRESS_TAG_BIT 0x80000000UL
  202. typedef unsigned short UHALF_PTR, *PUHALF_PTR;
  203. typedef short HALF_PTR, *PHALF_PTR;
  204. typedef _W64 long SHANDLE_PTR;
  205. typedef _W64 unsigned long HANDLE_PTR;
  206. #define HandleToULong( h ) ((ULONG)(ULONG_PTR)(h) )
  207. #define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
  208. #define ULongToHandle( ul ) ((HANDLE)(ULONG_PTR) (ul) )
  209. #define LongToHandle( h ) ((HANDLE)(LONG_PTR) (h) )
  210. #define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
  211. #define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
  212. #define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
  213. #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
  214. #define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
  215. #define PtrToShort( p ) ((short)(LONG_PTR)(p) )
  216. #define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i))
  217. #define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui))
  218. #define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l))
  219. #define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul))
  220. #endif // !_WIN64
  221. #define HandleToUlong(h) HandleToULong(h)
  222. #define UlongToHandle(ul) ULongToHandle(ul)
  223. #define UlongToPtr(ul) ULongToPtr(ul)
  224. #define UintToPtr(ui) UIntToPtr(ui)
  225. #define MAXUINT_PTR (~((UINT_PTR)0))
  226. #define MAXINT_PTR ((INT_PTR)(MAXUINT_PTR >> 1))
  227. #define MININT_PTR (~MAXINT_PTR)
  228. #define MAXULONG_PTR (~((ULONG_PTR)0))
  229. #define MAXLONG_PTR ((LONG_PTR)(MAXULONG_PTR >> 1))
  230. #define MINLONG_PTR (~MAXLONG_PTR)
  231. #define MAXUHALF_PTR ((UHALF_PTR)~0)
  232. #define MAXHALF_PTR ((HALF_PTR)(MAXUHALF_PTR >> 1))
  233. #define MINHALF_PTR (~MAXHALF_PTR)
  234. //
  235. // SIZE_T used for counts or ranges which need to span the range of
  236. // of a pointer. SSIZE_T is the signed variation.
  237. //
  238. typedef ULONG_PTR SIZE_T, *PSIZE_T;
  239. typedef LONG_PTR SSIZE_T, *PSSIZE_T;
  240. //
  241. // Add Windows flavor DWORD_PTR types
  242. //
  243. typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
  244. //
  245. // The following types are guaranteed to be signed and 64 bits wide.
  246. //
  247. typedef __int64 LONG64, *PLONG64;
  248. //
  249. // The following types are guaranteed to be unsigned and 64 bits wide.
  250. //
  251. typedef unsigned __int64 ULONG64, *PULONG64;
  252. typedef unsigned __int64 DWORD64, *PDWORD64;
  253. //
  254. // Thread affinity.
  255. //
  256. typedef ULONG_PTR KAFFINITY;
  257. typedef KAFFINITY *PKAFFINITY;
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif // _BASETSD_H_