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.

149 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. vwvdm.h
  5. Abstract:
  6. Contains macros, manifests, includes for dealing with VDM
  7. Author:
  8. Richard L Firth (rfirth) 25-Oct-1993
  9. Revision History:
  10. 25-Oct-1993 rfirth
  11. Created
  12. --*/
  13. #ifndef _VWVDM_H_
  14. #define _VWVDM_H_
  15. //
  16. // unaligned pointers - non-Intel platforms must use UNALIGNED to access data
  17. // in VDM which can (and most likely will) be aligned on odd-byte and word
  18. // boundaries
  19. //
  20. #ifndef ULPBYTE
  21. #define ULPBYTE BYTE UNALIGNED FAR*
  22. #endif
  23. #ifndef ULPWORD
  24. #define ULPWORD WORD UNALIGNED FAR*
  25. #endif
  26. #ifndef ULPDWORD
  27. #define ULPDWORD DWORD UNALIGNED FAR*
  28. #endif
  29. #ifndef ULPVOID
  30. #define ULPVOID VOID UNALIGNED FAR*
  31. #endif
  32. //
  33. // VDM macros
  34. //
  35. //
  36. // POINTER_FROM_WORDS - returns 32-bit pointer to address in VDM memory described
  37. // by seg:off. If seg:off = 0:0, returns NULL
  38. //
  39. #define POINTER_FROM_WORDS(seg, off, size) \
  40. _inlinePointerFromWords((WORD)(seg), (WORD)(off), (WORD)(size))
  41. //
  42. // _inlinePointerFromWords - the POINTER_FROM_WORDS macro is inefficient if the
  43. // arguments are calls to eg. getES(), getBX() - the calls are made twice if
  44. // the pointer turns out to be non-zero. Use an inline function to achieve the
  45. // same results, but only call function arguments once
  46. //
  47. __inline LPVOID _inlinePointerFromWords(WORD seg, WORD off, WORD size) {
  48. return (seg | off)
  49. ? (LPVOID)GetVDMPointer((ULONG)(MAKELONG(off, seg)), size, (CHAR)((getMSW() & MSW_PE) ? TRUE : FALSE))
  50. : NULL;
  51. }
  52. //
  53. // GET_POINTER - does the same thing as POINTER_FROM_WORDS, but we know beforehand
  54. // which processor mode we are in
  55. //
  56. #define GET_POINTER(seg, off, size, mode) \
  57. _inlineGetPointer((WORD)(seg), (WORD)(off), (WORD)(size), (BOOL)(mode))
  58. __inline LPVOID _inlineGetPointer(WORD seg, WORD off, WORD size, BOOL mode) {
  59. return (seg | off)
  60. ? (LPVOID)GetVDMPointer(MAKELONG(off, seg), size, (UCHAR)mode)
  61. : NULL;
  62. }
  63. //
  64. // GET_FAR_POINTER - same as READ_FAR_POINTER with the same proviso as for
  65. // GET_POINTER
  66. //
  67. #define GET_FAR_POINTER(addr, mode) ((LPBYTE)(GET_POINTER(GET_SELECTOR(addr), GET_OFFSET(addr), sizeof(LPBYTE), mode)))
  68. //
  69. // GET_SELECTOR - retrieves the selector word from the intel 32-bit far pointer
  70. // (DWORD) pointed at by <pointer> (remember: stored as offset, segment)
  71. //
  72. #define GET_SELECTOR(pointer) READ_WORD((LPWORD)(pointer)+1)
  73. //
  74. // GET_SEGMENT - same as GET_SELECTOR
  75. //
  76. #define GET_SEGMENT(pointer) GET_SELECTOR(pointer)
  77. //
  78. // GET_OFFSET - retrieves the offset word from an intel 32-bit far pointer
  79. // (DWORD) pointed at by <pointer> (remember: stored as offset, segment)
  80. //
  81. #define GET_OFFSET(pointer) READ_WORD((LPWORD)(pointer))
  82. //
  83. // READ_FAR_POINTER - read the pair of words in VDM memory, currently pointed at
  84. // by a 32-bit flat pointer and convert them to a 32-bit flat pointer
  85. //
  86. #define READ_FAR_POINTER(addr) ((LPBYTE)(POINTER_FROM_WORDS(GET_SELECTOR(addr), GET_OFFSET(addr), sizeof(LPBYTE))))
  87. //
  88. // READ_WORD - read a single 16-bit little-endian word from VDM memory. On non
  89. // Intel platforms, use unaligned pointer to access data
  90. //
  91. #define READ_WORD(addr) (*((ULPWORD)(addr)))
  92. //
  93. // READ_DWORD - read a 4-byte little-endian double word from VDM memory. On non
  94. // Intel platforms, use unaligned pointer to access data
  95. //
  96. #define READ_DWORD(addr) (*((ULPDWORD)(addr)))
  97. //
  98. // ARRAY_ELEMENTS - gives the number of elements of a particular type in an
  99. // array
  100. //
  101. #define ARRAY_ELEMENTS(a) (sizeof(a)/sizeof((a)[0]))
  102. //
  103. // LAST_ELEMENT - returns the index of the last element in array
  104. //
  105. #define LAST_ELEMENT(a) (ARRAY_ELEMENTS(a)-1)
  106. #endif // _VWVDM_H_