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.2 KiB

  1. /**************************************************************************
  2. * LOCAL.C
  3. *
  4. * Routines used to walk local heaps
  5. *
  6. **************************************************************************/
  7. #include "toolpriv.h"
  8. /* ----- Function prototypes ----- */
  9. NOEXPORT void NEAR PASCAL ComputeType(
  10. LOCALENTRY FAR *lpLocal);
  11. /* LocalInfo
  12. * Reports information about the state of the indicated heap
  13. */
  14. BOOL TOOLHELPAPI LocalInfo(
  15. LOCALINFO FAR *lpLocalInfo,
  16. HANDLE hHeap)
  17. {
  18. /* Check the version number and verify proper installation */
  19. if (!wLibInstalled || !lpLocalInfo ||
  20. lpLocalInfo->dwSize != sizeof (LOCALINFO))
  21. return FALSE;
  22. /* Get the item counts */
  23. if (wTHFlags & TH_KERNEL_386)
  24. lpLocalInfo->wcItems = WalkLoc386Count(hHeap);
  25. else
  26. lpLocalInfo->wcItems = WalkLoc286Count(hHeap);
  27. return TRUE;
  28. }
  29. /* LocalFirst
  30. * Finds the first block on a local heap.
  31. */
  32. BOOL TOOLHELPAPI LocalFirst(
  33. LOCALENTRY FAR *lpLocal,
  34. HANDLE hHeap)
  35. {
  36. WORD wFirst;
  37. /* Check the version number and verify proper installation */
  38. if (!wLibInstalled || !lpLocal || lpLocal->dwSize != sizeof (LOCALENTRY))
  39. return FALSE;
  40. /* Convert the heap variable to a selector */
  41. hHeap = HelperHandleToSel(hHeap);
  42. /* Get the first item from the heap */
  43. if (wTHFlags & TH_KERNEL_386)
  44. {
  45. if (!(wFirst = WalkLoc386First(hHeap)))
  46. return FALSE;
  47. }
  48. else
  49. {
  50. if (!(wFirst = WalkLoc286First(hHeap)))
  51. return FALSE;
  52. }
  53. /* Fill in other miscellaneous stuff */
  54. lpLocal->hHeap = hHeap;
  55. /* Get information about this item */
  56. if (wTHFlags & TH_KERNEL_386)
  57. WalkLoc386(wFirst, lpLocal, hHeap);
  58. else
  59. WalkLoc286(wFirst, lpLocal, hHeap);
  60. /* Guess at the type of the object */
  61. ComputeType(lpLocal);
  62. return TRUE;
  63. }
  64. /* LocalNext
  65. * Continues a local heap walk by getting information about the
  66. * next item.
  67. */
  68. BOOL TOOLHELPAPI LocalNext(
  69. LOCALENTRY FAR *lpLocal)
  70. {
  71. /* Check the version number and verify proper installation */
  72. if (!wLibInstalled || !lpLocal || lpLocal->dwSize != sizeof (LOCALENTRY))
  73. return FALSE;
  74. if (wTHFlags & TH_KERNEL_386)
  75. WalkLoc386(lpLocal->wNext, lpLocal, lpLocal->hHeap);
  76. else
  77. WalkLoc286(lpLocal->wNext, lpLocal, lpLocal->hHeap);
  78. /* See if this item is the last one. If so, return done because this
  79. * last item is NOT useful.
  80. */
  81. if (!lpLocal->wNext)
  82. return FALSE;
  83. /* Guess at the type of the object */
  84. ComputeType(lpLocal);
  85. return TRUE;
  86. }
  87. /* ComputeType
  88. * Computes the object type of an object
  89. */
  90. NOEXPORT void NEAR PASCAL ComputeType(
  91. LOCALENTRY FAR *lpLocal)
  92. {
  93. /* Decode the free/fixed/moveable bits */
  94. if (lpLocal->wFlags & 2)
  95. lpLocal->wFlags = LF_MOVEABLE;
  96. else if (lpLocal->wFlags & 1)
  97. lpLocal->wFlags = LF_FIXED;
  98. else
  99. {
  100. /* Free blocks never have a unique type so return */
  101. lpLocal->wFlags = LF_FREE;
  102. lpLocal->wType = LT_FREE;
  103. lpLocal->hHandle = NULL;
  104. return;
  105. }
  106. /* Decode the heap type if possible */
  107. UserGdiType(lpLocal);
  108. }