1 //
2 //    Copyright (C) Microsoft.  All rights reserved.
3 //
4 #ifndef __FXIFRKM_H__
5 #define __FXIFRKM_H__
6 
7 #define FX_IFR_MAX_BUFFER_SIZE      (0x10000)   // 64k
8 
9 #if (PAGE_SIZE > 0x1000)
10 #define FX_IFR_AVG_BUFFER_SIZE      (3 * PAGE_SIZE) // ia64
11 #else
12 #define FX_IFR_AVG_BUFFER_SIZE      (5 * PAGE_SIZE) // x86, amd64
13 #endif
14 
15 //
16 // Log Size should be in whole pages.
17 //
18 enum FxIFRValues {
19     FxIFRMinLogPages    = 1,
20     FxIFRMaxLogPages    = FX_IFR_MAX_BUFFER_SIZE/PAGE_SIZE,
21     FxIFRAvgLogPages    = FX_IFR_AVG_BUFFER_SIZE/PAGE_SIZE,
22 
23     FxIFRMinLogSize     = FxIFRMinLogPages * PAGE_SIZE,
24     FxIFRMaxLogSize     = FxIFRMaxLogPages * PAGE_SIZE,
25     FxIFRAvgLogSize     = FxIFRAvgLogPages * PAGE_SIZE,
26 
27     FxIFRMaxMessageSize = 256,
28 
29     FxIFRRecordSignature = WDF_IFR_RECORD_SIGNATURE,
30 };
31 
32 //
33 // Verify the following:
34 // - max_log_size must be <= 64k.
35 // - min_log_size must be >= page_size.
36 // - max_log_size  >= avg_log_size  >= min_log_size.
37 // - max_log_pages >= avg_log_pages >= min_log_pages.
38 //
39 C_ASSERT(FxIFRMaxLogSize <= 0x10000);
40 C_ASSERT(FxIFRMinLogSize >= PAGE_SIZE);
41 C_ASSERT(FxIFRMaxLogSize >= FxIFRAvgLogSize &&
42             FxIFRAvgLogSize >= FxIFRMinLogSize);
43 C_ASSERT(FxIFRMaxLogPages >= FxIFRAvgLogPages &&
44             FxIFRAvgLogPages >= FxIFRMinLogPages);
45 
46 
47 __inline
48 VOID
FxVerifyLogHeader(__in PFX_DRIVER_GLOBALS FxDriverGlobals,__in PWDF_IFR_HEADER Header)49 FxVerifyLogHeader(
50     __in PFX_DRIVER_GLOBALS FxDriverGlobals,
51     __in PWDF_IFR_HEADER Header
52     )
53 /*++
54 
55 Routine Description:
56     This routine is added to track the down IFR header corruption
57 
58 
59 
60 --*/
61 {
62     WDFCASSERT(WDF_IFR_HEADER_NAME_LEN == WDF_DRIVER_GLOBALS_NAME_LEN);
63 
64     if (FxDriverGlobals->FxVerifierOn
65         &&
66         (strncmp(Header->DriverName, FxDriverGlobals->Public.DriverName,
67                  WDF_IFR_HEADER_NAME_LEN) != 0
68          ||
69          FxIsEqualGuid((LPGUID)&(Header->Guid), (LPGUID)&WdfTraceGuid) == FALSE
70          ||
71          Header->Base != (PUCHAR) &Header[1]
72          ||
73          Header->Offset.u.s.Current > Header->Size
74          ||
75          Header->Offset.u.s.Previous > Header->Size
76          ||
77          Header->Size >= FxIFRMaxLogSize)) // size doesn't include header.
78     {
79         FxVerifierDbgBreakPoint(FxDriverGlobals);
80     }
81 }
82 
83 #endif // __FXIFRKM_H__
84