Skip to content

Commit 003d4da

Browse files
authored
Merge pull request #1402 from AllanZyne/user-after-free
[DeviceSanitizer] Checking "sycl::free" related errors
2 parents e38e79e + 7a5c1ad commit 003d4da

20 files changed

+1641
-796
lines changed

source/loader/CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,31 @@ if(UR_ENABLE_SANITIZER)
106106
target_sources(ur_loader
107107
PRIVATE
108108
${CMAKE_CURRENT_SOURCE_DIR}/../ur/ur.cpp
109+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_allocator.cpp
110+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_allocator.hpp
109111
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_interceptor.cpp
110112
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_interceptor.hpp
113+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_libdevice.hpp
114+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_quarantine.cpp
115+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_quarantine.hpp
116+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_report.cpp
117+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_report.hpp
118+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_shadow_setup.cpp
119+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_shadow_setup.hpp
111120
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/common.hpp
112-
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/device_sanitizer_report.hpp
121+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/stacktrace.cpp
122+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/stacktrace.hpp
123+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanddi.cpp
113124
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_layer.cpp
114125
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_layer.hpp
115-
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanddi.cpp
126+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_utils.cpp
127+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_utils.hpp
116128
)
117129

118130
target_sources(ur_loader
119131
PRIVATE
120-
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/linux/san_utils.cpp
132+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/linux/backtrace.cpp
133+
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/linux/sanitizer_utils.cpp
121134
)
122135

123136
target_include_directories(ur_loader PRIVATE
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
*
3+
* Copyright (C) 2024 Intel Corporation
4+
*
5+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
6+
* See LICENSE.TXT
7+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
*
9+
* @file asan_allocator.cpp
10+
*
11+
*/
12+
13+
#include "asan_allocator.hpp"
14+
#include "ur_sanitizer_layer.hpp"
15+
16+
namespace ur_sanitizer_layer {
17+
18+
void AllocInfo::print() {
19+
context.logger.info(
20+
"AllocInfo(Alloc=[{}-{}), User=[{}-{}), AllocSize={}, Type={})",
21+
(void *)AllocBegin, (void *)(AllocBegin + AllocSize), (void *)UserBegin,
22+
(void *)(UserEnd), AllocSize, ToString(Type));
23+
}
24+
25+
} // namespace ur_sanitizer_layer
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
*
3+
* Copyright (C) 2024 Intel Corporation
4+
*
5+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
6+
* See LICENSE.TXT
7+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
*
9+
* @file asan_allocator.hpp
10+
*
11+
*/
12+
13+
#pragma once
14+
15+
#include "common.hpp"
16+
#include "stacktrace.hpp"
17+
18+
#include <map>
19+
#include <memory>
20+
21+
namespace ur_sanitizer_layer {
22+
23+
enum class AllocType : uint32_t {
24+
UNKNOWN,
25+
DEVICE_USM,
26+
SHARED_USM,
27+
HOST_USM,
28+
MEM_BUFFER,
29+
DEVICE_GLOBAL
30+
};
31+
32+
struct AllocInfo {
33+
uptr AllocBegin = 0;
34+
uptr UserBegin = 0;
35+
uptr UserEnd = 0;
36+
size_t AllocSize = 0;
37+
38+
AllocType Type = AllocType::UNKNOWN;
39+
bool IsReleased = false;
40+
41+
ur_context_handle_t Context = nullptr;
42+
ur_device_handle_t Device = nullptr;
43+
44+
StackTrace AllocStack;
45+
StackTrace ReleaseStack;
46+
47+
void print();
48+
};
49+
50+
using AllocationMap = std::map<uptr, std::shared_ptr<AllocInfo>>;
51+
using AllocationIterator = AllocationMap::iterator;
52+
53+
inline const char *ToString(AllocType Type) {
54+
switch (Type) {
55+
case AllocType::DEVICE_USM:
56+
return "Device USM";
57+
case AllocType::HOST_USM:
58+
return "Host USM";
59+
case AllocType::SHARED_USM:
60+
return "Shared USM";
61+
case AllocType::MEM_BUFFER:
62+
return "Memory Buffer";
63+
case AllocType::DEVICE_GLOBAL:
64+
return "Device Global";
65+
default:
66+
return "Unknown Type";
67+
}
68+
}
69+
70+
} // namespace ur_sanitizer_layer

0 commit comments

Comments
 (0)