Skip to content

Commit

Permalink
Merge pull request #2592 from AllanZyne/review/yang/fix_asan_free
Browse files Browse the repository at this point in the history
[DeviceASAN] Fix throw "UR_RESULT_ERROR_INVALID_ARGUMENT" exception when catching free related error
  • Loading branch information
kbenzie authored Feb 13, 2025
2 parents 4ed3ba4 + 08504e8 commit 7e38d0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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 @@ -175,7 +175,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 @@ -190,17 +193,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

0 comments on commit 7e38d0a

Please sign in to comment.