1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | // |
5 | |
6 | // |
7 | //***************************************************************************** |
8 | // EventReporter.h: |
9 | // A utility to log an entry in event log. |
10 | //***************************************************************************** |
11 | |
12 | |
13 | #ifndef _eventreporter_h_ |
14 | #define _eventreporter_h_ |
15 | |
16 | #include "contract.h" |
17 | #include "sstring.h" |
18 | |
19 | // Maximum size for a string in event log entry |
20 | #define MAX_SIZE_EVENTLOG_ENTRY_STRING 0x8000 // decimal 32768 |
21 | |
22 | // The (approx.) maximum size that Vista appears to allow. Post discussion with the OS event log team, |
23 | // it has been identified that Vista has taken a breaking change in ReportEventW API implementation |
24 | // without getting it publicly documented. |
25 | // |
26 | // An event entry comprises of string to be written and event header information. Prior to Vista, |
27 | // 32K length strings were allowed and event header size was over it. Vista onwards, the total |
28 | // permissible length of the string and event header became 32K, resulting in strings becoming |
29 | // shorter in length. Hence, the change in size. |
30 | #define MAX_SIZE_EVENTLOG_ENTRY_STRING_WINVISTA 0x7C62 // decimal 31842 |
31 | |
32 | class EventReporter |
33 | { |
34 | public: |
35 | enum EventReporterType |
36 | { |
37 | ERT_UnhandledException, |
38 | ERT_ManagedFailFast, |
39 | ERT_UnmanagedFailFast, |
40 | ERT_StackOverflow, |
41 | ERT_CodeContractFailed, |
42 | }; |
43 | private: |
44 | EventReporterType m_eventType; |
45 | // We use 2048 which is large enough for most task. This allows us to avoid |
46 | // unnecessary memory allocation. |
47 | InlineSString<2048> m_Description; |
48 | |
49 | // Flag to indicate if the buffer is full |
50 | BOOL fBufferFull; |
51 | |
52 | static void GetCoreCLRInstanceProductVersion(DWORD * pdwMajor, DWORD * pdwMinor, DWORD * pdwBuild, DWORD * pdwRevision); |
53 | |
54 | public: |
55 | // Construct |
56 | EventReporter(EventReporterType type); |
57 | // Add extra info into description part of the log |
58 | void AddDescription(__in WCHAR *pString); |
59 | void AddDescription(SString& s); |
60 | // Start callstack record |
61 | void BeginStackTrace(); |
62 | // Add one frame to the callstack part |
63 | void AddStackTrace(SString& s); |
64 | // Add failfast stack trace |
65 | void AddFailFastStackTrace(SString& s); |
66 | // Report to the EventLog |
67 | void Report(); |
68 | }; |
69 | |
70 | // return TRUE if we need to log in EventLog. |
71 | BOOL ShouldLogInEventLog(); |
72 | // Record managed callstack in EventReporter. |
73 | void LogCallstackForEventReporter(EventReporter& reporter); |
74 | // Record unhandled native exceptions. |
75 | void DoReportForUnhandledNativeException(PEXCEPTION_POINTERS pExceptionInfo); |
76 | // Helper method for logging stack trace in EventReporter |
77 | void ReportExceptionStackHelper(OBJECTREF exObj, EventReporter& reporter, SmallStackSString& wordAt, int recursionLimit); |
78 | #endif // _eventreporter_h_ |
79 | |