1111 */
1212
1313#include " asan_report.hpp"
14- #include " asan_options.hpp"
15-
1614#include " asan_allocator.hpp"
1715#include " asan_interceptor.hpp"
1816#include " asan_libdevice.hpp"
17+ #include " asan_options.hpp"
18+ #include " asan_validator.hpp"
1919#include " ur_sanitizer_layer.hpp"
2020#include " ur_sanitizer_utils.hpp"
2121
2222namespace ur_sanitizer_layer {
2323
24+ namespace {
25+
26+ void PrintAllocateInfo (uptr Addr, const AllocInfo *AI) {
27+ getContext ()->logger .always (" {} is located inside of {} region [{}, {})" ,
28+ (void *)Addr, ToString (AI->Type ),
29+ (void *)AI->UserBegin , (void *)AI->UserEnd );
30+ getContext ()->logger .always (" allocated here:" );
31+ AI->AllocStack .print ();
32+ if (AI->IsReleased ) {
33+ getContext ()->logger .always (" freed here:" );
34+ AI->ReleaseStack .print ();
35+ }
36+ }
37+
38+ } // namespace
39+
2440void ReportBadFree (uptr Addr, const StackTrace &stack,
2541 const std::shared_ptr<AllocInfo> &AI) {
2642 getContext ()->logger .always (
@@ -34,11 +50,7 @@ void ReportBadFree(uptr Addr, const StackTrace &stack,
3450
3551 assert (AI && !AI->IsReleased && " Chunk must be not released" );
3652
37- getContext ()->logger .always (" {} is located inside of {} region [{}, {})" ,
38- (void *)Addr, ToString (AI->Type ),
39- (void *)AI->UserBegin , (void *)AI->UserEnd );
40- getContext ()->logger .always (" allocated here:" );
41- AI->AllocStack .print ();
53+ PrintAllocateInfo (Addr, AI.get ());
4254}
4355
4456void ReportBadContext (uptr Addr, const StackTrace &stack,
@@ -48,16 +60,7 @@ void ReportBadContext(uptr Addr, const StackTrace &stack,
4860 (void *)Addr);
4961 stack.print ();
5062
51- getContext ()->logger .always (" {} is located inside of {} region [{}, {})" ,
52- (void *)Addr, ToString (AI->Type ),
53- (void *)AI->UserBegin , (void *)AI->UserEnd );
54- getContext ()->logger .always (" allocated here:" );
55- AI->AllocStack .print ();
56-
57- if (AI->IsReleased ) {
58- getContext ()->logger .always (" freed here:" );
59- AI->ReleaseStack .print ();
60- }
63+ PrintAllocateInfo (Addr, AI.get ());
6164}
6265
6366void ReportDoubleFree (uptr Addr, const StackTrace &Stack,
@@ -139,16 +142,10 @@ void ReportUseAfterFree(const DeviceSanitizerReport &Report,
139142 " Failed to find which chunck {} is allocated" ,
140143 (void *)Report.Address );
141144 }
142- assert (AllocInfo->IsReleased );
145+ assert (AllocInfo->IsReleased &&
146+ " It must be released since it's use-after-free" );
143147
144- getContext ()->logger .always (
145- " {} is located inside of {} region [{}, {})" ,
146- (void *)Report.Address , ToString (AllocInfo->Type ),
147- (void *)AllocInfo->UserBegin , (void *)AllocInfo->UserEnd );
148- getContext ()->logger .always (" allocated here:" );
149- AllocInfo->AllocStack .print ();
150- getContext ()->logger .always (" released here:" );
151- AllocInfo->ReleaseStack .print ();
148+ PrintAllocateInfo (Report.Address , AllocInfo.get ());
152149 }
153150 } else {
154151 getContext ()->logger .always (
@@ -157,4 +154,47 @@ void ReportUseAfterFree(const DeviceSanitizerReport &Report,
157154 }
158155}
159156
157+ void ReportInvalidKernelArgument (ur_kernel_handle_t Kernel, uint32_t ArgIndex,
158+ uptr Addr, const ValidateUSMResult &VR,
159+ StackTrace Stack) {
160+ getContext ()->logger .always (" \n ====ERROR: DeviceSanitizer: "
161+ " invalid-argument on kernel <{}>" ,
162+ DemangleName (GetKernelName (Kernel)));
163+ Stack.print ();
164+ auto &AI = VR.AI ;
165+ switch (VR.Type ) {
166+ case ValidateUSMResult::MAYBE_HOST_POINTER:
167+ getContext ()->logger .always (" The {}th argument {} is not a USM pointer" ,
168+ ArgIndex + 1 , (void *)Addr);
169+ break ;
170+ case ValidateUSMResult::RELEASED_POINTER:
171+ getContext ()->logger .always (
172+ " The {}th argument {} is a released USM pointer" , ArgIndex,
173+ (void *)Addr);
174+ PrintAllocateInfo (Addr, AI.get ());
175+ break ;
176+ case ValidateUSMResult::BAD_CONTEXT:
177+ getContext ()->logger .always (
178+ " The {}th argument {} is allocated in other context" , ArgIndex,
179+ (void *)Addr);
180+ PrintAllocateInfo (Addr, AI.get ());
181+ break ;
182+ case ValidateUSMResult::BAD_DEVICE:
183+ getContext ()->logger .always (
184+ " The {}th argument {} is allocated in other device" , ArgIndex,
185+ (void *)Addr);
186+ PrintAllocateInfo (Addr, AI.get ());
187+ break ;
188+ case ValidateUSMResult::OUT_OF_BOUNDS:
189+ getContext ()->logger .always (
190+ " The {}th argument {} is located outside of its region [{}, {})" ,
191+ ArgIndex, (void *)Addr, (void *)AI->UserBegin , (void *)AI->UserEnd );
192+ getContext ()->logger .always (" allocated here:" );
193+ AI->AllocStack .print ();
194+ break ;
195+ default :
196+ break ;
197+ }
198+ }
199+
160200} // namespace ur_sanitizer_layer
0 commit comments