Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZyne committed Dec 12, 2023
1 parent e9a2093 commit a1c4ddc
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions source/loader/layers/sanitizer/asan_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ ur_program_handle_t getProgram(ur_kernel_handle_t Kernel) {

} // namespace

/// The memory chunk allocated from the underlying allocator looks like this:
/// L L L L L L U U U U U U R R
/// L -- left redzone words (0 or more bytes)
/// U -- user memory.
/// R -- right redzone (0 or more bytes)
///
/// ref: "compiler-rt/lib/asan/asan_allocator.cpp" Allocator::Allocate
ur_result_t SanitizerInterceptor::allocateMemory(
ur_context_handle_t Context, ur_device_handle_t Device,
const ur_usm_desc_t *Properties, ur_usm_pool_handle_t Pool, size_t Size,
Expand Down Expand Up @@ -232,12 +239,11 @@ void SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel,
DeviceSanitizerFormat(AH->ErrorType),
DeviceSanitizerFormat(AH->MemoryType));
context.logger.always(
stderr,
"%s of size %u at kernel <%s> LID(%lu, %lu, %lu) GID(%lu, "
"%lu, %lu)\n",
AH->IsWrite ? "WRITE" : "READ", AH->AccessSize, Func, AH->LID0,
AH->LID1, AH->LID2, AH->GID0, AH->GID1, AH->GID2);
context.logger.always(stderr, " #0 %s %s:%d\n", Func, File, AH->Line);
context.logger.always(" #0 %s %s:%d\n", Func, File, AH->Line);
if (!AH->IsRecover) {
abort();
}
Expand Down Expand Up @@ -377,6 +383,13 @@ ur_result_t SanitizerInterceptor::enqueueMemSetShadow(
return UR_RESULT_SUCCESS;
}

/// Each 8 bytes of application memory are mapped into one byte of shadow memory
/// The meaning of that byte:
/// - Negative: All bytes are not accessible (poisoned)
/// - 0: All bytes are accessible
/// - 1 <= k <= 7: Only the first k bytes is accessible
///
/// ref: https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm#mapping
ur_result_t SanitizerInterceptor::enqueueAllocInfo(
ur_context_handle_t Context, ur_device_handle_t Device,
ur_queue_handle_t Queue, std::shared_ptr<USMAllocInfo> &AllocInfo,
Expand Down

0 comments on commit a1c4ddc

Please sign in to comment.