Windows NT 4.0 source code leak
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.

361 lines
8.1 KiB

4 years ago
  1. /*++
  2. Revision History:
  3. 2-Feb-95 a-robw (Bob Watson)
  4. replaced Rtl... functions with local versions for Win95
  5. replaced KdPrint calls with calls to local CapDbgPrint
  6. --*/
  7. #include "cap.h"
  8. #ifdef i386
  9. /*********************** CAP_SetJump *******************************
  10. *
  11. * CAP_SetJmp(jmp_buf jmpBuf)
  12. *
  13. *
  14. * Purpose: Setup information from setjmp call for possible disposition
  15. * of a subsequent longjmp allso gets current datacell info
  16. * for longjmp
  17. *
  18. * Params: jmpBuf Environment array for longjmp
  19. *
  20. *
  21. * Return: -none-
  22. *
  23. *
  24. * History:
  25. * 12.19.92 MarkLea -- created
  26. *
  27. */
  28. void CAP_SetJmp(jmp_buf jmpBuf)
  29. {
  30. PTHDBLK pthdblk;
  31. PJMPINFO pJmpInfo;
  32. LARGE_INTEGER liStart;
  33. LARGE_INTEGER liEnd;
  34. LONGLONG liWaste;
  35. SaveAllRegs ();
  36. SETCAPINUSE();
  37. QueryPerformanceCounter (&liStart);
  38. pthdblk = GETCURTHDBLK();
  39. pJmpInfo = &(pthdblk->jmpinfo);
  40. pJmpInfo->jmpBuf[pJmpInfo->nJmpCnt] = jmpBuf;
  41. pJmpInfo->ulCurCell[pJmpInfo->nJmpCnt] = pthdblk->ulCurCell;
  42. pJmpInfo->nJmpCnt++;
  43. QueryPerformanceCounter (&liEnd);
  44. liWaste = liEnd.QuadPart - liStart.QuadPart;
  45. liWaste += liWasteOverheadSavRes;
  46. pthdblk->liWasteCount += liWaste;
  47. SETUPPrint (("CAP: SetJmp() - liWaste = 0x%x%x\n",
  48. liWaste));
  49. RESETCAPINUSE();
  50. RestoreAllRegs ();
  51. _asm
  52. {
  53. mov esp,ebp
  54. pop ebp
  55. jmp setjmpaddr
  56. }
  57. } /* CAP_SetJmp () */
  58. /*********************** CAP_LongJump *******************************
  59. *
  60. * CAP_LongJmp(jmp_buf jmpBuf, int nRet)
  61. *
  62. *
  63. * Purpose: Intercepts lonkjmp call for disposition of CAP data and
  64. * to restore the datacell to the position at the time of the
  65. * associated setjmp call. Sets the current data cell pointer
  66. * to the pointer from the associated setjmp call. Cleans up
  67. * the data collection by calling PostPenter.
  68. *
  69. * Params: jmpBuf Environment array for restoring the stack
  70. * nRet return value for setjmp
  71. *
  72. * Return: -none-
  73. *
  74. *
  75. * History:
  76. * 12.19.92 MarkLea -- created
  77. * 12.21.92 MarkLea -- added what I hope is M-thread support
  78. * -- added call to PostPenter.
  79. *
  80. */
  81. void CAP_LongJmp(jmp_buf jmpBuf, int nRet)
  82. {
  83. int nIndex;
  84. PTHDBLK pthdblk;
  85. PJMPINFO pJmpInfo;
  86. LARGE_INTEGER liStart;
  87. LARGE_INTEGER liEnd;
  88. LONGLONG liWaste;
  89. SaveAllRegs ();
  90. SETCAPINUSE();
  91. QueryPerformanceCounter (&liStart);
  92. pthdblk = GETCURTHDBLK();
  93. nIndex = 0;
  94. pJmpInfo = &(pthdblk->jmpinfo);
  95. //
  96. // Search for the correct jmpbuf and ulCurCell
  97. //
  98. while(jmpBuf != pJmpInfo->jmpBuf[nIndex])
  99. {
  100. nIndex++;
  101. //
  102. // If we get here, there is something wrong, so abort the cap
  103. //
  104. if (nIndex == pJmpInfo->nJmpCnt)
  105. {
  106. CapDbgPrint ("CAP: CAP_LongJmp() - Too many setjmp() calls\n");
  107. fProfiling=FALSE;
  108. }
  109. }
  110. //
  111. // Call PostPenter to cleanup the times from the current cell
  112. //
  113. //PostPenter(pthdblk);
  114. PostPenter();
  115. SETCAPINUSE(); // PostPenter() resets this
  116. //
  117. // Set the Current cell to the one that was current when the
  118. // setjmp call was made
  119. //
  120. pthdblk->ulCurCell = pJmpInfo->ulCurCell[nIndex];
  121. QueryPerformanceCounter (&liEnd);
  122. liWaste = liEnd.QuadPart - liStart.QuadPart;
  123. liWaste += liWasteOverheadSavRes;
  124. pthdblk->liWasteCount += liWaste;
  125. SETUPPrint (("CAP: LongJmp() - liWaste = 0x%x%x\n",
  126. liWaste));
  127. RESETCAPINUSE();
  128. RestoreAllRegs ();
  129. //
  130. // Now we need to call the original longjmp routine so we can complete
  131. // execution.
  132. //
  133. _asm
  134. {
  135. mov esp,ebp
  136. pop ebp
  137. jmp longjmpaddr
  138. }
  139. } /* CAP_LongJmp () */
  140. #endif // ifdef i386
  141. /*********************** CAP_LoadLibrary *******************************
  142. *
  143. * CAP_LoadLibraryA (),
  144. * CAP_LoadLibraryExA (),
  145. * CAP_LoadLibraryW (),
  146. * CAP_LoadLibraryExW (),
  147. *
  148. *
  149. * Purpose:
  150. *
  151. * Params: -none-
  152. *
  153. * Return: -none-
  154. *
  155. *
  156. * History:
  157. * 12.19.92 MarkLea -- created
  158. *
  159. */
  160. HANDLE CAP_LoadLibraryA (LPCSTR lpName)
  161. {
  162. PTHDBLK pthdblk;
  163. LARGE_INTEGER liStart;
  164. LARGE_INTEGER liEnd;
  165. LONGLONG liWaste;
  166. HANDLE hLib;
  167. hLib = LoadLibraryA (lpName);
  168. SETCAPINUSE();
  169. if (hLib && (fProfiling || fPaused))
  170. {
  171. QueryPerformanceCounter (&liStart);
  172. SetupLibProfiling (lpName, TRUE);
  173. if ( pthdblk = GETCURTHDBLK() )
  174. {
  175. QueryPerformanceCounter (&liEnd);
  176. liWaste = liEnd.QuadPart - liStart.QuadPart;
  177. liWaste += liWasteOverheadSavRes;
  178. pthdblk->liWasteCount += liWaste;
  179. SETUPPrint (("CAP: LoadLibraryA() - liWaste = 0x%x%x\n",
  180. liWaste));
  181. }
  182. }
  183. RESETCAPINUSE();
  184. return (hLib);
  185. } /* CAP_LoadLibraryA () */
  186. /*********************** CAP_LoadLibrary *******************************/
  187. HANDLE CAP_LoadLibraryExA (LPCSTR lpName, HANDLE hFile, DWORD dwFlags)
  188. {
  189. PTHDBLK pthdblk;
  190. LARGE_INTEGER liStart;
  191. LARGE_INTEGER liEnd;
  192. LONGLONG liWaste;
  193. HANDLE hLib;
  194. hLib = LoadLibraryExA (lpName, hFile, dwFlags);
  195. SETCAPINUSE();
  196. if (hLib && (fProfiling || fPaused))
  197. {
  198. QueryPerformanceCounter (&liStart);
  199. SetupLibProfiling (lpName, TRUE);
  200. if ( pthdblk = GETCURTHDBLK() )
  201. {
  202. QueryPerformanceCounter (&liEnd);
  203. liWaste = liEnd.QuadPart - liStart.QuadPart;
  204. liWaste += liWasteOverheadSavRes;
  205. pthdblk->liWasteCount += liWaste;
  206. SETUPPrint (("CAP: LoadLibraryExA() - liWaste = 0x%x%x\n",
  207. liWaste));
  208. }
  209. }
  210. RESETCAPINUSE();
  211. return (hLib);
  212. } /* CAP_LoadLibraryExA () */
  213. #ifndef _CHICAGO_
  214. /*********************** CAP_LoadLibraryW *******************************/
  215. HANDLE CAP_LoadLibraryW (LPCWSTR lpName)
  216. {
  217. PTHDBLK pthdblk;
  218. LARGE_INTEGER liStart;
  219. LARGE_INTEGER liEnd;
  220. LONGLONG liWaste;
  221. UNICODE_STRING ucImageName;
  222. STRING ImageName;
  223. HANDLE hLib;
  224. hLib = LoadLibraryW (lpName);
  225. SETCAPINUSE();
  226. if (hLib && (fProfiling || fPaused))
  227. {
  228. QueryPerformanceCounter (&liStart);
  229. CapInitUnicodeString (&ucImageName, lpName);
  230. CapUnicodeStringToAnsiString (&ImageName, &ucImageName, TRUE);
  231. SetupLibProfiling (ImageName.Buffer, TRUE);
  232. if ( pthdblk = GETCURTHDBLK() )
  233. {
  234. QueryPerformanceCounter (&liEnd);
  235. liWaste = liEnd.QuadPart - liStart.QuadPart;
  236. liWaste += liWasteOverheadSavRes;
  237. pthdblk->liWasteCount += liWaste;
  238. SETUPPrint (("CAP: LoadLibraryW() - liWaste = 0x%x%x\n",
  239. liWaste));
  240. }
  241. }
  242. RESETCAPINUSE();
  243. return (hLib);
  244. } /* CAP_LoadLibraryW () */
  245. /*********************** CAP_LoadLibraryExW *******************************/
  246. HANDLE CAP_LoadLibraryExW (LPCWSTR lpName, HANDLE hFile, DWORD dwFlags)
  247. {
  248. PTHDBLK pthdblk;
  249. LARGE_INTEGER liStart;
  250. LARGE_INTEGER liEnd;
  251. LONGLONG liWaste;
  252. UNICODE_STRING ucImageName;
  253. STRING ImageName;
  254. HANDLE hLib;
  255. hLib = LoadLibraryExW (lpName, hFile, dwFlags);
  256. SETCAPINUSE();
  257. if (hLib && (fProfiling || fPaused))
  258. {
  259. QueryPerformanceCounter (&liStart);
  260. CapInitUnicodeString (&ucImageName, lpName);
  261. CapUnicodeStringToAnsiString (&ImageName, &ucImageName, TRUE);
  262. SetupLibProfiling (ImageName.Buffer, TRUE);
  263. if ( pthdblk = GETCURTHDBLK() )
  264. {
  265. QueryPerformanceCounter (&liEnd);
  266. liWaste = liEnd.QuadPart - liStart.QuadPart;
  267. liWaste += liWasteOverheadSavRes;
  268. pthdblk->liWasteCount += liWaste;
  269. SETUPPrint (("CAP: LoadLibraryExW() - liWaste = 0x%x%x\n",
  270. liWaste));
  271. }
  272. }
  273. RESETCAPINUSE();
  274. return (hLib);
  275. } /* CAP_LoadLibraryExW () */
  276. #endif // !_CHICAGO_