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.

215 lines
4.0 KiB

  1. .xlist
  2. include kernel.inc
  3. .list
  4. if KDEBUG
  5. DataBegin
  6. externB fBooting
  7. externW pGlobalHeap
  8. ;externW hGlobalHeap
  9. DataEnd
  10. sBegin CODE
  11. assumes CS,CODE
  12. externW gdtdsc
  13. externNP check_lru_list
  14. externNP check_free_list
  15. externNP get_physical_address
  16. ;externFP ValidateFreeSpaces
  17. ;-----------------------------------------------------------------------;
  18. ; CheckGlobalHeap ;
  19. ; ;
  20. ; The Global Heap is checked for consistency. First the forward links ;
  21. ; are examined to make sure they lead from the hi_first to the hi_last. ;
  22. ; Then the backward links are checked to make sure they lead from the ;
  23. ; hi_last to the hi_first. Then the arenas are sequentially checked ;
  24. ; to see that the moveable entries point to allocated handles and that ;
  25. ; said handles point back. The handle table is then checked to see ;
  26. ; that the number of used handles match the number of referenced ;
  27. ; handles, and that the number of total handles matches the sum of the ;
  28. ; free, discarded, and used handles. Finally the free list of handles ;
  29. ; is checked. ;
  30. ; ;
  31. ; Arguments: ;
  32. ; none ;
  33. ; ;
  34. ; Returns: ;
  35. ; CF = 0 everything is just fine ;
  36. ; all registers preserved ;
  37. ; ;
  38. ; Error Returns: ;
  39. ; CF = 1 ;
  40. ; DX = offending arena header ;
  41. ; AX = 01h Forward links invalid ;
  42. ; 02h Backward links invalid ;
  43. ; 04h ga_handle points to free handle ;
  44. ; 08h arena points to handle but not vice versa ;
  45. ; 80h ga_sig is bad ;
  46. ; DX = 0 ;
  47. ; AX = 10h allocated handles don't match used handles ;
  48. ; 20h total number of handles don't match up ;
  49. ; 40h total number of free handles don't match up ;
  50. ; ;
  51. ; Registers Preserved: ;
  52. ; All ;
  53. ; ;
  54. ; Registers Destroyed: ;
  55. ; ;
  56. ; Calls: ;
  57. ; ;
  58. ; History: ;
  59. ; ;
  60. ; Sat Nov 01, 1986 02:16:46p -by- David N. Weise [davidw] ;
  61. ; Rewrote it from C into assembly. ;
  62. ;-----------------------------------------------------------------------;
  63. cProc CheckGlobalHeap,<PUBLIC,NEAR>
  64. cBegin nogen
  65. push ax
  66. push dx
  67. push bx
  68. push cx
  69. push di
  70. push si
  71. push ds
  72. push es
  73. xor ax,ax
  74. xor dx,dx
  75. xor di,di
  76. SetKernelDS
  77. cmp pGlobalHeap,di
  78. jnz there_is_a_GlobalHeap
  79. jmp all_done
  80. there_is_a_GlobalHeap:
  81. cmp fBooting, 1
  82. jz no_check
  83. mov ds,pGlobalHeap
  84. UnSetKernelDS
  85. cmp [di].hi_check,di
  86. jnz checking_enabled
  87. no_check:
  88. jmp all_done
  89. checking_enabled:
  90. mov cx,[di].hi_count
  91. mov dx,[di].hi_first
  92. mov es, dx
  93. forward_ho:
  94. push cx
  95. cCall get_physical_address, <es>
  96. add ax, 10h
  97. adc dx, 0
  98. mov bx, es:[di].ga_size
  99. xor cx, cx
  100. rept 4
  101. shl bx, 1
  102. rcl cx, 1
  103. endm
  104. cmp es:[di].ga_owner, di
  105. je no_limit_check
  106. cmp es:[di].ga_handle, di
  107. je no_limit_check
  108. push bx
  109. push cx
  110. push si
  111. push ds
  112. smov ds, gdtdsc
  113. mov si, es:[di].ga_handle
  114. sel_check si
  115. sub bx, 1
  116. sbb cx, 0
  117. or cx, cx ; More than 1 selector?
  118. jz @F
  119. mov bx, -1
  120. @@:
  121. cmp [si], bx
  122. jne bad_limit
  123. mov ch, [si+6]
  124. and cx, 0F0Fh
  125. cmp ch, cl
  126. je ok_limit
  127. bad_limit:
  128. Debug_Out "gacheck: Bad limit for #SI"
  129. ok_limit:
  130. pop ds
  131. pop si
  132. pop cx
  133. pop bx
  134. no_limit_check:
  135. cmp es:[di].ga_owner,GA_NOT_THERE ;286pmode has some of these
  136. jnz check_size ; with 0 size
  137. pop cx
  138. jmp short size_ok
  139. check_size:
  140. add bx, ax
  141. adc cx, dx
  142. cCall get_physical_address, <es:[di].ga_next>
  143. cmp cx, dx
  144. pop cx
  145. mov dx, es
  146. xchg ax, dx
  147. jne forward_size_mismatch
  148. cmp dx, bx
  149. jne forward_size_mismatch
  150. size_ok:
  151. mov ax, es
  152. mov dx, es:[di].ga_next
  153. mov es, dx
  154. cmp ax, es:[di].ga_prev
  155. jz size_and_next_match
  156. forward_size_mismatch:
  157. cmp cx,1
  158. jnz forward_links_invalid
  159. size_and_next_match:
  160. loop xxxx
  161. cmp ax,[di].hi_last
  162. jz forward_links_okay
  163. forward_links_invalid:
  164. Debug_Out "gacheck: Forward links invalid"
  165. mov dx,ax
  166. mov ax,1
  167. jmp all_done
  168. xxxx:
  169. jmp forward_ho
  170. forward_links_okay:
  171. xor ax, ax
  172. clear_dx_all_done:
  173. xor dx,dx
  174. all_done:
  175. pop es
  176. pop ds
  177. pop si
  178. pop di
  179. pop cx
  180. pop bx
  181. or ax,ax
  182. jnz cgh_error
  183. pop dx
  184. pop ax
  185. ret
  186. cgh_error:
  187. int 3
  188. add sp,4
  189. stc
  190. ret
  191. cEnd nogen
  192. sEnd CODE
  193. endif
  194. end