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.

889 lines
22 KiB

  1. /****************************************************************************
  2. INTEL CORPORATION PROPRIETARY INFORMATION
  3. Copyright (c) 1992 Intel Corporation
  4. All Rights Reserved
  5. This software is supplied under the terms of a license
  6. agreement or non-disclosure agreement with Intel Corporation
  7. and may not be copied or disclosed except in accordance
  8. with the terms of that agreement
  9. $Source: q:/prism/network/isrdbg/rcs/isrdbg.c $
  10. $Revision: 1.3 $
  11. $Date: 30 Dec 1996 16:44:32 $
  12. $Author: EHOWARDX $
  13. $Locker: $
  14. Description
  15. -----------
  16. VCITest - test harness for VCI and underlaying subsystems.
  17. ****************************************************************************/
  18. // Turn off Windows stuff will never use.
  19. #define NOSOUND
  20. #define NOSYSMETRICS
  21. #define NOTEXTMETRIC
  22. #define NOWH
  23. #define NOCOMM
  24. #define NOKANJI
  25. #ifndef STRICT
  26. #define STRICT
  27. #endif // not defined STRICT
  28. #include <windows.h>
  29. #include <string.h>
  30. #define ISRDBG32_C
  31. #include <isrg.h> // exports to functions.
  32. #include "isrdbg32.h" // private header file for this app
  33. HINSTANCE ghAppInstance = 0; // global instance handle
  34. // Global lock to protect:
  35. // gStrTabOfs, guNumItems
  36. HANDLE gSemaphore = 0; // global semaphore for accessing dbg info.
  37. // Most data needs to be globally mapped because info is shared with viewer and apps
  38. // placing debug info into the buffers.
  39. typedef struct _tDS
  40. {
  41. UINT uBindCount; // How many copies of this DLL have run.
  42. UINT guNumModules;
  43. UINT guNumItems;
  44. UINT gStrTabOfs;
  45. WORD ghDefaultModule;
  46. } tDS,*ptDS;
  47. HANDLE ghDS = 0;
  48. ptDS gpDS = NULL;
  49. HANDLE ghModuleTable = 0;
  50. ptISRModule gpModuleTable = NULL;
  51. HANDLE ghDbgTable = 0;
  52. ptISRItem gpDbgTable = NULL;
  53. HANDLE ghzStrTab = 0;
  54. LPSTR gpzStrTab = NULL;
  55. //------------------------------------------------------------------------------
  56. ptISRItem WINAPI
  57. ISR_GetItemInternal (UINT uItem);
  58. //------------------------------------------------------------------------------
  59. BOOL MapGlobalWin32Memory(void** pMem,HANDLE* hMem,UINT MemSize,char* MemName)
  60. {
  61. BOOL fInit;
  62. if (!pMem || !hMem)
  63. return FALSE;
  64. *hMem = CreateFileMapping(
  65. INVALID_HANDLE_VALUE, // use paging file
  66. NULL, // no security attr.
  67. PAGE_READWRITE, // read/write access
  68. 0, // size: high 32-bits
  69. MemSize, // size: low 32-bits
  70. MemName); // name of map object
  71. if (!*hMem)
  72. return FALSE;
  73. // The first process to attach initializes memory.
  74. fInit = (GetLastError() != ERROR_ALREADY_EXISTS);
  75. // Get a pointer to the file-mapped shared memory.
  76. *pMem = MapViewOfFile(
  77. *hMem, // object to map view of
  78. FILE_MAP_WRITE, // read/write access
  79. 0, // high offset: map from
  80. 0, // low offset: beginning
  81. 0); // default: map entire file
  82. if (!*pMem)
  83. {
  84. CloseHandle(*hMem);
  85. *hMem = 0;
  86. return FALSE;
  87. }
  88. // Initialize memory if this is the first process.
  89. if (fInit)
  90. {
  91. memset(*pMem,0,MemSize);
  92. }
  93. return TRUE;
  94. }
  95. void FreeGlobalWin32Memory(void* pMem,HANDLE hMem)
  96. {
  97. // Unmap shared memory from the process's address space.
  98. if (pMem)
  99. UnmapViewOfFile(pMem);
  100. // Close the process's handle to the file-mapping object.
  101. if (hMem)
  102. CloseHandle(hMem);
  103. }
  104. //------------------------------------------------------------------------------
  105. // InitModules
  106. // Init the Module filters on startup.
  107. // Do not init the filters when the module is registered.
  108. // The display app may have some global filters in effect by the time
  109. // the individual register module calls come in.
  110. //------------------------------------------------------------------------------
  111. static void
  112. InitModules (void)
  113. {
  114. UINT hMod;
  115. ptISRModule pMod;
  116. for (hMod = 0; hMod < kMaxModules; hMod++)
  117. {
  118. pMod = ISR_GetModule(hMod);
  119. if (!pMod)
  120. break;
  121. pMod->DisplayFilter = 0xFF;
  122. pMod->CaptureFilter = 0xFF;
  123. }
  124. }
  125. //------------------------------------------------------------------------------
  126. // ValidCaptureMsg
  127. // Validate the capture filters to determine if this message should be
  128. // dropped.
  129. //
  130. // Returns:
  131. // TRUE - if msg is valid and should be kept
  132. // FALSE - if msg is filtered out and should be dropped.
  133. //------------------------------------------------------------------------------
  134. static UINT
  135. ValidCaptureMsg (WORD hISRInst, BYTE DbgLevel)
  136. {
  137. ptISRModule pMod;
  138. pMod = ISR_GetModule(hISRInst);
  139. if (!pMod)
  140. return FALSE;
  141. if (DbgLevel & pMod->CaptureFilter)
  142. return TRUE;
  143. else
  144. return FALSE;
  145. }
  146. //------------------------------------------------------------------------------
  147. // OutputRec ()
  148. // Store a string resource Id to be displayed at task time.
  149. // In addition store a number to be displayed in printf format of the
  150. // string.
  151. //------------------------------------------------------------------------------
  152. ISR_DLL void WINAPI
  153. OutputRec
  154. (
  155. WORD hISRInst, // Our handle to registered modules
  156. BYTE DbgLevel, // Caller determined debug level
  157. BYTE Flags,
  158. UINT IP, // Callers Instruction Ptr address
  159. DWORD Param1,
  160. DWORD Param2
  161. )
  162. {
  163. ptISRItem pItem;
  164. UINT uItem;
  165. // Capture Filter
  166. if ( !ValidCaptureMsg(hISRInst, DbgLevel) )
  167. return;
  168. // Protect against reentrancy. Just drop the msg if reentered.
  169. if (WAIT_OBJECT_0 != WaitForSingleObject(gSemaphore,100))
  170. return;
  171. uItem = gpDS->guNumItems++;
  172. if (kMaxISRItems <= gpDS->guNumItems)
  173. {
  174. gpDS->guNumItems = 0;
  175. }
  176. ReleaseSemaphore(gSemaphore,1,NULL);
  177. pItem = ISR_GetItemInternal(uItem);
  178. if (!pItem)
  179. {
  180. // This is a serious bug. Our debugger is even hosed.
  181. // Need to think of a way to indicate this to the user.
  182. return;
  183. }
  184. pItem->hISRInst = hISRInst;
  185. pItem->DbgLevel = DbgLevel;
  186. pItem->Flags = Flags;
  187. pItem->IP = IP;
  188. pItem->Param1 = Param1;
  189. pItem->Param2 = Param2;
  190. }
  191. //------------------------------------------------------------------------------
  192. //------------------------------------------------------------------------------
  193. ISR_DLL void WINAPI
  194. OutputRecStr
  195. (
  196. WORD hISRInst, // Our handle to registered modules
  197. BYTE DbgLevel, // Caller determined debug level
  198. BYTE Flags,
  199. UINT IP, // Callers Instruction Ptr address
  200. LPSTR pzStr1,
  201. LPSTR pzStr2,
  202. DWORD Param1
  203. )
  204. {
  205. LPSTR pzStrTab;
  206. UINT uStrOfs;
  207. UINT uStrLen;
  208. UINT StrLen1;
  209. UINT StrLen2;
  210. // Capture Filter
  211. if ( !ValidCaptureMsg(hISRInst, DbgLevel) )
  212. return;
  213. if (pzStr1)
  214. StrLen1 = lstrlen(pzStr1);
  215. else
  216. StrLen1 = 0;
  217. if (pzStr2)
  218. StrLen2 = lstrlen(pzStr2);
  219. else
  220. StrLen2 = 0;
  221. uStrLen = StrLen1 + StrLen2 + 1; // 1 for null terminator.
  222. if (kMaxStrTab <= uStrLen)
  223. {
  224. return; // It is so big.
  225. }
  226. // Protect against reentrancy. Just drop the msg if reentered.
  227. if (WAIT_OBJECT_0 != WaitForSingleObject(gSemaphore,100))
  228. return;
  229. uStrOfs = gpDS->gStrTabOfs;
  230. gpDS->gStrTabOfs += uStrLen;
  231. if (kMaxStrTab <= gpDS->gStrTabOfs)
  232. {
  233. uStrOfs = 0;
  234. gpDS->gStrTabOfs = uStrLen;
  235. // Also reset items which would otherwise point in trashed strings.
  236. gpDS->guNumItems = 0;
  237. }
  238. pzStrTab = gpzStrTab + uStrOfs;
  239. ReleaseSemaphore(gSemaphore,1,NULL);
  240. if (pzStr1)
  241. lstrcpy(pzStrTab, pzStr1);
  242. if (pzStr2)
  243. lstrcpy(pzStrTab+StrLen1, pzStr2);
  244. OutputRec(hISRInst, DbgLevel, kParam1IsStr, IP, uStrOfs, Param1);
  245. }
  246. //------------------------------------------------------------------------------
  247. // ISR_HookDbgStrStr
  248. // Allow two strings to be concatenated together.
  249. //------------------------------------------------------------------------------
  250. ISR_DLL void WINAPI DLL_EXPORT
  251. ISR_HookDbgStrStr (UINT IP, WORD hISRInst, BYTE DbgLevel, LPSTR pzStr1, LPSTR pzStr2)
  252. {
  253. OutputRecStr(hISRInst, DbgLevel, kParam1IsStr, IP, pzStr1, pzStr2, 0);
  254. }
  255. //------------------------------------------------------------------------------
  256. // ISR_HookDbgRes
  257. // Use a resource to format a number.
  258. //------------------------------------------------------------------------------
  259. ISR_DLL void WINAPI DLL_EXPORT
  260. ISR_HookDbgRes (UINT IP, WORD hISRInst, BYTE DbgLevel, UINT uResId, DWORD Param1)
  261. {
  262. OutputRec(hISRInst, DbgLevel, kParam1IsRes, IP, uResId, Param1);
  263. }
  264. //------------------------------------------------------------------------------
  265. // ISR_HookDbgStr
  266. // Use a str to format a number.
  267. //------------------------------------------------------------------------------
  268. ISR_DLL void WINAPI DLL_EXPORT
  269. ISR_HookDbgStr (UINT IP, WORD hISRInst, BYTE DbgLevel, LPSTR pzStr1, DWORD Param1)
  270. {
  271. OutputRecStr(hISRInst, DbgLevel, kParam1IsStr, IP, pzStr1, 0, Param1);
  272. }
  273. //------------------------------------------------------------------------------
  274. // ISR_DbgStrStr
  275. // Allow two strings to be concatenated together.
  276. //------------------------------------------------------------------------------
  277. ISR_DLL void WINAPI DLL_EXPORT
  278. ISR_DbgStrStr (WORD hISRInst, BYTE DbgLevel, LPSTR pzStr1, LPSTR pzStr2)
  279. {
  280. UINT IP = 0;
  281. // _asm
  282. // {
  283. // push ax
  284. // mov ax,[bp+2]
  285. // mov IP,ax
  286. // pop ax
  287. // }
  288. ISR_HookDbgStrStr(IP, hISRInst, DbgLevel, pzStr1, pzStr2);
  289. }
  290. //------------------------------------------------------------------------------
  291. // ISR_DbgRes
  292. // Use a resource to format a number.
  293. //------------------------------------------------------------------------------
  294. ISR_DLL void WINAPI DLL_EXPORT
  295. ISR_DbgRes (WORD hISRInst, BYTE DbgLevel, UINT uResId, DWORD Param1)
  296. {
  297. UINT IP = 0;
  298. // _asm
  299. // {
  300. // push ax
  301. // mov ax,[bp+2]
  302. // mov IP,ax
  303. // pop ax
  304. // }
  305. ISR_HookDbgRes(IP, hISRInst, DbgLevel, uResId, Param1);
  306. }
  307. //------------------------------------------------------------------------------
  308. // ISR_DbgStr
  309. // Use a str to format a number.
  310. //------------------------------------------------------------------------------
  311. ISR_DLL void WINAPI DLL_EXPORT
  312. ISR_DbgStr (WORD hISRInst, BYTE DbgLevel, LPSTR pzStr1, DWORD Param1)
  313. {
  314. UINT IP = 0;
  315. // _asm
  316. // {
  317. // push ax
  318. // mov ax,[bp+2]
  319. // mov IP,ax
  320. // pop ax
  321. // }
  322. ISR_HookDbgStr(IP, hISRInst, DbgLevel, pzStr1, Param1);
  323. }
  324. //------------------------------------------------------------------------------
  325. // TT_DbgMsg
  326. // This function builds a formatted string, based upon numeric or
  327. // string input parameters, and sends the string to isrdbg.dll to
  328. // be displayed in the isrdsp.exe window. THIS FUNCTION CAN NOT
  329. // BE CALLED AT INTERRUPT-TIME. This function uses the same
  330. // mechanism as isrdbg.dll to enable/disable debug output.
  331. //
  332. // In:
  333. // hISRInst, - Module's ISRDBG handle.
  334. // DbgLevel, - Appropriate ISRDBG level.
  335. // zMsgFmt, - Output format string (like printf).
  336. // ... - Optional parameter list.
  337. //
  338. // Out:
  339. // none
  340. //
  341. // Return:
  342. // none
  343. //------------------------------------------------------------------------------
  344. ISR_DLL void FAR cdecl DLL_EXPORT
  345. TTDbgMsg
  346. (
  347. WORD hISRInst,
  348. BYTE DbgLevel,
  349. LPCSTR zMsgFmt,
  350. ...
  351. )
  352. {
  353. WORD TempIP = 0;
  354. char MsgBuf[256];
  355. // _asm
  356. // {
  357. // push ax
  358. // mov ax,[bp+2]
  359. // mov TempIP,ax
  360. // pop ax
  361. // }
  362. #ifdef _M_ALPHA
  363. va_list valDummy;
  364. ZeroMemory(&valDummy, sizeof(valDummy));
  365. va_start (valDummy,zMsgFmt);
  366. wvsprintf (MsgBuf, zMsgFmt, valDummy);
  367. va_end (valDummy);
  368. #else // _M_ALPHA
  369. wvsprintf (MsgBuf, zMsgFmt, (va_list) (&zMsgFmt + 1));
  370. #endif // _M_ALPHA
  371. ISR_HookDbgStrStr(TempIP, hISRInst, DbgLevel, MsgBuf, 0);
  372. }
  373. //------------------------------------------------------------------------------
  374. // ISR_OutputDbgStr ()
  375. // Store a string to be displayed at task time.
  376. // The passed in string will be copied to a local storage.
  377. // Therefore the caller can reuse on return.
  378. //------------------------------------------------------------------------------
  379. ISR_DLL void WINAPI DLL_EXPORT
  380. ISR_OutputDbgStr (LPSTR pzStr)
  381. {
  382. WORD TempIP = 0;
  383. // _asm
  384. // {
  385. // push ax
  386. // mov ax,[bp+2]
  387. // mov TempIP,ax
  388. // pop ax
  389. // }
  390. ISR_HookDbgStrStr(TempIP, gpDS->ghDefaultModule, kISRDefault, pzStr, 0);
  391. }
  392. //------------------------------------------------------------------------------
  393. // ISR_OutputStr ()
  394. // Store a string resource Id to be displayed at task time.
  395. //------------------------------------------------------------------------------
  396. ISR_DLL void WINAPI DLL_EXPORT
  397. ISR_OutputStr (UINT uResId)
  398. {
  399. UINT TempIP = 0;
  400. // _asm
  401. // {
  402. // push ax
  403. // mov ax,[bp+2]
  404. // mov TempIP,ax
  405. // pop ax
  406. // }
  407. ISR_HookDbgRes(TempIP, gpDS->ghDefaultModule, kISRDefault, uResId, 0);
  408. }
  409. //------------------------------------------------------------------------------
  410. // ISR_OutputNum ()
  411. // Store a string resource Id to be displayed at task time.
  412. // In addition store a number to be displayed in printf format of the
  413. // string.
  414. //------------------------------------------------------------------------------
  415. ISR_DLL void WINAPI DLL_EXPORT
  416. ISR_OutputNum (UINT uResId, DWORD Num)
  417. {
  418. WORD TempIP = 0;
  419. // _asm
  420. // {
  421. // push ax
  422. // mov ax,[bp+2]
  423. // mov TempIP,ax
  424. // pop ax
  425. // }
  426. ISR_HookDbgRes(TempIP, gpDS->ghDefaultModule, kISRDefault, uResId, Num);
  427. }
  428. //------------------------------------------------------------------------------
  429. // DbgMsg ()
  430. // Canned Debug format that may be useful. This function has nothen
  431. // to do with Interrupt time display. However it keeps all the
  432. // display info in one place. Basically it is convenient.
  433. //
  434. // WARNING: Do not call this at interrupt time. wsprintf is not reentrant.
  435. //------------------------------------------------------------------------------
  436. ISR_DLL void FAR cdecl DLL_EXPORT
  437. DbgMsg
  438. (
  439. LPCSTR module,
  440. int state,
  441. LPCSTR format_str,
  442. ...
  443. )
  444. {
  445. WORD TempIP = 0;
  446. char MsgBuf[256];
  447. va_list valDummy;
  448. // _asm
  449. // {
  450. // push ax
  451. // mov ax,[bp+2]
  452. // mov TempIP,ax
  453. // pop ax
  454. // }
  455. wsprintf (MsgBuf, ">--<%s> %s", module,
  456. (LPSTR) ((state == ISR_DBG) ? "debug : " : "ERROR : "));
  457. #ifdef _M_ALPHA
  458. ZeroMemory(&valDummy, sizeof(valDummy));
  459. va_start (valDummy,format_str);
  460. wvsprintf ((LPSTR) (MsgBuf + lstrlen (MsgBuf)), format_str,valDummy);
  461. va_end (valDummy);
  462. #else // _M_ALPHA
  463. wvsprintf ((LPSTR) (MsgBuf + lstrlen (MsgBuf)), format_str,
  464. (va_list) (&format_str + 1));
  465. #endif // _M_ALPHA
  466. ISR_HookDbgStrStr(TempIP, gpDS->ghDefaultModule, kISRDefault, MsgBuf, 0);
  467. // lstrcat (MsgBuf, "\n");
  468. // OutputDebugString (MsgBuf);
  469. }
  470. //------------------------------------------------------------------------------
  471. // ISR_ClearItems ()
  472. // Clear the list of debug msgs.
  473. //------------------------------------------------------------------------------
  474. ISR_DLL void WINAPI DLL_EXPORT
  475. ISR_ClearItems (void)
  476. {
  477. // Protect against reentrancy. Just drop the msg if reentered.
  478. if (WAIT_OBJECT_0 != WaitForSingleObject(gSemaphore,100))
  479. return;
  480. // This is not a serious race condition. Must likely failure
  481. // is what messages get dropped.
  482. gpDS->guNumItems = 0;
  483. gpDS->gStrTabOfs = 0;
  484. ReleaseSemaphore(gSemaphore,1,NULL);
  485. }
  486. //------------------------------------------------------------------------------
  487. // ISR_GetNumItems ()
  488. // Return the number of items that have be entered.
  489. //------------------------------------------------------------------------------
  490. ISR_DLL UINT WINAPI DLL_EXPORT
  491. ISR_GetNumItems (void)
  492. {
  493. return gpDS->guNumItems;
  494. }
  495. //------------------------------------------------------------------------------
  496. // ISR_GetNumModules ()
  497. // Return the number of modules that have be entered.
  498. //------------------------------------------------------------------------------
  499. ISR_DLL UINT WINAPI DLL_EXPORT
  500. ISR_GetNumModules (void)
  501. {
  502. return gpDS->guNumModules;
  503. }
  504. //------------------------------------------------------------------------------
  505. // ISR_GetItemInternal
  506. // Return a pointer to the record num uItem. Only reason to
  507. // do it this way is to hide the buf struct. This way I can use a
  508. // heap manager such as BigMem or SmartHeap or NT HeapAlloc.
  509. // The items are numbered 0..n-1.
  510. // Alternatively a Ptr to the array of records could be passed back.
  511. //------------------------------------------------------------------------------
  512. ptISRItem WINAPI
  513. ISR_GetItemInternal (UINT uItem)
  514. {
  515. if (kMaxISRItems <= uItem)
  516. {
  517. return NULL;
  518. }
  519. return &gpDbgTable[uItem];
  520. }
  521. //------------------------------------------------------------------------------
  522. // ISR_GetItem
  523. // Return a pointer to the record num uItem. Only reason to
  524. // do it this way is to hide the buf struct. This way I can use a
  525. // heap manager such as BigMem or SmartHeap or NT HeapAlloc.
  526. // The items are numbered 0..n-1.
  527. // Alternatively a Ptr to the array of records could be passed back.
  528. //------------------------------------------------------------------------------
  529. ISR_DLL ptISRItem WINAPI DLL_EXPORT
  530. ISR_GetItem (UINT uItem,ptISRItem pItem)
  531. {
  532. ptISRItem pISRItem;
  533. if (!pItem)
  534. {
  535. return NULL;
  536. }
  537. pISRItem = ISR_GetItemInternal(uItem);
  538. if (!pISRItem)
  539. {
  540. return NULL;
  541. }
  542. memcpy(pItem,pISRItem,sizeof(tISRItem));
  543. if (pISRItem->Flags & kParam1IsStr)
  544. {
  545. // This memory is shared so therefore need to make a copy for upper layers
  546. // Ptr within the struct are offsets so now need to be ptrs again.
  547. // Each instance of DLL in Win32 has its own memory map
  548. pItem->Param1 += (DWORD_PTR)gpzStrTab;
  549. }
  550. return pItem;
  551. }
  552. //------------------------------------------------------------------------------
  553. // ISR_RegisterModule
  554. // Register a name to be associated with related debug strings.
  555. // The debug display code can then present this information to the user
  556. // to determine how to filter the data.
  557. //
  558. // Params:
  559. // zShortName - name to display when space is critical.
  560. // zLongName - name to display when a complete description is needed.
  561. //
  562. // Returns:
  563. // on error zero for the compatible handle.
  564. // a handle to be used when making all other debug output calls.
  565. //------------------------------------------------------------------------------
  566. ISR_DLL void WINAPI DLL_EXPORT
  567. ISR_RegisterModule (LPWORD phISRInst, LPSTR pzShortName, LPSTR pzLongName)
  568. {
  569. ptISRModule pMod;
  570. UINT hMod;
  571. if (!phISRInst)
  572. return;
  573. *phISRInst = 0;
  574. if (kMaxModules <= gpDS->guNumModules)
  575. {
  576. // We are out of handles.
  577. // Return the default handle and drop the name info.
  578. return;
  579. }
  580. // Check if this module label was used before. If it has then just reuse it.
  581. // This case will most likely happen when the module is loaded, unloaded,
  582. // and then reloaded. Another case is when the same name is used in two
  583. // different instances. This would be a confusing programmer oversight
  584. // and that his problem.
  585. for (hMod = 0; hMod < kMaxModules; hMod++)
  586. {
  587. // if no name then we cannot group very well.
  588. // In this case waste another handle.
  589. if (!pzShortName || (0 == *pzShortName))
  590. break;
  591. pMod = ISR_GetModule(hMod);
  592. if (!pMod)
  593. break;
  594. if ( !_strnicmp(pzShortName,pMod->zSName,sizeof(pMod->zSName)-1) )
  595. {
  596. // It matched so just reuse it.
  597. *phISRInst = (WORD)hMod;
  598. return;
  599. }
  600. }
  601. *phISRInst = gpDS->guNumModules++;
  602. pMod = ISR_GetModule(*phISRInst);
  603. if (!pMod)
  604. return;
  605. if (pzShortName)
  606. strncpy(pMod->zSName,pzShortName,sizeof(pMod->zSName));
  607. pMod->zSName[sizeof(pMod->zSName)-1] = 0;
  608. if (pzLongName)
  609. strncpy(pMod->zLName,pzLongName,sizeof(pMod->zLName));
  610. pMod->zLName[sizeof(pMod->zLName)-1] = 0;
  611. return;
  612. }
  613. //------------------------------------------------------------------------------
  614. // ISR_GetModule
  615. // Return a pointer to the module record. Only reason to
  616. // do it this way is to hide the buf struct. This way I can use a
  617. // heap manager such as BigMem or SmartHeap or NT HeapAlloc.
  618. // Alternatively a Ptr to the array of records could be passed back.
  619. //------------------------------------------------------------------------------
  620. ISR_DLL ptISRModule WINAPI DLL_EXPORT
  621. ISR_GetModule (UINT hISRInst)
  622. {
  623. if (kMaxModules <= hISRInst)
  624. {
  625. return NULL;
  626. }
  627. return(&gpModuleTable[hISRInst]);
  628. }
  629. //------------------------------------------------------------------------------
  630. // ISR_SetCaptureFilter
  631. // Debug Messages for a given module can be dropped based on a low/high
  632. // filter. If the entire module is not wanted then call with
  633. // LoFilter = 255, and HiFilter = 0.
  634. //
  635. //------------------------------------------------------------------------------
  636. ISR_DLL int WINAPI DLL_EXPORT
  637. ISR_SetCaptureFilter (WORD hISRInst, BYTE CaptureFilter, BYTE DisplayFilter)
  638. {
  639. ptISRModule pMod;
  640. pMod = ISR_GetModule(hISRInst);
  641. if (!pMod)
  642. return -1;
  643. pMod->CaptureFilter = CaptureFilter;
  644. pMod->DisplayFilter = DisplayFilter;
  645. return 0;
  646. }
  647. /***************************************************************************
  648. LibMain()
  649. DLL entry point
  650. Parameters
  651. hDllInstance = instance handle of the DLL (NOT our caller!)
  652. wDataSegment = our DS
  653. wHeapSize = size of our heap in DS (see .def)
  654. lpzCmdLine = argv passed to application (our caller)
  655. Returns
  656. TRUE iff we were able to register our window class
  657. Side Effects
  658. - Unlocks our data segment (which is really a NOP for protect mode)
  659. ****************************************************************************/
  660. extern BOOL WINAPI
  661. DllMain
  662. (
  663. HINSTANCE hDllInstance,
  664. DWORD dwReason,
  665. PVOID pReserved
  666. )
  667. {
  668. switch (dwReason)
  669. {
  670. case DLL_PROCESS_ATTACH:
  671. {
  672. // Called for each exe binding. Each time a exe binds a different hDllInstance will
  673. // be passed in. Also our global data will be unique for each Process binding.
  674. ghAppInstance = hDllInstance;
  675. // Create a named file mapping object for the base table.
  676. MapGlobalWin32Memory(&gpDS,&ghDS,sizeof(tDS),"ISRDBG_DS");
  677. MapGlobalWin32Memory(&gpModuleTable,&ghModuleTable,sizeof(tISRModule) * kMaxModules,"ISRDBG_ModuleTable");
  678. MapGlobalWin32Memory(&gpDbgTable,&ghDbgTable,sizeof(tISRItem) * kMaxISRItems,"ISRDBG_DbgTable");
  679. MapGlobalWin32Memory(&gpzStrTab,&ghzStrTab,kMaxStrTab,"ISRDBG_StrTab");
  680. if (!gpDS || !gpModuleTable || !gpDbgTable || !gpzStrTab)
  681. {
  682. return FALSE;
  683. }
  684. gSemaphore = CreateSemaphore(NULL,1,1,NULL);
  685. if (!gpDS->uBindCount++)
  686. {
  687. // Set the filters before any output.
  688. InitModules();
  689. // Reserve the default module.
  690. ISR_RegisterModule(&gpDS->ghDefaultModule, "Default", "<ISRDBG><Default Module>");
  691. ISR_DbgStrStr(gpDS->ghDefaultModule, kISRDefault, "<ISRDBG><DllMain>", "Win32 x1.00");
  692. ISR_DbgStrStr(gpDS->ghDefaultModule, kISRDefault, "<ISRDBG><DllMain>", "Line 2 test");
  693. }
  694. break;
  695. }
  696. case DLL_THREAD_ATTACH:
  697. {
  698. break;
  699. }
  700. case DLL_THREAD_DETACH:
  701. {
  702. break;
  703. }
  704. case DLL_PROCESS_DETACH:
  705. {
  706. if (gSemaphore)
  707. {
  708. CloseHandle(gSemaphore);
  709. gSemaphore = 0;
  710. }
  711. // The DLL is detaching from a process due to
  712. // process termination or a call to FreeLibrary.
  713. FreeGlobalWin32Memory(gpDS,ghDS);
  714. FreeGlobalWin32Memory(gpModuleTable,ghModuleTable);
  715. FreeGlobalWin32Memory(gpDbgTable,ghDbgTable);
  716. FreeGlobalWin32Memory(gpzStrTab,ghzStrTab);
  717. break;
  718. }
  719. }
  720. return TRUE;
  721. }