Skip to content

Commit a333357

Browse files
authored
Merge pull request #2592 from AllanZyne/review/yang/fix_asan_free
[DeviceASAN] Fix throw "UR_RESULT_ERROR_INVALID_ARGUMENT" exception when catching free related error
2 parents 72ef2e5 + be22ba0 commit a333357

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

source/loader/layers/sanitizer/asan/asan_interceptor.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ ur_result_t AsanInterceptor::releaseMemory(ur_context_handle_t Context,
175175
if (!AllocInfoItOp) {
176176
// "Addr" might be a host pointer
177177
ReportBadFree(Addr, GetCurrentBacktrace(), nullptr);
178-
return UR_RESULT_ERROR_INVALID_ARGUMENT;
178+
if (getOptions().HaltOnError) {
179+
exitWithErrors();
180+
}
181+
return UR_RESULT_SUCCESS;
179182
}
180183

181184
auto AllocInfoIt = *AllocInfoItOp;
@@ -190,17 +193,26 @@ ur_result_t AsanInterceptor::releaseMemory(ur_context_handle_t Context,
190193
// "Addr" might be a host pointer
191194
ReportBadFree(Addr, GetCurrentBacktrace(), nullptr);
192195
}
193-
return UR_RESULT_ERROR_INVALID_ARGUMENT;
196+
if (getOptions().HaltOnError) {
197+
exitWithErrors();
198+
}
199+
return UR_RESULT_SUCCESS;
194200
}
195201

196202
if (Addr != AllocInfo->UserBegin) {
197203
ReportBadFree(Addr, GetCurrentBacktrace(), AllocInfo);
198-
return UR_RESULT_ERROR_INVALID_ARGUMENT;
204+
if (getOptions().HaltOnError) {
205+
exitWithErrors();
206+
}
207+
return UR_RESULT_SUCCESS;
199208
}
200209

201210
if (AllocInfo->IsReleased) {
202211
ReportDoubleFree(Addr, GetCurrentBacktrace(), AllocInfo);
203-
return UR_RESULT_ERROR_INVALID_ARGUMENT;
212+
if (getOptions().HaltOnError) {
213+
exitWithErrors();
214+
}
215+
return UR_RESULT_SUCCESS;
204216
}
205217

206218
AllocInfo->IsReleased = true;

source/loader/layers/sanitizer/asan/asan_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ AsanOptions::AsanOptions() {
9090
SetBoolOption("detect_privates", DetectPrivates);
9191
SetBoolOption("print_stats", PrintStats);
9292
SetBoolOption("detect_leaks", DetectLeaks);
93+
SetBoolOption("halt_on_error", HaltOnError);
9394

9495
auto KV = OptionsEnvMap->find("quarantine_size_mb");
9596
if (KV != OptionsEnvMap->end()) {

source/loader/layers/sanitizer/asan/asan_options.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct AsanOptions {
2828
bool PrintStats = false;
2929
bool DetectKernelArguments = true;
3030
bool DetectLeaks = true;
31+
bool HaltOnError = true;
3132

3233
explicit AsanOptions();
3334
};

0 commit comments

Comments
 (0)