Skip to content

[DeviceASAN] Fix throw "UR_RESULT_ERROR_INVALID_ARGUMENT" exception when catching free related error #2592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions source/loader/layers/sanitizer/asan/asan_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ ur_result_t AsanInterceptor::releaseMemory(ur_context_handle_t Context,
if (!AllocInfoItOp) {
// "Addr" might be a host pointer
ReportBadFree(Addr, GetCurrentBacktrace(), nullptr);
return UR_RESULT_ERROR_INVALID_ARGUMENT;
if (getOptions().HaltOnError) {
exitWithErrors();
}
return UR_RESULT_SUCCESS;
}

auto AllocInfoIt = *AllocInfoItOp;
Expand All @@ -186,17 +189,26 @@ ur_result_t AsanInterceptor::releaseMemory(ur_context_handle_t Context,
// "Addr" might be a host pointer
ReportBadFree(Addr, GetCurrentBacktrace(), nullptr);
}
return UR_RESULT_ERROR_INVALID_ARGUMENT;
if (getOptions().HaltOnError) {
exitWithErrors();
}
return UR_RESULT_SUCCESS;
}

if (Addr != AllocInfo->UserBegin) {
ReportBadFree(Addr, GetCurrentBacktrace(), AllocInfo);
return UR_RESULT_ERROR_INVALID_ARGUMENT;
if (getOptions().HaltOnError) {
exitWithErrors();
}
return UR_RESULT_SUCCESS;
}

if (AllocInfo->IsReleased) {
ReportDoubleFree(Addr, GetCurrentBacktrace(), AllocInfo);
return UR_RESULT_ERROR_INVALID_ARGUMENT;
if (getOptions().HaltOnError) {
exitWithErrors();
}
return UR_RESULT_SUCCESS;
}

AllocInfo->IsReleased = true;
Expand Down
1 change: 1 addition & 0 deletions source/loader/layers/sanitizer/asan/asan_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ AsanOptions::AsanOptions() {
SetBoolOption("detect_privates", DetectPrivates);
SetBoolOption("print_stats", PrintStats);
SetBoolOption("detect_leaks", DetectLeaks);
SetBoolOption("halt_on_error", HaltOnError);

auto KV = OptionsEnvMap->find("quarantine_size_mb");
if (KV != OptionsEnvMap->end()) {
Expand Down
1 change: 1 addition & 0 deletions source/loader/layers/sanitizer/asan/asan_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct AsanOptions {
bool PrintStats = false;
bool DetectKernelArguments = true;
bool DetectLeaks = true;
bool HaltOnError = true;

explicit AsanOptions();
};
Expand Down
Loading