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.

225 lines
4.6 KiB

  1. /*
  2. * segment.c - Segment functions of DBG DLL.
  3. *
  4. */
  5. #include <precomp.h>
  6. #pragma hdrstop
  7. void
  8. SegmentLoad(
  9. LPSTR lpModuleName,
  10. LPSTR lpPathName,
  11. WORD Selector,
  12. WORD Segment,
  13. BOOL fData
  14. )
  15. {
  16. if ( fDebugged ) {
  17. SEGMENT_NOTE se;
  18. DbgGetContext();
  19. RtlFillMemory( &se, sizeof(se), (UCHAR)0 );
  20. se.Selector1 = Selector;
  21. se.Segment = Segment+1; // make it one-based
  22. se.Type = fData ? SN_DATA : SN_CODE;
  23. strncpy(se.FileName, lpPathName,
  24. min(strlen(lpPathName), MAX_PATH16-1) );
  25. strncpy(se.Module, lpModuleName,
  26. min(strlen(lpModuleName), MAX_MODULE-1) );
  27. EventParams[2] = (DWORD)&se;
  28. SendVDMEvent(DBG_SEGLOAD);
  29. }
  30. }
  31. void
  32. SegmentMove(
  33. WORD OldSelector,
  34. WORD NewSelector
  35. )
  36. {
  37. if ( fDebugged ) {
  38. SEGMENT_NOTE se;
  39. DbgGetContext();
  40. RtlFillMemory( &se, sizeof(se), (UCHAR)0 );
  41. se.Selector1 = OldSelector;
  42. se.Selector2 = NewSelector;
  43. EventParams[2] = (DWORD)&se;
  44. SendVDMEvent(DBG_SEGMOVE);
  45. }
  46. }
  47. void
  48. SegmentFree(
  49. WORD Selector,
  50. BOOL fBPRelease
  51. )
  52. {
  53. if ( fDebugged ) {
  54. SEGMENT_NOTE se;
  55. DbgGetContext();
  56. RtlFillMemory( &se, sizeof(se), (UCHAR)0 );
  57. se.Selector1 = Selector;
  58. se.Type = (WORD)fBPRelease;
  59. EventParams[2] = (DWORD)&se;
  60. SendVDMEvent(DBG_SEGFREE);
  61. }
  62. }
  63. void
  64. ModuleLoad(
  65. LPSTR lpModuleName,
  66. LPSTR lpPathName,
  67. WORD Segment,
  68. DWORD Length
  69. )
  70. {
  71. if ( fDebugged ) {
  72. SEGMENT_NOTE se;
  73. DbgGetContext();
  74. RtlFillMemory( &se, sizeof(se), (UCHAR)0 );
  75. se.Selector1 = Segment;
  76. se.Length = Length;
  77. strncpy(se.FileName, lpPathName,
  78. min(strlen(lpPathName), MAX_PATH16-1) );
  79. strncpy(se.Module, lpModuleName,
  80. min(strlen(lpModuleName), MAX_MODULE-1) );
  81. EventParams[2] = (DWORD)&se;
  82. SendVDMEvent(DBG_MODLOAD);
  83. }
  84. }
  85. void
  86. ModuleSegmentMove(
  87. LPSTR lpModuleName,
  88. LPSTR lpPathName,
  89. WORD ModuleSegment,
  90. WORD OldSelector,
  91. WORD NewSelector,
  92. DWORD Length
  93. )
  94. {
  95. if ( fDebugged ) {
  96. SEGMENT_NOTE se;
  97. DbgGetContext();
  98. RtlFillMemory( &se, sizeof(se), (UCHAR)0 );
  99. se.Segment = ModuleSegment;
  100. se.Selector1 = OldSelector;
  101. se.Selector2 = NewSelector;
  102. se.Type = SN_V86;
  103. se.Length = Length;
  104. strncpy(se.FileName, lpPathName,
  105. min(strlen(lpPathName), MAX_PATH16-1) );
  106. strncpy(se.Module, lpModuleName,
  107. min(strlen(lpModuleName), MAX_MODULE-1) );
  108. EventParams[2] = (DWORD)&se;
  109. SendVDMEvent(DBG_SEGMOVE);
  110. }
  111. }
  112. void
  113. ModuleFree(
  114. LPSTR lpModuleName,
  115. LPSTR lpPathName
  116. )
  117. {
  118. if ( fDebugged ) {
  119. SEGMENT_NOTE se;
  120. DbgGetContext();
  121. RtlFillMemory( &se, sizeof(se), (UCHAR)0 );
  122. strncpy(se.FileName, lpPathName,
  123. min(strlen(lpPathName), MAX_PATH16-1) );
  124. strncpy(se.Module, lpModuleName,
  125. min(strlen(lpModuleName), MAX_MODULE-1) );
  126. EventParams[2] = (DWORD)&se;
  127. SendVDMEvent(DBG_MODFREE);
  128. }
  129. }
  130. void
  131. xxxDbgSegmentNotice(
  132. WORD wType,
  133. WORD wModuleSeg,
  134. WORD wLoadSeg,
  135. WORD wNewSeg,
  136. LPSTR lpModuleName,
  137. LPSTR lpModulePath,
  138. DWORD dwImageLen )
  139. /* DbgSegmentNotice
  140. *
  141. * packs up the data and raises STATUS_SEGMENT_NOTIFICATION
  142. *
  143. * Entry - WORD wType - DBG_MODLOAD, DBG_MODFREE
  144. * WORD wModuleSeg- segment number within module (1 based)
  145. * WORD wLoadSeg - Starting Segment (reloc factor)
  146. * LPSTR lpName - ptr to Name of Image
  147. * DWORD dwModLen - Length of module
  148. *
  149. *
  150. * if wType ==DBG_MODLOAD wOldLoadSeg is unused
  151. * if wType ==DBG_MODFREE wLoadSeg,dwImageLen,wOldLoadSeg are unused
  152. *
  153. * Use 0 or NULL for unused parameters
  154. *
  155. * Exit - void
  156. *
  157. */
  158. {
  159. if (!fDebugged) {
  160. return;
  161. }
  162. if (wType == DBG_MODLOAD) {
  163. ModuleLoad(lpModuleName, lpModulePath, wLoadSeg, dwImageLen);
  164. } else if (wType == DBG_MODFREE) {
  165. ModuleFree(lpModuleName, lpModulePath);
  166. } else if (wType == DBG_SEGMOVE) {
  167. ModuleSegmentMove(lpModuleName, lpModulePath, wModuleSeg, wLoadSeg, wNewSeg, dwImageLen);
  168. }
  169. }