Leaked source code of windows server 2003
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.

413 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. bldrthnk.h
  5. Abstract:
  6. Include file defining a number of structures used by bldrthnk.c. This
  7. file also includes some M4 preprocessor directives, see INCLUDE_M4.
  8. Author:
  9. Forrest C. Foltz (forrestf) 15-May-2000
  10. To use:
  11. Revision History:
  12. --*/
  13. //
  14. // Maximum identifier name length
  15. //
  16. #define MAX_NAME_LENGTH 128
  17. //
  18. // FIELD_DEF Describes a field definition within a structure's field list.
  19. //
  20. typedef struct _FIELD_DEF {
  21. CHAR Name[MAX_NAME_LENGTH];
  22. CHAR TypeName[MAX_NAME_LENGTH];
  23. ULONG TypeSize;
  24. ULONG Offset;
  25. ULONG Size;
  26. CHAR SizeFormula[MAX_NAME_LENGTH];
  27. } FIELD_DEF, *PFIELD_DEF;
  28. //
  29. // STRUC_DEF describes a structure.
  30. //
  31. typedef struct _STRUC_DEF {
  32. //
  33. // Name of this structure type
  34. //
  35. CHAR Name[MAX_NAME_LENGTH];
  36. //
  37. // Total size of the structure
  38. //
  39. ULONG Size;
  40. //
  41. // Array of field pointers. Defined as ULONGLONG to ensure an identical
  42. // layout between 32- and 64-bit objs.
  43. //
  44. ULONGLONG Fields[];
  45. } STRUC_DEF, *PSTRUC_DEF;
  46. //
  47. // Master array of pointers to structure definitions.
  48. //
  49. typedef struct _DEFINITIONS *PDEFINITIONS;
  50. typedef struct _DEFINITIONS {
  51. //
  52. // Two signatures, SIG_1 and SIG_2 to facilitate locating this list
  53. // within an .OBJ.
  54. //
  55. ULONG Sig1;
  56. ULONG Sig2;
  57. //
  58. // Array of pointers to STRUC_DEFs. Defined as ULONGLONG to ensure
  59. // identical layout between 32- and 64-bit.
  60. //
  61. ULONGLONG Structures[];
  62. } DEFINITIONS;
  63. //
  64. // SIG_1 and SIG_2 are expected to be found in DEFINITIONS.Sig1 and
  65. // DEFINITIONS.Sig2, respectively.
  66. //
  67. #define SIG_1 (ULONG)'Sig1'
  68. #define SIG_2 (ULONG)'Sig2'
  69. //
  70. // Macro used to generate a boolean value representing whether the given
  71. // type is considered signed or unsigned by the compiler.
  72. //
  73. #define IS_SIGNED_TYPE(x) (((x)-1) < ((x)0))
  74. #if defined(_WIN64)
  75. #define ONLY64(x) x
  76. #else
  77. #define ONLY64(x) 0
  78. #endif
  79. //
  80. // Structures will ultimately be described as arrays of COPY_REC structures.
  81. // Each COPY_REC structure supplies the information necessary to copy a field
  82. // from a 32-bit structure layout to a 64-bit structure layout.
  83. //
  84. typedef struct _COPY_REC {
  85. //
  86. // Offset of the field in a 32-bit structure.
  87. //
  88. USHORT Offset32;
  89. //
  90. // Offset of the field in a 64-bit structure.
  91. //
  92. USHORT Offset64;
  93. //
  94. // Size of the field in a 32-bit structure.
  95. //
  96. USHORT Size32;
  97. //
  98. // Size of the field in a 64-bit structure.
  99. //
  100. USHORT Size64;
  101. //
  102. // TRUE if the field should be sign-extended.
  103. //
  104. BOOLEAN SignExtend;
  105. } COPY_REC, *PCOPY_REC;
  106. #if !defined(ASSERT)
  107. #define ASSERT(x)
  108. #endif
  109. //
  110. // 64-bit list manipulation macros follow.
  111. //
  112. #define InitializeListHead64( ListHead ) \
  113. (ListHead)->Flink = PTR_64(ListHead); \
  114. (ListHead)->Blink = PTR_64(ListHead);
  115. #define InsertTailList64( ListHead, Entry ) { \
  116. PLIST_ENTRY_64 _EX_Blink; \
  117. PLIST_ENTRY_64 _EX_ListHead; \
  118. _EX_ListHead = (ListHead); \
  119. _EX_Blink = PTR_32(_EX_ListHead->Blink); \
  120. (Entry)->Flink = PTR_64(_EX_ListHead); \
  121. (Entry)->Blink = PTR_64(_EX_Blink); \
  122. _EX_Blink->Flink = PTR_64(Entry); \
  123. _EX_ListHead->Blink = PTR_64(Entry); \
  124. }
  125. VOID
  126. CopyRec(
  127. IN PVOID Source,
  128. OUT PVOID Destination,
  129. IN PCOPY_REC CopyRecArray
  130. );
  131. #if defined(WANT_BLDRTHNK_FUNCTIONS)
  132. ULONG
  133. StringLen(
  134. IN PCHAR Str
  135. )
  136. {
  137. if (Str == NULL) {
  138. return 0;
  139. } else {
  140. return strlen(Str)+sizeof(CHAR);
  141. }
  142. }
  143. VOID
  144. CopyRec(
  145. IN PVOID Source,
  146. OUT PVOID Destination,
  147. IN PCOPY_REC CopyRecArray
  148. )
  149. /*++
  150. Routine Description:
  151. CopyRec copies the contents of a 32-bit structure to the equivalent
  152. 64-bit structure.
  153. Arguments:
  154. Source - Supplies a pointer to the 32-bit source structure.
  155. Destination - Supplies a pointer to the 64-bit destination structure.
  156. CopyRecArray - Supplies a pointer to a 0-terminated COPY_REC array
  157. that describes the relationships between the 32- and 64-bit fields
  158. within the structure.
  159. Return value:
  160. None.
  161. --*/
  162. {
  163. PCOPY_REC copyRec;
  164. PCHAR signDst;
  165. ULONG extendBytes;
  166. PCHAR src;
  167. PCHAR dst;
  168. CHAR sign;
  169. copyRec = CopyRecArray;
  170. while (copyRec->Size32 != 0) {
  171. src = (PCHAR)Source + copyRec->Offset32;
  172. dst = (PCHAR)Destination + copyRec->Offset64;
  173. //
  174. // Determine whether this looks like a KSEG0 pointer
  175. //
  176. if (copyRec->Size32 == sizeof(PVOID) &&
  177. copyRec->Size64 == sizeof(POINTER64) &&
  178. copyRec->SignExtend != FALSE &&
  179. IS_KSEG0_PTR_X86( *(PULONG)src )) {
  180. //
  181. // Source appears to be a KSEG0 pointer. All pointers
  182. // must be explicitly "thunked" during the copy phase, so
  183. // set this pointer to a known value that we can look for
  184. // later in order to detect pointers that haven't been
  185. // thunked yet.
  186. //
  187. *(POINTER64 *)dst = PTR_64(*(PVOID *)src);
  188. } else {
  189. memcpy( dst, src, copyRec->Size32 );
  190. //
  191. // Determine whether to sign-extend or zero-extend
  192. //
  193. extendBytes = copyRec->Size64 - copyRec->Size32;
  194. if (extendBytes > 0) {
  195. signDst = dst + copyRec->Size32;
  196. if (copyRec->SignExtend != FALSE &&
  197. (*(signDst-1) & 0x80) != 0) {
  198. //
  199. // Signed value is negative, fill the high bits with
  200. // ones.
  201. //
  202. sign = 0xFF;
  203. } else {
  204. //
  205. // Unsigned value or postitive signed value, fill the high
  206. // bits with zeros.
  207. //
  208. sign = 0;
  209. }
  210. memset( signDst, sign, extendBytes );
  211. }
  212. }
  213. copyRec += 1;
  214. }
  215. }
  216. #endif // WANT_BLDRTHNK_FUNCTIONS
  217. #if defined(INCLUDE_M4)
  218. define(`IFDEF_WIN64',`#if defined(_WIN64)')
  219. //
  220. // Here begin the M4 macros used to build the structure definition module,
  221. // which is subsequently compiled by both the 32- and 64-bit compiler, with
  222. // the resulting object modules processed by bldrthnk.exe.
  223. //
  224. //
  225. // A structure layout file consists of a number of structure definition
  226. // blocks, terminated by a single DD().
  227. //
  228. // For example (underscores prepended to prevent M4 processing):
  229. //
  230. //
  231. // SD( LIST_ENTRY )
  232. // FD( Flink, PLIST_ENTRY )
  233. // FD( Blink, PLIST_ENTRY )
  234. // SE()
  235. //
  236. // DD()
  237. //
  238. define(`STRUC_NAME_LIST',`')
  239. define(`FIELD_NAME_LIST',`')
  240. //
  241. // The SD macro begins the definition of a structure.
  242. //
  243. // Usage: SD( <structure_name> )
  244. //
  245. define(`SD', `define(`STRUC_NAME',`$1')
  246. STRUC_NAME `gs_'STRUC_NAME; define(`_ONLY64',`') define(`STRUC_NAME_LIST', STRUC_NAME_LIST `(ULONGLONG)&g_'STRUC_NAME cma
  247. )'
  248. )
  249. define(`SD64', `define(`STRUC_NAME',`$1')
  250. IFDEF_WIN64
  251. STRUC_NAME `gs_'STRUC_NAME; define(`_ONLY64',`#endif') define(`STRUC_NAME_LIST', STRUC_NAME_LIST ONLY64(`(ULONGLONG)&g_'STRUC_NAME) cma
  252. )'
  253. )
  254. //
  255. // The FD macro defines a field within a structure definition block
  256. //
  257. // Usage: FD( <field_name>, <type> )
  258. //
  259. define(`FD', `FIELD_DEF `g_'STRUC_NAME`_'$1 =
  260. { "$1",
  261. "$2",
  262. sizeof($2),
  263. FIELD_OFFSET(STRUC_NAME,$1),
  264. sizeof(`gs_'STRUC_NAME.$1),
  265. "" };
  266. define(`FIELD_NAME_LIST', FIELD_NAME_LIST `(ULONGLONG)&g_'STRUC_NAME`_'$1 cma
  267. )'
  268. )
  269. //
  270. // The FDC macro works like the previous macro, except that it is applied to
  271. // a field that points to a buffer that must be copied as well.
  272. //
  273. define(`FDC', `FIELD_DEF `g_'STRUC_NAME`_'$1 =
  274. { "$1",
  275. "$2",
  276. sizeof($2),
  277. FIELD_OFFSET(STRUC_NAME,$1),
  278. sizeof(`gs_'STRUC_NAME.$1),
  279. $3 };
  280. define(`FIELD_NAME_LIST', FIELD_NAME_LIST `(ULONGLONG)&g_'STRUC_NAME`_'$1 cma
  281. )'
  282. )
  283. //
  284. // The SE macro marks the end of a structure definition.
  285. //
  286. // Usage: SE()
  287. //
  288. define(`SE', `STRUC_DEF `g_'STRUC_NAME = {
  289. "STRUC_NAME", sizeof(STRUC_NAME),
  290. {
  291. define(`cma',`,') FIELD_NAME_LIST undefine(`cma') 0 }
  292. define(`FIELD_NAME_LIST',`')
  293. };'
  294. _ONLY64
  295. )
  296. //
  297. // The DD macro marks the end of all structure definitions, and results
  298. // in the generation of a single DEFINITIONS structure.
  299. //
  300. // Usage: DD()
  301. //
  302. define(`DD', `DEFINITIONS Definitions = {
  303. SIG_1, SIG_2,
  304. {
  305. define(`cma',`,') STRUC_NAME_LIST undefine(`cma') 0 }
  306. }; define(`STRUC_NAME_LIST',`')');
  307. #endif