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.

212 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. gennt32t.cpp
  5. Abstract:
  6. Generates NT32 headers for use in the NT64 build.
  7. Author:
  8. mzoran 5-8-98
  9. Revision History:
  10. --*/
  11. #pragma warning( disable : 4786) //disable identifier is too long for debugging error
  12. #pragma warning( disable : 4503) //disable decorated name is too long
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <imagehlp.h>
  18. #include <ctype.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <assert.h>
  23. #include <iostream>
  24. #include <fstream>
  25. #include <iomanip>
  26. #include <string>
  27. #include <sstream>
  28. #include <set>
  29. #include <map>
  30. extern "C" {
  31. #include "gen.h"
  32. // string to put in front of all error messages so that BUILD can find them.
  33. const char *ErrMsgPrefix = "NMAKE : U8603: 'GENNT32T' ";
  34. #pragma warning(push)
  35. #pragma warning(disable:4702)
  36. void
  37. HandlePreprocessorDirective(
  38. char *p
  39. )
  40. {
  41. ExitErrMsg(FALSE, "Preprocessor directives not allowed by gennt32t.\n");
  42. }
  43. #pragma warning(pop)
  44. }
  45. using namespace std;
  46. typedef string String;
  47. PRBTREE pFunctions = NULL;
  48. PRBTREE pStructures = NULL;
  49. PRBTREE pTypedefs = NULL;
  50. PKNOWNTYPES NIL = NULL;
  51. void ExtractCVMHeader(PCVMHEAPHEADER pHeader) {
  52. pFunctions = &pHeader->FuncsList;
  53. pTypedefs = &pHeader->TypeDefsList;
  54. pStructures =&pHeader->StructsList;
  55. NIL =&pHeader->NIL;
  56. }
  57. void GetType(PKNOWNTYPES pTypes, char *pPrepend, ostream & oType, ostream & oName, BOOL bAddTypeName) {
  58. while(1) {
  59. PKNOWNTYPES pBasicType = NULL;
  60. assert(pTypes->TypeName != NULL);
  61. oType << "/* " << pTypes->TypeName << " */";
  62. if(pTypes->Flags & BTI_ISARRAY)
  63. oName << '[' << pTypes->dwArrayElements << ']';
  64. if (pTypes->IndLevel > 0) {
  65. oType << GetHostPointerName(pTypes->Flags & BTI_PTR64);
  66. return;
  67. }
  68. if(!(BTI_NOTDERIVED & pTypes->Flags)) {
  69. if (strcmp(pTypes->BaseName, "enum") == 0) {
  70. if (bAddTypeName)
  71. oType << "enum " << pPrepend << pTypes->TypeName << " {} \n";
  72. else
  73. oType << "_int32 \n";
  74. return;
  75. }
  76. else if (strcmp(pTypes->BaseName, "union") == 0 ||
  77. strcmp(pTypes->BaseName, "struct") == 0) {
  78. oType << "\n#pragma pack(" << pTypes->dwCurrentPacking
  79. << ")\n";
  80. if (bAddTypeName)
  81. oType << pTypes->BaseName << " " << pPrepend << pTypes->TypeName;
  82. else
  83. oType << pTypes->BaseName << " ";
  84. if (NULL != pTypes->pmeminfo) {
  85. oType << "{\n";
  86. PMEMBERINFO pmeminfo = pTypes->pmeminfo;
  87. do {
  88. ostringstream oMemberType("");
  89. ostringstream oMemberName("");
  90. PKNOWNTYPES pMemberType = pmeminfo->pkt;
  91. if(pmeminfo->sName != NULL)
  92. oMemberName << pmeminfo->sName;
  93. if (pmeminfo->bIsArray)
  94. oMemberName << '[' << pmeminfo->ArrayElements << ']';
  95. if (pmeminfo->IndLevel > 0) {
  96. oMemberType << GetHostPointerName(pmeminfo->bIsPtr64);
  97. }
  98. else {
  99. GetType(pMemberType, pPrepend, oMemberType, oMemberName, FALSE);
  100. if (pmeminfo->bIsBitfield)
  101. oMemberName << " : " << pmeminfo->BitsRequired;
  102. }
  103. oType << oMemberType.str() << " " << oMemberName.str() << ";\n";
  104. pmeminfo = pmeminfo->pmeminfoNext;
  105. } while(NULL != pmeminfo);
  106. oType << "}\n";
  107. }
  108. return;
  109. }
  110. else {
  111. pBasicType = pTypes->pTypedefBase;
  112. if (NULL == pBasicType) {
  113. oType << GetHostPointerName(pTypes->Flags & BTI_PTR64);
  114. return;
  115. }
  116. pTypes = pBasicType;
  117. }
  118. }
  119. else {
  120. char Buffer[MAX_PATH];
  121. oType << GetHostTypeName(pTypes, Buffer);
  122. return;
  123. }
  124. }
  125. }
  126. void DumpTypesHeader(void) {
  127. PKNOWNTYPES pTypes;
  128. cout << "///////////////////////////////////////////\n";
  129. cout << "// This file is autogenerated by gennt32t. \n";
  130. cout << "// Do not edit \n";
  131. cout << "///////////////////////////////////////////\n";
  132. cout << '\n' << '\n';
  133. cout << "#include <guiddef.h>\n\n";
  134. cout << "#pragma pack(push, gennt32t)\n\n";
  135. cout << "///////////////////////////////////////////\n";
  136. cout << "// Structures \n";
  137. cout << "///////////////////////////////////////////\n";
  138. for(pTypes = pStructures->pLastNodeInserted; pTypes != NULL; pTypes = pTypes->Next) {
  139. if (pTypes->TypeName != NULL && !(pTypes->Flags & BTI_NOTDERIVED)) {
  140. ostringstream oType;
  141. ostringstream oName;
  142. GetType(pTypes, "NT32", oType, oName, TRUE);
  143. cout << "/* " << pTypes->TypeName << " */";
  144. cout << oType.str() << "\n";
  145. cout << oName.str() << ";" << "\n";
  146. cout << "/* End of definition for " << pTypes->TypeName << " */\n";
  147. cout << '\n';
  148. } }
  149. cout << '\n' << '\n';
  150. cout << "///////////////////////////////////////////\n";
  151. cout << "// TypeDefs \n";
  152. cout << "///////////////////////////////////////////\n";
  153. for(pTypes = pTypedefs->pLastNodeInserted; pTypes != NULL; pTypes = pTypes->Next) {
  154. if (pTypes->TypeName != NULL && !(pTypes->Flags & BTI_NOTDERIVED)) {
  155. ostringstream oType;
  156. ostringstream oName;
  157. oName << "NT32" << pTypes->TypeName << " ";
  158. GetType(pTypes, "NT32", oType, oName, FALSE);
  159. cout << "/* " << pTypes->TypeName << " */" << " typedef \n";
  160. cout << oType.str() << "\n";
  161. cout << oName.str() << "\n";
  162. cout << ";" << "\n";
  163. cout << "/* End of definition for " << pTypes->TypeName << " */\n";
  164. cout << '\n';
  165. }
  166. }
  167. cout << '\n' << '\n';
  168. cout << "#pragma pack(pop, gennt32t)\n\n";
  169. }
  170. int _cdecl main(int argc, char*argv[]) {
  171. ExtractCVMHeader(MapPpmFile(argv[1], TRUE));
  172. DumpTypesHeader();
  173. return 0;
  174. }