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.

1475 lines
35 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. //
  7. // module: DStsPage.cpp
  8. // author: DMihai
  9. // created: 11/1/00
  10. //
  11. // Description:
  12. //
  13. #include "stdafx.h"
  14. #include <Cderr.h>
  15. #include "verifier.h"
  16. #include "DStsPage.h"
  17. #include "VrfUtil.h"
  18. #include "VGlobal.h"
  19. #include "VBitsDlg.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. //
  26. // Timer ID
  27. //
  28. #define REFRESH_TIMER_ID 0x1234
  29. //
  30. // Help IDs
  31. //
  32. static DWORD MyHelpIds[] =
  33. {
  34. IDC_CRTSTAT_SETTBITS_LIST, IDH_DV_CurrentSettings,
  35. IDC_CRTSTAT_DRIVERS_LIST, IDH_DV_CurrentVerifiedDrivers,
  36. IDC_CRTSTAT_CHSETT_BUTTON, IDH_DV_Changebut,
  37. IDC_CRTSTAT_ADDDRV_BUTTON, IDH_DV_Addbut,
  38. IDC_CRTSTAT_REMDRVT_BUTTON, IDH_DV_Removebut,
  39. 0, 0
  40. };
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CDriverStatusPage property page
  43. IMPLEMENT_DYNCREATE(CDriverStatusPage, CVerifierPropertyPage)
  44. CDriverStatusPage::CDriverStatusPage() : CVerifierPropertyPage(CDriverStatusPage::IDD)
  45. {
  46. //{{AFX_DATA_INIT(CDriverStatusPage)
  47. //}}AFX_DATA_INIT
  48. m_uTimerHandler = 0;
  49. //
  50. // Driver list sort parameters
  51. //
  52. m_nSortColumnIndexDrv = 0;
  53. m_bAscendDrvNameSort = FALSE;
  54. m_bAscendDrvStatusSort = FALSE;
  55. //
  56. // Settings bits sort parameters
  57. //
  58. m_nSortColumnIndexSettbits = 1;
  59. m_bAscendSortEnabledBits = FALSE;
  60. m_bAscendSortNameBits = FALSE;
  61. m_pParentSheet = NULL;
  62. }
  63. CDriverStatusPage::~CDriverStatusPage()
  64. {
  65. }
  66. VOID CDriverStatusPage::DoDataExchange(CDataExchange* pDX)
  67. {
  68. if( ! pDX->m_bSaveAndValidate )
  69. {
  70. //
  71. // Query the kernel
  72. //
  73. if( TRUE != VrfGetRuntimeVerifierData( &m_RuntimeVerifierData ) ||
  74. m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetSize() == 0 )
  75. {
  76. //
  77. // Don't have any verified drivers currently
  78. //
  79. //
  80. // Clear all settings bits just in case the kernel
  81. // didn't return them to us all zero ;-)
  82. //
  83. m_RuntimeVerifierData.m_bSpecialPool = FALSE;
  84. m_RuntimeVerifierData.m_bPoolTracking = FALSE;
  85. m_RuntimeVerifierData.m_bForceIrql = FALSE;
  86. m_RuntimeVerifierData.m_bIo = FALSE;
  87. m_RuntimeVerifierData.m_bEnhIo = FALSE;
  88. m_RuntimeVerifierData.m_bDeadlockDetect = FALSE;
  89. m_RuntimeVerifierData.m_bDMAVerif = FALSE;
  90. m_RuntimeVerifierData.m_bLowRes = FALSE;
  91. }
  92. }
  93. CVerifierPropertyPage::DoDataExchange(pDX);
  94. //{{AFX_DATA_MAP(CDriverStatusPage)
  95. DDX_Control(pDX, IDC_CRTSTAT_SETTBITS_LIST, m_SettBitsList);
  96. DDX_Control(pDX, IDC_CRTSTAT_NEXT_DESCR_STATIC, m_NextDescription);
  97. DDX_Control(pDX, IDC_CRTSTAT_DRIVERS_LIST, m_DriversList);
  98. //}}AFX_DATA_MAP
  99. }
  100. BEGIN_MESSAGE_MAP(CDriverStatusPage, CVerifierPropertyPage)
  101. //{{AFX_MSG_MAP(CDriverStatusPage)
  102. ON_NOTIFY(LVN_COLUMNCLICK, IDC_CRTSTAT_DRIVERS_LIST, OnColumnclickCrtstatDriversList)
  103. ON_WM_TIMER()
  104. ON_BN_CLICKED(IDC_CRTSTAT_CHSETT_BUTTON, OnChsettButton)
  105. ON_BN_CLICKED(IDC_CRTSTAT_ADDDRV_BUTTON, OnAdddrvButton)
  106. ON_BN_CLICKED(IDC_CRTSTAT_REMDRVT_BUTTON, OnRemdrvtButton)
  107. ON_NOTIFY(LVN_COLUMNCLICK, IDC_CRTSTAT_SETTBITS_LIST, OnColumnclickCrtstatSettbitsList)
  108. ON_WM_CONTEXTMENU()
  109. ON_MESSAGE( WM_HELP, OnHelp )
  110. //}}AFX_MSG_MAP
  111. END_MESSAGE_MAP()
  112. /////////////////////////////////////////////////////////////
  113. VOID CDriverStatusPage::RefreshInfo()
  114. {
  115. if( UpdateData( FALSE ) )
  116. {
  117. //
  118. // Refresh the settings bits list
  119. //
  120. RefreshListSettBits();
  121. //SortTheListSettBits();
  122. //
  123. // Refresh the drivers list
  124. //
  125. FillTheListDrivers();
  126. SortTheListDrivers();
  127. }
  128. }
  129. /////////////////////////////////////////////////////////////
  130. //
  131. // Driver status list control methods
  132. //
  133. VOID CDriverStatusPage::SetupListHeaderDrivers()
  134. {
  135. LVCOLUMN lvColumn;
  136. CRect rectWnd;
  137. CString strDrivers, strStatus;
  138. VERIFY( strDrivers.LoadString( IDS_DRIVERS ) );
  139. VERIFY( strStatus.LoadString( IDS_STATUS ) );
  140. //
  141. // List's regtangle
  142. //
  143. m_DriversList.GetClientRect( &rectWnd );
  144. //
  145. // Column 0
  146. //
  147. ZeroMemory( &lvColumn, sizeof( lvColumn ) );
  148. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  149. lvColumn.fmt = LVCFMT_LEFT;
  150. lvColumn.iSubItem = 0;
  151. lvColumn.pszText = strDrivers.GetBuffer( strDrivers.GetLength() + 1 );
  152. lvColumn.cx = (int)( rectWnd.Width() * 0.50 );
  153. VERIFY( m_DriversList.InsertColumn( 0, &lvColumn ) != -1 );
  154. strDrivers.ReleaseBuffer();
  155. //
  156. // Column 1
  157. //
  158. lvColumn.iSubItem = 1;
  159. lvColumn.pszText = strStatus.GetBuffer( strStatus.GetLength() + 1 );
  160. lvColumn.cx = (int)( rectWnd.Width() * 0.44 );
  161. VERIFY( m_DriversList.InsertColumn( 1, &lvColumn ) != -1 );
  162. strStatus.ReleaseBuffer();
  163. }
  164. /////////////////////////////////////////////////////////////
  165. VOID CDriverStatusPage::FillTheListDrivers()
  166. {
  167. LVITEM lvItem;
  168. int nActualIndex;
  169. BOOL *pbAlreadyInList;
  170. int nItemCount;
  171. int nCrtListItem;
  172. INT_PTR nCrtVerifiedDriver;
  173. INT_PTR nDriversNo;
  174. TCHAR szDriverName[ _MAX_PATH ];
  175. BOOL bResult;
  176. CString strText;
  177. //
  178. // The number of drivers currently verified
  179. //
  180. nDriversNo = m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetSize();
  181. if( nDriversNo == 0 )
  182. {
  183. //
  184. // Clear the list
  185. //
  186. VERIFY( m_DriversList.DeleteAllItems() );
  187. }
  188. else
  189. {
  190. //
  191. // There are some drivers currently verified
  192. //
  193. pbAlreadyInList = new BOOL[ nDriversNo ];
  194. if( pbAlreadyInList == NULL )
  195. {
  196. return;
  197. }
  198. for( nCrtVerifiedDriver = 0; nCrtVerifiedDriver < nDriversNo; nCrtVerifiedDriver+= 1)
  199. {
  200. pbAlreadyInList[ nCrtVerifiedDriver ] = FALSE;
  201. }
  202. //
  203. // Parse all the current list items
  204. //
  205. nItemCount = m_DriversList.GetItemCount();
  206. for( nCrtListItem = 0; nCrtListItem < nItemCount; nCrtListItem+= 1 )
  207. {
  208. //
  209. // Get the current driver's name from the list
  210. //
  211. ZeroMemory( &lvItem, sizeof( lvItem ) );
  212. lvItem.mask = LVIF_TEXT;
  213. lvItem.iItem = nCrtListItem;
  214. lvItem.iSubItem = 0;
  215. lvItem.pszText = szDriverName;
  216. lvItem.cchTextMax = ARRAY_LENGTH( szDriverName );
  217. bResult = m_DriversList.GetItem( &lvItem );
  218. if( bResult == FALSE )
  219. {
  220. //
  221. // Could not get the current item's attributes?!?
  222. //
  223. ASSERT( FALSE );
  224. //
  225. // Remove this item from the list
  226. //
  227. VERIFY( m_DriversList.DeleteItem( nCrtListItem ) );
  228. nCrtListItem -= 1;
  229. nItemCount -= 1;
  230. }
  231. else
  232. {
  233. //
  234. // see is the current driver is still in m_RuntimeVerifierData
  235. //
  236. for( nCrtVerifiedDriver = 0; nCrtVerifiedDriver < nDriversNo; nCrtVerifiedDriver+= 1)
  237. {
  238. if( m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( nCrtVerifiedDriver )
  239. ->m_strName.CompareNoCase( szDriverName ) == 0 )
  240. {
  241. //
  242. // Update the item's data with the current index in the array
  243. //
  244. lvItem.mask = LVIF_PARAM;
  245. lvItem.lParam = nCrtVerifiedDriver;
  246. VERIFY( m_DriversList.SetItem( &lvItem ) != -1 );
  247. //
  248. // Update the second column
  249. //
  250. UpdateStatusColumnDrivers( nCrtListItem, nCrtVerifiedDriver );
  251. //
  252. // Mark the current driver as updated
  253. //
  254. pbAlreadyInList[ nCrtVerifiedDriver ] = TRUE;
  255. break;
  256. }
  257. }
  258. //
  259. // If the driver is no longer verified, remove it from the list
  260. //
  261. if( nCrtVerifiedDriver >= nDriversNo )
  262. {
  263. VERIFY( m_DriversList.DeleteItem( nCrtListItem ) );
  264. nCrtListItem -= 1;
  265. nItemCount -= 1;
  266. }
  267. }
  268. }
  269. //
  270. // Add the drivers that were not in the list before this update
  271. //
  272. for( nCrtVerifiedDriver = 0; nCrtVerifiedDriver < nDriversNo; nCrtVerifiedDriver += 1)
  273. {
  274. if( ! pbAlreadyInList[ nCrtVerifiedDriver ] )
  275. {
  276. //
  277. // Add a new item for this
  278. //
  279. ZeroMemory( &lvItem, sizeof( lvItem ) );
  280. //
  281. // sub-item 0
  282. //
  283. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  284. lvItem.lParam = nCrtVerifiedDriver;
  285. lvItem.iItem = m_DriversList.GetItemCount();
  286. lvItem.iSubItem = 0;
  287. strText = m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( nCrtVerifiedDriver )->m_strName;
  288. lvItem.pszText = strText.GetBuffer( strText.GetLength() + 1 );
  289. if( NULL != lvItem.pszText )
  290. {
  291. nActualIndex = m_DriversList.InsertItem( &lvItem );
  292. VERIFY( nActualIndex != -1 );
  293. strText.ReleaseBuffer();
  294. //
  295. // sub-item 1
  296. //
  297. UpdateStatusColumnDrivers( nActualIndex, nCrtVerifiedDriver );
  298. }
  299. }
  300. }
  301. delete pbAlreadyInList;
  302. }
  303. }
  304. /////////////////////////////////////////////////////////////
  305. VOID CDriverStatusPage::UpdateStatusColumnDrivers( INT_PTR nItemIndex, INT_PTR nCrtDriver )
  306. {
  307. CRuntimeDriverData *pCrtDriverData;
  308. LVITEM lvItem;
  309. CString strStatus;
  310. ASSERT( nItemIndex >= 0 &&
  311. nItemIndex < m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetSize() &&
  312. nItemIndex < m_DriversList.GetItemCount() &&
  313. nCrtDriver >= 0 &&
  314. nCrtDriver < m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetSize() &&
  315. nCrtDriver < m_DriversList.GetItemCount() );
  316. pCrtDriverData = m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( nCrtDriver );
  317. ASSERT_VALID( pCrtDriverData );
  318. //
  319. // Determine what's the appropriate value for the second column
  320. //
  321. if( ! pCrtDriverData->Loads )
  322. {
  323. VERIFY( strStatus.LoadString( IDS_NEVER_LOADED ) );
  324. }
  325. else
  326. {
  327. if( pCrtDriverData->Loads == pCrtDriverData->Unloads )
  328. {
  329. VERIFY( strStatus.LoadString( IDS_UNLOADED ) );
  330. }
  331. else
  332. {
  333. if( pCrtDriverData->Loads > pCrtDriverData->Unloads )
  334. {
  335. VERIFY( strStatus.LoadString( IDS_LOADED ) );
  336. }
  337. else
  338. {
  339. ASSERT( FALSE );
  340. VERIFY( strStatus.LoadString( IDS_UNKNOWN ) );
  341. }
  342. }
  343. }
  344. //
  345. // Update the list item
  346. //
  347. ZeroMemory( &lvItem, sizeof( lvItem ) );
  348. lvItem.mask = LVIF_TEXT;
  349. lvItem.iItem = (INT)nItemIndex;
  350. lvItem.iSubItem = 1;
  351. lvItem.pszText = strStatus.GetBuffer( strStatus.GetLength() + 1 );
  352. VERIFY( m_DriversList.SetItem( &lvItem ) );
  353. strStatus.ReleaseBuffer();
  354. }
  355. /////////////////////////////////////////////////////////////
  356. int CALLBACK CDriverStatusPage::DrvStatusCmpFunc(
  357. LPARAM lParam1,
  358. LPARAM lParam2,
  359. LPARAM lParamSort)
  360. {
  361. UINT uIndex1 = (UINT)lParam1;
  362. UINT uIndex2 = (UINT)lParam2;
  363. int nCmpRez = 0;
  364. CRuntimeDriverData *pDriverData1;
  365. CRuntimeDriverData *pDriverData2;
  366. CDriverStatusPage *pThis = (CDriverStatusPage *)lParamSort;
  367. ASSERT_VALID( pThis );
  368. //
  369. // Difference between loads and unloads #
  370. //
  371. pDriverData1 = pThis->m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( uIndex1 );
  372. ASSERT_VALID( pDriverData1 );
  373. pDriverData2 = pThis->m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( uIndex2 );
  374. ASSERT_VALID( pDriverData2 );
  375. LONG lLoadDiff1 = (LONG) pDriverData1->Loads - (LONG) pDriverData1->Unloads;
  376. LONG lLoadDiff2 = (LONG) pDriverData2->Loads - (LONG) pDriverData2->Unloads;
  377. if( lLoadDiff1 == lLoadDiff2 )
  378. {
  379. //
  380. // Both loaded or both not loaded
  381. //
  382. if( pDriverData1->Loads == pDriverData2->Loads )
  383. {
  384. //
  385. // Loaded same number of times
  386. //
  387. nCmpRez = 0;
  388. }
  389. else
  390. {
  391. if( pDriverData1->Loads > pDriverData2->Loads )
  392. {
  393. nCmpRez = 2;
  394. }
  395. else
  396. {
  397. nCmpRez = -2;
  398. }
  399. }
  400. }
  401. else
  402. {
  403. if( lLoadDiff1 > lLoadDiff2 )
  404. {
  405. nCmpRez = 1;
  406. }
  407. else
  408. {
  409. nCmpRez = -1;
  410. }
  411. }
  412. if( FALSE != pThis->m_bAscendDrvStatusSort )
  413. {
  414. nCmpRez *= -1;
  415. }
  416. return nCmpRez;
  417. }
  418. /////////////////////////////////////////////////////////////
  419. int CALLBACK CDriverStatusPage::DrvNameCmpFunc(
  420. LPARAM lParam1,
  421. LPARAM lParam2,
  422. LPARAM lParamSort)
  423. {
  424. int nCmpRez = 0;
  425. UINT uIndex1 = (UINT)lParam1;
  426. UINT uIndex2 = (UINT)lParam2;
  427. CRuntimeDriverData *pDriverData1;
  428. CRuntimeDriverData *pDriverData2;
  429. CDriverStatusPage *pThis = (CDriverStatusPage *)lParamSort;
  430. ASSERT_VALID( pThis );
  431. pDriverData1 = pThis->m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( uIndex1 );
  432. ASSERT_VALID( pDriverData1 );
  433. pDriverData2 = pThis->m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( uIndex2 );
  434. ASSERT_VALID( pDriverData2 );
  435. nCmpRez = pDriverData1->m_strName.CompareNoCase( pDriverData2->m_strName );
  436. if( FALSE != pThis->m_bAscendDrvNameSort )
  437. {
  438. nCmpRez *= -1;
  439. }
  440. return nCmpRez;
  441. }
  442. /////////////////////////////////////////////////////////////
  443. //
  444. // Settings bits list control methods
  445. //
  446. VOID CDriverStatusPage::SetupListHeaderSettBits()
  447. {
  448. CString strTitle;
  449. CRect rectWnd;
  450. LVCOLUMN lvColumn;
  451. //
  452. // The list's rectangle
  453. //
  454. m_SettBitsList.GetClientRect( &rectWnd );
  455. ZeroMemory( &lvColumn,
  456. sizeof( lvColumn ) );
  457. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  458. lvColumn.fmt = LVCFMT_LEFT;
  459. //
  460. // Column 0
  461. //
  462. VERIFY( strTitle.LoadString( IDS_ENABLED_QUESTION ) );
  463. lvColumn.iSubItem = 0;
  464. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  465. lvColumn.cx = (int)( rectWnd.Width() * 0.25 );
  466. VERIFY( m_SettBitsList.InsertColumn( 0, &lvColumn ) != -1 );
  467. strTitle.ReleaseBuffer();
  468. //
  469. // Column 1
  470. //
  471. VERIFY( strTitle.LoadString( IDS_SETTING ) );
  472. lvColumn.iSubItem = 1;
  473. lvColumn.pszText = strTitle.GetBuffer( strTitle.GetLength() + 1 );
  474. lvColumn.cx = (int)( rectWnd.Width() * 0.75 );
  475. VERIFY( m_SettBitsList.InsertColumn( 1, &lvColumn ) != -1 );
  476. strTitle.ReleaseBuffer();
  477. }
  478. /////////////////////////////////////////////////////////////
  479. VOID CDriverStatusPage::FillTheListSettBits()
  480. {
  481. //
  482. // N.B.
  483. //
  484. // If you change the first parameter (index - stored in the item's data)
  485. // you need to change the switch statement in IsSettBitEnabled as well
  486. //
  487. AddListItemSettBits( 0, m_RuntimeVerifierData.m_bSpecialPool, IDS_SPECIAL_POOL );
  488. AddListItemSettBits( 1, m_RuntimeVerifierData.m_bPoolTracking, IDS_POOL_TRACKING );
  489. AddListItemSettBits( 2, m_RuntimeVerifierData.m_bForceIrql, IDS_FORCE_IRQL_CHECKING );
  490. AddListItemSettBits( 3, m_RuntimeVerifierData.m_bIo, IDS_IO_VERIFICATION );
  491. AddListItemSettBits( 4, m_RuntimeVerifierData.m_bEnhIo, IDS_ENH_IO_VERIFICATION );
  492. AddListItemSettBits( 5, m_RuntimeVerifierData.m_bDeadlockDetect, IDS_DEADLOCK_DETECTION );
  493. AddListItemSettBits( 6, m_RuntimeVerifierData.m_bDMAVerif, IDS_DMA_CHECHKING );
  494. AddListItemSettBits( 7, m_RuntimeVerifierData.m_bLowRes, IDS_LOW_RESOURCE_SIMULATION );
  495. }
  496. /////////////////////////////////////////////////////////////
  497. VOID CDriverStatusPage::RefreshListSettBits()
  498. {
  499. INT nListItems;
  500. INT nCrtListItem;
  501. INT_PTR nCrtVerifierBit;
  502. BOOL bEnabled;
  503. nListItems = m_SettBitsList.GetItemCount();
  504. for( nCrtListItem = 0; nCrtListItem < nListItems; nCrtListItem += 1 )
  505. {
  506. nCrtVerifierBit = m_SettBitsList.GetItemData( nCrtListItem );
  507. bEnabled = IsSettBitEnabled( nCrtVerifierBit );
  508. UpdateStatusColumnSettBits( nCrtListItem, bEnabled );
  509. }
  510. }
  511. /////////////////////////////////////////////////////////////////////////////
  512. BOOL CDriverStatusPage::SettbitsGetBitName( LPARAM lItemData,
  513. TCHAR *szBitName,
  514. ULONG uBitNameBufferLen )
  515. {
  516. INT nItemIndex;
  517. BOOL bResult;
  518. LVFINDINFO FindInfo;
  519. LVITEM lvItem;
  520. bResult = FALSE;
  521. ZeroMemory( &FindInfo, sizeof( FindInfo ) );
  522. FindInfo.flags = LVFI_PARAM;
  523. FindInfo.lParam = lItemData;
  524. nItemIndex = m_SettBitsList.FindItem( &FindInfo );
  525. if( nItemIndex < 0 || nItemIndex > 7 )
  526. {
  527. ASSERT( FALSE );
  528. }
  529. else
  530. {
  531. //
  532. // Found our item - get the name
  533. //
  534. ZeroMemory( &lvItem, sizeof( lvItem ) );
  535. lvItem.mask = LVIF_TEXT;
  536. lvItem.iItem = nItemIndex;
  537. lvItem.iSubItem = 1;
  538. lvItem.pszText = szBitName;
  539. lvItem.cchTextMax = uBitNameBufferLen;
  540. bResult = m_SettBitsList.GetItem( &lvItem );
  541. if( FALSE == bResult )
  542. {
  543. //
  544. // Could not get the current item's attributes?!?
  545. //
  546. ASSERT( FALSE );
  547. }
  548. }
  549. return bResult;
  550. }
  551. /////////////////////////////////////////////////////////////////////////////
  552. BOOL CDriverStatusPage::IsSettBitEnabled( INT_PTR nBitIndex )
  553. {
  554. BOOL bEnabled;
  555. //
  556. // N.B.
  557. //
  558. // If you change this switch statement you need to change FillTheListSettBits as well
  559. //
  560. switch( nBitIndex )
  561. {
  562. case 0:
  563. bEnabled = m_RuntimeVerifierData.m_bSpecialPool;
  564. break;
  565. case 1:
  566. bEnabled = m_RuntimeVerifierData.m_bPoolTracking;
  567. break;
  568. case 2:
  569. bEnabled = m_RuntimeVerifierData.m_bForceIrql;
  570. break;
  571. case 3:
  572. bEnabled = m_RuntimeVerifierData.m_bIo;
  573. break;
  574. case 4:
  575. bEnabled = m_RuntimeVerifierData.m_bEnhIo;
  576. break;
  577. case 5:
  578. bEnabled = m_RuntimeVerifierData.m_bDeadlockDetect;
  579. break;
  580. case 6:
  581. bEnabled = m_RuntimeVerifierData.m_bDMAVerif;
  582. break;
  583. case 7:
  584. bEnabled = m_RuntimeVerifierData.m_bLowRes;
  585. break;
  586. default:
  587. //
  588. // Oops, how did we get here ?!?
  589. //
  590. ASSERT( FALSE );
  591. bEnabled = FALSE;
  592. break;
  593. }
  594. return bEnabled;
  595. }
  596. /////////////////////////////////////////////////////////////////////////////
  597. VOID CDriverStatusPage::AddListItemSettBits( INT nItemData, BOOL bEnabled, ULONG uIdResourceString )
  598. {
  599. INT nActualIndex;
  600. LVITEM lvItem;
  601. CString strText;
  602. ZeroMemory( &lvItem, sizeof( lvItem ) );
  603. //
  604. // LVITEM's member pszText is not a const pointer
  605. // so we need to GetBuffer here :-(
  606. //
  607. //
  608. // Sub-item 0 - enabled/diabled
  609. //
  610. if( FALSE == bEnabled )
  611. {
  612. VERIFY( strText.LoadString( IDS_NO ) );
  613. }
  614. else
  615. {
  616. VERIFY( strText.LoadString( IDS_YES ) );
  617. }
  618. lvItem.pszText = strText.GetBuffer( strText.GetLength() + 1 );
  619. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  620. lvItem.lParam = nItemData;
  621. lvItem.iItem = m_SettBitsList.GetItemCount();
  622. nActualIndex = m_SettBitsList.InsertItem( &lvItem );
  623. strText.ReleaseBuffer();
  624. if( nActualIndex < 0 )
  625. {
  626. //
  627. // Could not add an item in the list - give up
  628. //
  629. goto Done;
  630. }
  631. //
  632. // Sub-item 1 - feature name
  633. //
  634. VERIFY( strText.LoadString( uIdResourceString ) );
  635. lvItem.pszText = strText.GetBuffer( strText.GetLength() + 1 );
  636. if( NULL == lvItem.pszText )
  637. {
  638. goto Done;
  639. }
  640. lvItem.mask = LVIF_TEXT;
  641. lvItem.iItem = nActualIndex;
  642. lvItem.iSubItem = 1;
  643. VERIFY( m_SettBitsList.SetItem( &lvItem ) );
  644. strText.ReleaseBuffer();
  645. Done:
  646. //
  647. // All done
  648. //
  649. NOTHING;
  650. }
  651. /////////////////////////////////////////////////////////////
  652. VOID CDriverStatusPage::UpdateStatusColumnSettBits( INT nItemIndex, BOOL bEnabled )
  653. {
  654. LVITEM lvItem;
  655. CString strText;
  656. ASSERT( nItemIndex < m_SettBitsList.GetItemCount() );
  657. if( FALSE == bEnabled )
  658. {
  659. VERIFY( strText.LoadString( IDS_NO ) );
  660. }
  661. else
  662. {
  663. VERIFY( strText.LoadString( IDS_YES ) );
  664. }
  665. ZeroMemory( &lvItem, sizeof( lvItem ) );
  666. lvItem.mask = LVIF_TEXT;
  667. lvItem.iItem = nItemIndex;
  668. lvItem.iSubItem = 0;
  669. lvItem.pszText = strText.GetBuffer( strText.GetLength() + 1 );
  670. VERIFY( m_SettBitsList.SetItem( &lvItem ) );
  671. strText.ReleaseBuffer();
  672. }
  673. /////////////////////////////////////////////////////////////
  674. int CALLBACK CDriverStatusPage::SettbitsNameCmpFunc(
  675. LPARAM lParam1,
  676. LPARAM lParam2,
  677. LPARAM lParamSort)
  678. {
  679. int nCmpRez = 0;
  680. BOOL bSuccess;
  681. TCHAR szBitName1[ _MAX_PATH ];
  682. TCHAR szBitName2[ _MAX_PATH ];
  683. CDriverStatusPage *pThis = (CDriverStatusPage *)lParamSort;
  684. ASSERT_VALID( pThis );
  685. //
  686. // Get the first bit name
  687. //
  688. bSuccess = pThis->SettbitsGetBitName( lParam1,
  689. szBitName1,
  690. ARRAY_LENGTH( szBitName1 ) );
  691. if( FALSE == bSuccess )
  692. {
  693. goto Done;
  694. }
  695. //
  696. // Get the second bit name
  697. //
  698. bSuccess = pThis->SettbitsGetBitName( lParam2,
  699. szBitName2,
  700. ARRAY_LENGTH( szBitName2 ) );
  701. if( FALSE == bSuccess )
  702. {
  703. goto Done;
  704. }
  705. //
  706. // Compare the names
  707. //
  708. nCmpRez = _tcsicmp( szBitName1, szBitName2 );
  709. if( FALSE != pThis->m_bAscendSortNameBits )
  710. {
  711. nCmpRez *= -1;
  712. }
  713. Done:
  714. return nCmpRez;
  715. }
  716. /////////////////////////////////////////////////////////////
  717. int CALLBACK CDriverStatusPage::SettbitsEnabledCmpFunc(
  718. LPARAM lParam1,
  719. LPARAM lParam2,
  720. LPARAM lParamSort)
  721. {
  722. int nCmpRez = 0;
  723. BOOL bEnabled1;
  724. BOOL bEnabled2;
  725. CDriverStatusPage *pThis = (CDriverStatusPage *)lParamSort;
  726. ASSERT_VALID( pThis );
  727. bEnabled1 = pThis->IsSettBitEnabled( (INT) lParam1 );
  728. bEnabled2 = pThis->IsSettBitEnabled( (INT) lParam2 );
  729. if( bEnabled1 == bEnabled2 )
  730. {
  731. nCmpRez = 0;
  732. }
  733. else
  734. {
  735. if( FALSE == bEnabled1 )
  736. {
  737. nCmpRez = -1;
  738. }
  739. else
  740. {
  741. nCmpRez = 1;
  742. }
  743. }
  744. if( FALSE != pThis->m_bAscendSortEnabledBits )
  745. {
  746. nCmpRez *= -1;
  747. }
  748. return nCmpRez;
  749. }
  750. /////////////////////////////////////////////////////////////
  751. //
  752. // Other methods
  753. //
  754. /////////////////////////////////////////////////////////////
  755. VOID CDriverStatusPage::SortTheListDrivers()
  756. {
  757. if( 0 != m_nSortColumnIndexDrv )
  758. {
  759. //
  760. // Sort by status
  761. //
  762. m_DriversList.SortItems( DrvStatusCmpFunc, (LPARAM)this );
  763. }
  764. else
  765. {
  766. //
  767. // Sort by driver name
  768. //
  769. m_DriversList.SortItems( DrvNameCmpFunc, (LPARAM)this );
  770. }
  771. }
  772. /////////////////////////////////////////////////////////////
  773. VOID CDriverStatusPage::SortTheListSettBits()
  774. {
  775. if( 0 != m_nSortColumnIndexSettbits )
  776. {
  777. //
  778. // Sort by bit name
  779. //
  780. m_SettBitsList.SortItems( SettbitsNameCmpFunc, (LPARAM)this );
  781. }
  782. else
  783. {
  784. //
  785. // Sort by enabled/disabled
  786. //
  787. m_SettBitsList.SortItems( SettbitsEnabledCmpFunc, (LPARAM)this );
  788. }
  789. }
  790. /////////////////////////////////////////////////////////////
  791. // CDriverStatusPage message handlers
  792. BOOL CDriverStatusPage::OnInitDialog()
  793. {
  794. CPropertyPage::OnInitDialog();
  795. m_bTimerBlocked = FALSE;
  796. //
  797. // Setup the settings bits list
  798. //
  799. m_SettBitsList.SetExtendedStyle(
  800. LVS_EX_FULLROWSELECT | m_SettBitsList.GetExtendedStyle() );
  801. m_SettBitsList.SetBkColor( ::GetSysColor( COLOR_3DFACE ) );
  802. m_SettBitsList.SetTextBkColor( ::GetSysColor( COLOR_3DFACE ) );
  803. SetupListHeaderSettBits();
  804. FillTheListSettBits();
  805. //SortTheListSettBits();
  806. //
  807. // Setup the drivers list
  808. //
  809. m_DriversList.SetExtendedStyle(
  810. LVS_EX_FULLROWSELECT | m_DriversList.GetExtendedStyle() );
  811. m_DriversList.SetBkColor( ::GetSysColor( COLOR_3DFACE ) );
  812. m_DriversList.SetTextBkColor( ::GetSysColor( COLOR_3DFACE ) );
  813. SetupListHeaderDrivers();
  814. FillTheListDrivers();
  815. SortTheListDrivers();
  816. VrfSetWindowText( m_NextDescription, IDS_CRTSTAT_PAGE_NEXT_DESCR );
  817. VERIFY( m_uTimerHandler = SetTimer( REFRESH_TIMER_ID,
  818. 5000,
  819. NULL ) );
  820. return TRUE; // return TRUE unless you set the focus to a control
  821. // EXCEPTION: OCX Property Pages should return FALSE
  822. }
  823. /////////////////////////////////////////////////////////////
  824. VOID CDriverStatusPage::OnColumnclickCrtstatDriversList(NMHDR* pNMHDR,
  825. LRESULT* pResult)
  826. {
  827. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  828. if( 0 != pNMListView->iSubItem )
  829. {
  830. //
  831. // Clicked on the status column
  832. //
  833. if( m_nSortColumnIndexDrv == pNMListView->iSubItem )
  834. {
  835. //
  836. // Change the current ascend/descend order for this column
  837. //
  838. m_bAscendDrvStatusSort = !m_bAscendDrvStatusSort;
  839. }
  840. }
  841. else
  842. {
  843. //
  844. // Clicked on the driver name column
  845. //
  846. if( m_nSortColumnIndexDrv == pNMListView->iSubItem )
  847. {
  848. //
  849. // Change the current ascend/descend order for this column
  850. //
  851. m_bAscendDrvNameSort = !m_bAscendDrvNameSort;
  852. }
  853. }
  854. m_nSortColumnIndexDrv = pNMListView->iSubItem;
  855. SortTheListDrivers();
  856. *pResult = 0;
  857. }
  858. /////////////////////////////////////////////////////////////
  859. VOID CDriverStatusPage::OnTimer(UINT nIDEvent)
  860. {
  861. if( m_bTimerBlocked != TRUE && nIDEvent == REFRESH_TIMER_ID )
  862. {
  863. ASSERT_VALID( m_pParentSheet );
  864. if( m_pParentSheet->GetActivePage() == this )
  865. {
  866. //
  867. // Refresh the displayed data
  868. //
  869. RefreshInfo();
  870. }
  871. }
  872. CPropertyPage::OnTimer(nIDEvent);
  873. }
  874. /////////////////////////////////////////////////////////////////////////////
  875. BOOL CDriverStatusPage::OnSetActive()
  876. {
  877. ASSERT_VALID( m_pParentSheet );
  878. m_pParentSheet->SetWizardButtons( PSWIZB_BACK |
  879. PSWIZB_NEXT );
  880. return CVerifierPropertyPage::OnSetActive();
  881. }
  882. /////////////////////////////////////////////////////////////////////////////
  883. LRESULT CDriverStatusPage::OnWizardNext()
  884. {
  885. GoingToNextPageNotify( IDD_GLOBAL_COUNTERS_PAGE );
  886. return IDD_GLOBAL_COUNTERS_PAGE;
  887. }
  888. /////////////////////////////////////////////////////////////////////////////
  889. void CDriverStatusPage::OnChsettButton()
  890. {
  891. CVolatileBitsDlg dlg;
  892. if( IDOK == dlg.DoModal() )
  893. {
  894. RefreshInfo();
  895. }
  896. }
  897. /////////////////////////////////////////////////////////////////////////////
  898. #define VRF_MAX_CHARS_FOR_OPEN 4096
  899. void CDriverStatusPage::OnAdddrvButton()
  900. {
  901. POSITION pos;
  902. BOOL bEnabledSome = FALSE;
  903. DWORD dwRetValue;
  904. DWORD dwOldMaxFileName = 0;
  905. DWORD dwErrorCode;
  906. int nFileNameStartIndex;
  907. INT_PTR nResult;
  908. TCHAR szDriversDir[ _MAX_PATH ];
  909. TCHAR szAppTitle[ _MAX_PATH ];
  910. TCHAR *szFilesBuffer = NULL;
  911. TCHAR *szOldFilesBuffer = NULL;
  912. CString strPathName;
  913. CString strFileName;
  914. CFileDialog fileDlg(
  915. TRUE, // open file
  916. _T( "sys" ), // default extension
  917. NULL, // no initial file name
  918. OFN_ALLOWMULTISELECT | // multiple selection
  919. OFN_HIDEREADONLY | // hide the "open read-only" checkbox
  920. OFN_NONETWORKBUTTON | // no network button
  921. OFN_NOTESTFILECREATE | // don't test for write protection, a full disk, etc.
  922. OFN_SHAREAWARE, // don't check the existance of file with OpenFile
  923. _T( "Drivers (*.sys)|*.sys||" ) ); // only one filter
  924. //
  925. // check the max length for the returned string
  926. //
  927. if( fileDlg.m_ofn.nMaxFile < VRF_MAX_CHARS_FOR_OPEN )
  928. {
  929. //
  930. // allocate a new buffer for the file names
  931. //
  932. szFilesBuffer = new TCHAR[ VRF_MAX_CHARS_FOR_OPEN ];
  933. szFilesBuffer[ 0 ] = (TCHAR)0;
  934. if( szFilesBuffer != NULL )
  935. {
  936. //
  937. // Save the old buffer address and length
  938. //
  939. dwOldMaxFileName = fileDlg.m_ofn.nMaxFile;
  940. szOldFilesBuffer = fileDlg.m_ofn.lpstrFile;
  941. //
  942. // Set the new buffer address and length
  943. //
  944. fileDlg.m_ofn.lpstrFile = szFilesBuffer;
  945. fileDlg.m_ofn.nMaxFile = VRF_MAX_CHARS_FOR_OPEN;
  946. }
  947. }
  948. //
  949. // Dialog title
  950. //
  951. if( VrfLoadString(
  952. IDS_APPTITLE,
  953. szAppTitle,
  954. ARRAY_LENGTH( szAppTitle ) ) )
  955. {
  956. fileDlg.m_ofn.lpstrTitle = szAppTitle;
  957. }
  958. //
  959. // We change directory first time we try this to %windir%\system32\drivers
  960. //
  961. dwRetValue = ExpandEnvironmentStrings(
  962. _T( "%windir%\\system32\\drivers" ),
  963. szDriversDir,
  964. ARRAY_LENGTH( szDriversDir ) );
  965. if( dwRetValue > 0 && dwRetValue <= ARRAY_LENGTH( szDriversDir ) )
  966. {
  967. fileDlg.m_ofn.lpstrInitialDir = szDriversDir;
  968. }
  969. //
  970. // Show the file selection dialog
  971. //
  972. nResult = fileDlg.DoModal();
  973. switch( nResult )
  974. {
  975. case IDOK:
  976. break;
  977. case IDCANCEL:
  978. goto cleanup;
  979. default:
  980. dwErrorCode = CommDlgExtendedError();
  981. if( dwErrorCode == FNERR_BUFFERTOOSMALL )
  982. {
  983. VrfErrorResourceFormat(
  984. IDS_TOO_MANY_FILES_SELECTED );
  985. }
  986. else
  987. {
  988. VrfErrorResourceFormat(
  989. IDS_CANNOT_OPEN_FILES,
  990. dwErrorCode );
  991. }
  992. goto cleanup;
  993. }
  994. //
  995. // Block the timer
  996. //
  997. m_bTimerBlocked = TRUE;
  998. //
  999. // Parse all the selected files and try to enable them for verification
  1000. //
  1001. pos = fileDlg.GetStartPosition();
  1002. while( pos != NULL )
  1003. {
  1004. //
  1005. // Get the full path for the next file
  1006. //
  1007. strPathName = fileDlg.GetNextPathName( pos );
  1008. //
  1009. // Split only the file name, without the directory
  1010. //
  1011. nFileNameStartIndex = strPathName.ReverseFind( _T( '\\' ) );
  1012. if( nFileNameStartIndex < 0 )
  1013. {
  1014. //
  1015. // This shoudn't happen but you never know :-)
  1016. //
  1017. nFileNameStartIndex = 0;
  1018. }
  1019. else
  1020. {
  1021. //
  1022. // skip the backslash
  1023. //
  1024. nFileNameStartIndex += 1;
  1025. }
  1026. strFileName = strPathName.Right( strPathName.GetLength() - nFileNameStartIndex );
  1027. //
  1028. // Try to add this driver to the current verification list
  1029. //
  1030. if( VrfAddDriverVolatile( strFileName ) )
  1031. {
  1032. bEnabledSome = TRUE;
  1033. }
  1034. }
  1035. //
  1036. // Enable the timer
  1037. //
  1038. m_bTimerBlocked = FALSE;
  1039. //
  1040. // Refresh
  1041. //
  1042. if( bEnabledSome == TRUE )
  1043. {
  1044. RefreshInfo();
  1045. }
  1046. cleanup:
  1047. if( szFilesBuffer != NULL )
  1048. {
  1049. fileDlg.m_ofn.nMaxFile = dwOldMaxFileName;
  1050. fileDlg.m_ofn.lpstrFile = szOldFilesBuffer;
  1051. delete szFilesBuffer;
  1052. }
  1053. }
  1054. /////////////////////////////////////////////////////////////////////////////
  1055. void CDriverStatusPage::OnRemdrvtButton()
  1056. {
  1057. INT nItems;
  1058. INT nCrtItem;
  1059. INT_PTR nIndexInArray;
  1060. CRuntimeDriverData *pRuntimeDriverData;
  1061. BOOL bDisabledSome = FALSE;
  1062. //
  1063. // Block the timer
  1064. //
  1065. m_bTimerBlocked = TRUE;
  1066. //
  1067. // The number of items in the list
  1068. //
  1069. nItems = m_DriversList.GetItemCount();
  1070. //
  1071. // Parse all the items, looking for the selected ones.
  1072. //
  1073. for( nCrtItem = 0; nCrtItem < nItems; nCrtItem += 1 )
  1074. {
  1075. if( m_DriversList.GetItemState( nCrtItem, LVIS_SELECTED ) & LVIS_SELECTED )
  1076. {
  1077. //
  1078. // Get the index of the corresponding entry in the array
  1079. //
  1080. nIndexInArray = (UINT)m_DriversList.GetItemData( nCrtItem );
  1081. //
  1082. // sanity checks
  1083. //
  1084. if( nIndexInArray >= m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetSize() )
  1085. {
  1086. ASSERT( FALSE );
  1087. continue;
  1088. }
  1089. pRuntimeDriverData = m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( nIndexInArray );
  1090. ASSERT_VALID( pRuntimeDriverData );
  1091. if( VrfRemoveDriverVolatile( pRuntimeDriverData->m_strName ) )
  1092. {
  1093. bDisabledSome = TRUE;
  1094. }
  1095. }
  1096. }
  1097. //
  1098. // Enable the timer
  1099. //
  1100. m_bTimerBlocked = FALSE;
  1101. //
  1102. // If we disabled some drivers' verification we need to refresh the list
  1103. //
  1104. if( bDisabledSome )
  1105. {
  1106. RefreshInfo();
  1107. }
  1108. }
  1109. /////////////////////////////////////////////////////////////////////////////
  1110. void CDriverStatusPage::OnColumnclickCrtstatSettbitsList(NMHDR* pNMHDR, LRESULT* pResult)
  1111. {
  1112. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  1113. if( 0 != pNMListView->iSubItem )
  1114. {
  1115. //
  1116. // Clicked on the bit name column
  1117. //
  1118. if( m_nSortColumnIndexSettbits == pNMListView->iSubItem )
  1119. {
  1120. //
  1121. // Change the current ascend/descend order for this column
  1122. //
  1123. m_bAscendSortNameBits = !m_bAscendSortNameBits;
  1124. }
  1125. }
  1126. else
  1127. {
  1128. //
  1129. // Clicked on the enabled/disabled column
  1130. //
  1131. if( m_nSortColumnIndexSettbits == pNMListView->iSubItem )
  1132. {
  1133. //
  1134. // Change the current ascend/descend order for this column
  1135. //
  1136. m_bAscendSortEnabledBits = !m_bAscendSortEnabledBits;
  1137. }
  1138. }
  1139. m_nSortColumnIndexSettbits = pNMListView->iSubItem;
  1140. SortTheListSettBits();
  1141. *pResult = 0;
  1142. }
  1143. /////////////////////////////////////////////////////////////////////////////
  1144. LONG CDriverStatusPage::OnHelp( WPARAM wParam, LPARAM lParam )
  1145. {
  1146. LONG lResult = 0;
  1147. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  1148. ::WinHelp(
  1149. (HWND) lpHelpInfo->hItemHandle,
  1150. g_szVerifierHelpFile,
  1151. HELP_WM_HELP,
  1152. (DWORD_PTR) MyHelpIds );
  1153. return lResult;
  1154. }
  1155. /////////////////////////////////////////////////////////////////////////////
  1156. void CDriverStatusPage::OnContextMenu(CWnd* pWnd, CPoint point)
  1157. {
  1158. ::WinHelp(
  1159. pWnd->m_hWnd,
  1160. g_szVerifierHelpFile,
  1161. HELP_CONTEXTMENU,
  1162. (DWORD_PTR) MyHelpIds );
  1163. }