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.

138 lines
3.9 KiB

  1. #define _WIN32_WINNT 0x0501
  2. #include <stdio.h>
  3. #include <assert.h>
  4. #include <limits.h>
  5. #include <stddef.h>
  6. void Test1()
  7. {
  8. #if 0
  9. typedef struct {
  10. int i;
  11. struct {
  12. int j;
  13. char pseudo_pointer[sizeof(void*)];
  14. };
  15. } Struct1;
  16. typedef struct {
  17. int i;
  18. struct {
  19. int j;
  20. void* pointer;
  21. };
  22. } Struct2;
  23. typedef struct {
  24. int i;
  25. struct {
  26. int j;
  27. int k;
  28. void* pointer;
  29. };
  30. } Struct3;
  31. #define X(x) printf("Win%ld %s %ld\n", (long)(sizeof(void*)*CHAR_BIT), #x, (long)x)
  32. X(sizeof(Struct1));
  33. X(sizeof(Struct2));
  34. X(sizeof(Struct3));
  35. X(offsetof(Struct1, j));
  36. X(offsetof(Struct2, j));
  37. X(offsetof(Struct3, j));
  38. X(offsetof(Struct1, pseudo_pointer));
  39. X(offsetof(Struct2, pointer));
  40. X(offsetof(Struct3, pointer));
  41. #undef X
  42. #endif
  43. }
  44. #include "nt.h"
  45. #include "ntrtl.h"
  46. #include "wow64t.h"
  47. #if !defined(RTL_PADDING_BETWEEN_FIELDS)
  48. #define RTL_PADDING_BETWEEN_FIELDS(T, F1, F2) \
  49. ((FIELD_OFFSET(T, F2) > FIELD_OFFSET(T, F1)) \
  50. ? (FIELD_OFFSET(T, F2) - FIELD_OFFSET(T, F1) - RTL_FIELD_SIZE(T, F1)) \
  51. : (FIELD_OFFSET(T, F1) - FIELD_OFFSET(T, F2) - RTL_FIELD_SIZE(T, F2)))
  52. #endif
  53. void Test2()
  54. {
  55. #undef TEB_MEMBER
  56. #define TEB_MEMBER(name) printf("%s %ld %ld\n", #name, (long)FIELD_OFFSET(TEB, name), (long)RTL_FIELD_SIZE(TEB, name));
  57. #ifdef _IA64_
  58. #define TEB_MEMBER_IA64(name) TEB_MEMBER(name)
  59. #else
  60. #define TEB_MEMBER_IA64(name) /* nothing */
  61. #endif
  62. #define TEB TEB
  63. printf("\n\nnative TEB %ld\n\n", (long)sizeof(TEB));
  64. #include "teb.h"
  65. #undef TEB
  66. #undef TEB_MEMBER
  67. #define TEB_MEMBER(name) printf("%s %ld %ld\n", #name, (long)FIELD_OFFSET(TEB32, name), (long)RTL_FIELD_SIZE(TEB32, name));
  68. #undef TEB_MEMBER_IA64
  69. #define TEB_MEMBER_IA64(name) /* nothing */
  70. printf("\n\nTEB32 %ld\n\n", (long)sizeof(TEB32));
  71. #include "teb.h"
  72. #undef TEB_MEMBER
  73. #define TEB_MEMBER(name) printf("%s %ld %ld\n", #name, (long)FIELD_OFFSET(TEB64, name), (long)RTL_FIELD_SIZE(TEB64, name));
  74. #if defined(_X86_)
  75. #undef TEB_MEMBER_IA64
  76. #define TEB_MEMBER_IA64(name) TEB_MEMBER(name)
  77. #endif
  78. #define TEB64 TEB64
  79. printf("\n\nTEB64 %ld\n\n", (long)sizeof(TEB64));
  80. #include "teb.h"
  81. #undef TEB64
  82. #define PEB_MEMBER(name) printf("%s %ld %ld\n", #name, (long)FIELD_OFFSET(PEB, name), (long)RTL_FIELD_SIZE(PEB, name));
  83. #define PEB PEB
  84. printf("\n\nnative PEB %ld\n\n", (long)sizeof(PEB));
  85. #include "peb.h"
  86. #undef PEB
  87. #undef PEB_MEMBER
  88. #define PEB_MEMBER(name) printf("%s %ld %ld\n", #name, (long)FIELD_OFFSET(PEB32, name), (long)RTL_FIELD_SIZE(PEB32, name));
  89. printf("\n\nPEB32 %ld\n\n", (long)sizeof(PEB32));
  90. #include "peb.h"
  91. #undef PEB_MEMBER
  92. #define PEB_MEMBER(name) printf("%s %ld %ld\n", #name, (long)FIELD_OFFSET(PEB64, name), (long)RTL_FIELD_SIZE(PEB64, name));
  93. printf("\n\nPEB64 %ld\n\n", (long)sizeof(PEB64));
  94. #include "peb.h"
  95. printf("\n\npadding\n\n");
  96. printf("TEB %ld\n", (long)RTL_PADDING_BETWEEN_FIELDS(TEB, ActivationContextStack, ExceptionCode));
  97. printf("TEB %ld\n", (long)RTL_PADDING_BETWEEN_FIELDS(TEB, ExceptionCode, ActivationContextStack));
  98. printf("TEB32 %ld\n", (long)RTL_PADDING_BETWEEN_FIELDS(TEB32, ActivationContextStack, ExceptionCode));
  99. printf("TEB32 %ld\n", (long)RTL_PADDING_BETWEEN_FIELDS(TEB32, ExceptionCode, ActivationContextStack));
  100. printf("TEB64 %ld\n", (long)RTL_PADDING_BETWEEN_FIELDS(TEB64, ActivationContextStack, ExceptionCode));
  101. printf("TEB64 %ld\n", (long)RTL_PADDING_BETWEEN_FIELDS(TEB64, ExceptionCode, ActivationContextStack));
  102. #if defined(SD_BRANCH_LAB01_FUSION)
  103. if ((sizeof(PVOID)*CHAR_BIT) == 32)
  104. {
  105. assert(sizeof(PEB) == sizeof(PEB32));
  106. assert(sizeof(TEB) == sizeof(TEB32));
  107. }
  108. if ((sizeof(PVOID)*CHAR_BIT) == 64)
  109. {
  110. assert(sizeof(PEB) == sizeof(PEB64));
  111. assert(sizeof(TEB) == sizeof(TEB64));
  112. }
  113. #endif
  114. }
  115. int main()
  116. {
  117. Test1();
  118. Test2();
  119. return 0;
  120. }