Skip to content

Commit

Permalink
Merge pull request #1402 from AllanZyne/user-after-free
Browse files Browse the repository at this point in the history
[DeviceSanitizer] Checking "sycl::free" related errors
  • Loading branch information
aarongreig authored Apr 17, 2024
2 parents e38e79e + 7a5c1ad commit 003d4da
Show file tree
Hide file tree
Showing 20 changed files with 1,641 additions and 796 deletions.
19 changes: 16 additions & 3 deletions source/loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,31 @@ if(UR_ENABLE_SANITIZER)
target_sources(ur_loader
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../ur/ur.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_allocator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_allocator.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_interceptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_interceptor.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_libdevice.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_quarantine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_quarantine.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_report.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_report.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_shadow_setup.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/asan_shadow_setup.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/common.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/device_sanitizer_report.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/stacktrace.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/stacktrace.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanddi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_layer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_layer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanddi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/ur_sanitizer_utils.hpp
)

target_sources(ur_loader
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/linux/san_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/linux/backtrace.cpp
${CMAKE_CURRENT_SOURCE_DIR}/layers/sanitizer/linux/sanitizer_utils.cpp
)

target_include_directories(ur_loader PRIVATE
Expand Down
25 changes: 25 additions & 0 deletions source/loader/layers/sanitizer/asan_allocator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright (C) 2024 Intel Corporation
*
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
* See LICENSE.TXT
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
* @file asan_allocator.cpp
*
*/

#include "asan_allocator.hpp"
#include "ur_sanitizer_layer.hpp"

namespace ur_sanitizer_layer {

void AllocInfo::print() {
context.logger.info(
"AllocInfo(Alloc=[{}-{}), User=[{}-{}), AllocSize={}, Type={})",
(void *)AllocBegin, (void *)(AllocBegin + AllocSize), (void *)UserBegin,
(void *)(UserEnd), AllocSize, ToString(Type));
}

} // namespace ur_sanitizer_layer
70 changes: 70 additions & 0 deletions source/loader/layers/sanitizer/asan_allocator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
*
* Copyright (C) 2024 Intel Corporation
*
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
* See LICENSE.TXT
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
* @file asan_allocator.hpp
*
*/

#pragma once

#include "common.hpp"
#include "stacktrace.hpp"

#include <map>
#include <memory>

namespace ur_sanitizer_layer {

enum class AllocType : uint32_t {
UNKNOWN,
DEVICE_USM,
SHARED_USM,
HOST_USM,
MEM_BUFFER,
DEVICE_GLOBAL
};

struct AllocInfo {
uptr AllocBegin = 0;
uptr UserBegin = 0;
uptr UserEnd = 0;
size_t AllocSize = 0;

AllocType Type = AllocType::UNKNOWN;
bool IsReleased = false;

ur_context_handle_t Context = nullptr;
ur_device_handle_t Device = nullptr;

StackTrace AllocStack;
StackTrace ReleaseStack;

void print();
};

using AllocationMap = std::map<uptr, std::shared_ptr<AllocInfo>>;
using AllocationIterator = AllocationMap::iterator;

inline const char *ToString(AllocType Type) {
switch (Type) {
case AllocType::DEVICE_USM:
return "Device USM";
case AllocType::HOST_USM:
return "Host USM";
case AllocType::SHARED_USM:
return "Shared USM";
case AllocType::MEM_BUFFER:
return "Memory Buffer";
case AllocType::DEVICE_GLOBAL:
return "Device Global";
default:
return "Unknown Type";
}
}

} // namespace ur_sanitizer_layer
Loading

0 comments on commit 003d4da

Please sign in to comment.