Skip to content

Commit

Permalink
Support multiple error reports (#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZyne authored Jun 27, 2024
1 parent 45c3429 commit 764b75c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
27 changes: 17 additions & 10 deletions source/loader/layers/sanitizer/asan_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,23 @@ ur_result_t SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel,
auto Result = context.urDdiTable.Queue.pfnFinish(Queue);

if (Result == UR_RESULT_SUCCESS) {
const auto &AH = LaunchInfo.Data->SanitizerReport;
if (!AH.Flag) {
return UR_RESULT_SUCCESS;
}
if (AH.ErrorType == DeviceSanitizerErrorType::USE_AFTER_FREE) {
ReportUseAfterFree(AH, Kernel, GetContext(Queue));
} else if (AH.ErrorType == DeviceSanitizerErrorType::OUT_OF_BOUNDS) {
ReportOutOfBoundsError(AH, Kernel);
} else {
ReportGenericError(AH);
for (const auto &AH : LaunchInfo.Data->SanitizerReport) {
if (!AH.Flag) {
continue;
}
if (AH.ErrorType == DeviceSanitizerErrorType::USE_AFTER_FREE) {
ReportUseAfterFree(AH, Kernel, GetContext(Queue));
} else if (AH.ErrorType ==
DeviceSanitizerErrorType::OUT_OF_BOUNDS ||
AH.ErrorType == DeviceSanitizerErrorType::MISALIGNED ||
AH.ErrorType == DeviceSanitizerErrorType::NULL_POINTER) {
ReportOutOfBoundsError(AH, Kernel);
} else {
ReportGenericError(AH);
}
if (!AH.IsRecover) {
exit(1);
}
}
}

Expand Down
11 changes: 7 additions & 4 deletions source/loader/layers/sanitizer/asan_libdevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ struct LocalArgsInfo {
uint64_t SizeWithRedZone = 0;
};

constexpr std::size_t ASAN_MAX_NUM_REPORTS = 10;

struct LaunchInfo {
uintptr_t PrivateShadowOffset =
0; // don't move this field, we use it in AddressSanitizerPass
// Don't move this field, we use it in AddressSanitizerPass
uintptr_t PrivateShadowOffset = 0;

uintptr_t LocalShadowOffset = 0;
uintptr_t LocalShadowOffsetEnd = 0;
DeviceSanitizerReport SanitizerReport;

uint32_t NumLocalArgs = 0;
LocalArgsInfo *LocalArgs = nullptr; // ordered by ArgIndex
LocalArgsInfo *LocalArgs = nullptr; // Ordered by ArgIndex

DeviceSanitizerReport SanitizerReport[ASAN_MAX_NUM_REPORTS];
};

constexpr unsigned ASAN_SHADOW_SCALE = 4;
Expand Down
11 changes: 0 additions & 11 deletions source/loader/layers/sanitizer/asan_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void ReportBadFree(uptr Addr, const StackTrace &stack,
if (!AI) {
context.logger.always("{} may be allocated on Host Memory",
(void *)Addr);
exit(1);
}

assert(!AI->IsReleased && "Chunk must be not released");
Expand All @@ -40,8 +39,6 @@ void ReportBadFree(uptr Addr, const StackTrace &stack,
(void *)AI->UserBegin, (void *)AI->UserEnd);
context.logger.always("allocated here:");
AI->AllocStack.print();

exit(1);
}

void ReportBadContext(uptr Addr, const StackTrace &stack,
Expand All @@ -61,8 +58,6 @@ void ReportBadContext(uptr Addr, const StackTrace &stack,
context.logger.always("freed here:");
AI->ReleaseStack.print();
}

exit(1);
}

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

void ReportGenericError(const DeviceSanitizerReport &Report) {
context.logger.always("\n====ERROR: DeviceSanitizer: {}",
ToString(Report.ErrorType));
exit(1);
}

void ReportOutOfBoundsError(const DeviceSanitizerReport &Report,
Expand All @@ -107,8 +100,6 @@ void ReportOutOfBoundsError(const DeviceSanitizerReport &Report,
KernelName.c_str(), Report.LID0, Report.LID1, Report.LID2, Report.GID0,
Report.GID1, Report.GID2);
context.logger.always(" #0 {} {}:{}", Func, File, Report.Line);

exit(1);
}

void ReportUseAfterFree(const DeviceSanitizerReport &Report,
Expand Down Expand Up @@ -162,8 +153,6 @@ void ReportUseAfterFree(const DeviceSanitizerReport &Report,
"Please enable quarantine to get more information like memory "
"chunck's kind and where the chunck was allocated and released.");
}

exit(1);
}

} // namespace ur_sanitizer_layer

0 comments on commit 764b75c

Please sign in to comment.