xref: /aosp_15_r20/external/gmmlib/Source/Common/AssertTracer/AssertTracer.h (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2017 Intel Corporation
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files(the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and / or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 ============================================================================*/
22 
23 /*
24 File Name:  AssertTracer.h
25 
26 Abstract:
27     These functions enables reporting asserts to system log in the debug
28     driver build.
29 
30 Notes:
31 
32 \*****************************************************************************/
33 #ifndef _ASSERT_TRACER_H_
34 #define _ASSERT_TRACER_H_
35 
36 #if defined( _WIN32 ) && (defined( _DEBUG ) || defined(_RELEASE_INTERNAL))
37 
38 #if !defined( __GMM_KMD__ ) && !defined( STATIC_DRIVER_MODEL ) && !defined( LHDM )
39 #include <windows.h>
40 // Windows.h defines MemoryFence as _mm_mfence, but this conflicts with llvm::sys::MemoryFence
41 #undef MemoryFence
42 #include <stdio.h>
43 #include <stdlib.h>
44 #endif
45 #undef REPORT_ASSERT_MSG
46 #define REPORT_ASSERT_MSG( expr, msg )                                            \
47     if ( !( expr ) )                                                              \
48     {                                                                             \
49         ReportAssert( #expr, __FILE__, __FUNCTION__, __LINE__, #msg );            \
50     }
51 #undef REPORT_ASSERT
52 #define REPORT_ASSERT( expr )                                                     \
53     if ( !( expr ) )                                                              \
54     {                                                                             \
55         ReportAssert( #expr, __FILE__, __FUNCTION__, __LINE__, "" );              \
56     }
57 
58 #undef REPORT_ASSERT_MSG_ETW
59 #define REPORT_ASSERT_MSG_ETW( compId, compMsk, expr, msg )                       \
60     if (!(expr))                                                                  \
61     {                                                                             \
62         ReportAssertETW( compId, compMsk, #expr, __FILE__, __FUNCTION__, __LINE__, #msg ); \
63     }
64 #undef REPORT_ASSERT_ETW
65 #define REPORT_ASSERT_ETW( compId, compMsk, expr )                                \
66     if (!(expr))                                                                  \
67     {                                                                             \
68         ReportAssertETW( compId, compMsk, #expr, __FILE__, __FUNCTION__, __LINE__, "" );  \
69     }
70 
71 #ifdef __cplusplus
72 extern "C"
73     {
74 #endif
75 void __stdcall ReportAssert( const char *expr,
76                    const char *file,
77                    const char *func,
78                    const unsigned long line,
79                    const char *msg );
80 
81 void __stdcall ReportAssertETW(const unsigned short compId,
82                     const unsigned long compMsk,
83                     const char *expr,
84                     const char *file,
85                     const char *func,
86                     const unsigned long line,
87                     const char *msg );
88 
89 
90 #ifdef __cplusplus
91     }
92 #endif
93 
94 #elif defined( __linux__ ) && defined( _RELEASE_INTERNAL ) && !defined( __ANDROID__ )
95 // do while() is missing ";" at the end and this is intentional
96 // As invoking assert looks like this: assert(expr); So semicolon will
97 // be stuck to do.. while() and that way sorting out possible
98 // problems when assert is used as block in one liner conditions
99 #define REPORT_ASSERT( expr )                                          \
100     do {                                                               \
101         if( !( expr ) )                                                \
102         {                                                              \
103             LogAssertion( __FUNCTION__, __FILE__, __LINE__, #expr );   \
104         }                                                              \
105     } while( 0 )
106 #define REPORT_ASSERT_MSG( expr, msg ) REPORT_ASSERT( expr )
107 #define REPORT_ASSERT_ETW( CompId, compMsk, expr)
108 void LogAssertion( const char *function_name, const char *file_name, unsigned int line_number, const char *expr );
109 #else
110 #define REPORT_ASSERT_MSG( expr, msg )
111 #define REPORT_ASSERT( expr )
112 #define REPORT_ASSERT_MSG_ETW( compMsk, expr, msg )
113 #define REPORT_ASSERT_ETW( CompId, compMsk, expr )
114 #endif // defined( _WIN32 ) && defined( _DEBUG )
115 #endif  //_ASSERT_TRACER_H_
116