Skip to content

Commit 764b75c

Browse files
authored
Support multiple error reports (#1677)
1 parent 45c3429 commit 764b75c

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

source/loader/layers/sanitizer/asan_interceptor.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,23 @@ ur_result_t SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel,
354354
auto Result = context.urDdiTable.Queue.pfnFinish(Queue);
355355

356356
if (Result == UR_RESULT_SUCCESS) {
357-
const auto &AH = LaunchInfo.Data->SanitizerReport;
358-
if (!AH.Flag) {
359-
return UR_RESULT_SUCCESS;
360-
}
361-
if (AH.ErrorType == DeviceSanitizerErrorType::USE_AFTER_FREE) {
362-
ReportUseAfterFree(AH, Kernel, GetContext(Queue));
363-
} else if (AH.ErrorType == DeviceSanitizerErrorType::OUT_OF_BOUNDS) {
364-
ReportOutOfBoundsError(AH, Kernel);
365-
} else {
366-
ReportGenericError(AH);
357+
for (const auto &AH : LaunchInfo.Data->SanitizerReport) {
358+
if (!AH.Flag) {
359+
continue;
360+
}
361+
if (AH.ErrorType == DeviceSanitizerErrorType::USE_AFTER_FREE) {
362+
ReportUseAfterFree(AH, Kernel, GetContext(Queue));
363+
} else if (AH.ErrorType ==
364+
DeviceSanitizerErrorType::OUT_OF_BOUNDS ||
365+
AH.ErrorType == DeviceSanitizerErrorType::MISALIGNED ||
366+
AH.ErrorType == DeviceSanitizerErrorType::NULL_POINTER) {
367+
ReportOutOfBoundsError(AH, Kernel);
368+
} else {
369+
ReportGenericError(AH);
370+
}
371+
if (!AH.IsRecover) {
372+
exit(1);
373+
}
367374
}
368375
}
369376

source/loader/layers/sanitizer/asan_libdevice.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,19 @@ struct LocalArgsInfo {
6767
uint64_t SizeWithRedZone = 0;
6868
};
6969

70+
constexpr std::size_t ASAN_MAX_NUM_REPORTS = 10;
71+
7072
struct LaunchInfo {
71-
uintptr_t PrivateShadowOffset =
72-
0; // don't move this field, we use it in AddressSanitizerPass
73+
// Don't move this field, we use it in AddressSanitizerPass
74+
uintptr_t PrivateShadowOffset = 0;
7375

7476
uintptr_t LocalShadowOffset = 0;
7577
uintptr_t LocalShadowOffsetEnd = 0;
76-
DeviceSanitizerReport SanitizerReport;
7778

7879
uint32_t NumLocalArgs = 0;
79-
LocalArgsInfo *LocalArgs = nullptr; // ordered by ArgIndex
80+
LocalArgsInfo *LocalArgs = nullptr; // Ordered by ArgIndex
81+
82+
DeviceSanitizerReport SanitizerReport[ASAN_MAX_NUM_REPORTS];
8083
};
8184

8285
constexpr unsigned ASAN_SHADOW_SCALE = 4;

source/loader/layers/sanitizer/asan_report.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ void ReportBadFree(uptr Addr, const StackTrace &stack,
3030
if (!AI) {
3131
context.logger.always("{} may be allocated on Host Memory",
3232
(void *)Addr);
33-
exit(1);
3433
}
3534

3635
assert(!AI->IsReleased && "Chunk must be not released");
@@ -40,8 +39,6 @@ void ReportBadFree(uptr Addr, const StackTrace &stack,
4039
(void *)AI->UserBegin, (void *)AI->UserEnd);
4140
context.logger.always("allocated here:");
4241
AI->AllocStack.print();
43-
44-
exit(1);
4542
}
4643

4744
void ReportBadContext(uptr Addr, const StackTrace &stack,
@@ -61,8 +58,6 @@ void ReportBadContext(uptr Addr, const StackTrace &stack,
6158
context.logger.always("freed here:");
6259
AI->ReleaseStack.print();
6360
}
64-
65-
exit(1);
6661
}
6762

6863
void ReportDoubleFree(uptr Addr, const StackTrace &Stack,
@@ -79,13 +74,11 @@ void ReportDoubleFree(uptr Addr, const StackTrace &Stack,
7974
AI->ReleaseStack.print();
8075
context.logger.always("previously allocated here:");
8176
AI->AllocStack.print();
82-
exit(1);
8377
}
8478

8579
void ReportGenericError(const DeviceSanitizerReport &Report) {
8680
context.logger.always("\n====ERROR: DeviceSanitizer: {}",
8781
ToString(Report.ErrorType));
88-
exit(1);
8982
}
9083

9184
void ReportOutOfBoundsError(const DeviceSanitizerReport &Report,
@@ -107,8 +100,6 @@ void ReportOutOfBoundsError(const DeviceSanitizerReport &Report,
107100
KernelName.c_str(), Report.LID0, Report.LID1, Report.LID2, Report.GID0,
108101
Report.GID1, Report.GID2);
109102
context.logger.always(" #0 {} {}:{}", Func, File, Report.Line);
110-
111-
exit(1);
112103
}
113104

114105
void ReportUseAfterFree(const DeviceSanitizerReport &Report,
@@ -162,8 +153,6 @@ void ReportUseAfterFree(const DeviceSanitizerReport &Report,
162153
"Please enable quarantine to get more information like memory "
163154
"chunck's kind and where the chunck was allocated and released.");
164155
}
165-
166-
exit(1);
167156
}
168157

169158
} // namespace ur_sanitizer_layer

0 commit comments

Comments
 (0)