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.

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