1- // ==--- sanitizer_utils .cpp - device sanitizer util inserted by compiler ---==//
1+ // ==--- asan_rtl .cpp - device address sanitizer runtime library --------- ---==//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
55// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66//
77// ===----------------------------------------------------------------------===//
88
9- #include " asan_libdevice.hpp"
9+ #include " include/asan_rtl.hpp"
10+ #include " asan/asan_libdevice.hpp"
1011#include " atomic.hpp"
1112#include " device.h"
1213#include " spirv_vars.h"
1314
14- #include " include/sanitizer_utils.hpp"
15-
16- using uptr = uintptr_t ;
17- using s8 = char ;
18- using u8 = unsigned char ;
19- using s16 = short ;
20- using u16 = unsigned short ;
21-
2215// Save the pointer to LaunchInfo
2316__SYCL_GLOBAL__ uptr *__SYCL_LOCAL__ __AsanLaunchInfo;
2417
@@ -375,7 +368,7 @@ bool MemIsZero(__SYCL_GLOBAL__ const char *beg, uptr size) {
375368static __SYCL_CONSTANT__ const char __mem_sanitizer_report[] =
376369 " [kernel] SanitizerReport (ErrorType=%d, IsRecover=%d)\n " ;
377370
378- void __asan_internal_report_save (DeviceSanitizerErrorType error_type) {
371+ void __asan_internal_report_save (ErrorType error_type) {
379372 const int Expected = ASAN_REPORT_NONE;
380373 int Desired = ASAN_REPORT_START;
381374
@@ -387,21 +380,21 @@ void __asan_internal_report_save(DeviceSanitizerErrorType error_type) {
387380 __spirv_BuiltInWorkgroupId.z ;
388381
389382 auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)
390- ->SanitizerReport [WG_LID % ASAN_MAX_NUM_REPORTS];
383+ ->Report [WG_LID % ASAN_MAX_NUM_REPORTS];
391384
392385 if (atomicCompareAndSet (
393386 &(((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)->ReportFlag ), 1 ,
394387 0 ) == 0 &&
395388 atomicCompareAndSet (&SanitizerReport.Flag , Desired, Expected) ==
396389 Expected) {
397- SanitizerReport.ErrorType = error_type;
390+ SanitizerReport.ErrorTy = error_type;
398391 SanitizerReport.IsRecover = false ;
399392
400393 // Show we've done copying
401394 atomicStore (&SanitizerReport.Flag , ASAN_REPORT_FINISH);
402395
403396 ASAN_DEBUG (__spirv_ocl_printf (__mem_sanitizer_report,
404- SanitizerReport.ErrorType ,
397+ SanitizerReport.ErrorTy ,
405398 SanitizerReport.IsRecover ));
406399 }
407400 __devicelib_exit ();
@@ -410,8 +403,7 @@ void __asan_internal_report_save(DeviceSanitizerErrorType error_type) {
410403void __asan_internal_report_save (
411404 uptr ptr, uint32_t as, const char __SYCL_CONSTANT__ *file, uint32_t line,
412405 const char __SYCL_CONSTANT__ *func, bool is_write, uint32_t access_size,
413- DeviceSanitizerMemoryType memory_type, DeviceSanitizerErrorType error_type,
414- bool is_recover = false ) {
406+ MemoryType memory_type, ErrorType error_type, bool is_recover = false ) {
415407
416408 const int Expected = ASAN_REPORT_NONE;
417409 int Desired = ASAN_REPORT_START;
@@ -424,7 +416,7 @@ void __asan_internal_report_save(
424416 __spirv_BuiltInWorkgroupId.z ;
425417
426418 auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)
427- ->SanitizerReport [WG_LID % ASAN_MAX_NUM_REPORTS];
419+ ->Report [WG_LID % ASAN_MAX_NUM_REPORTS];
428420
429421 if ((is_recover ||
430422 atomicCompareAndSet (
@@ -470,15 +462,15 @@ void __asan_internal_report_save(
470462 SanitizerReport.Address = ptr;
471463 SanitizerReport.IsWrite = is_write;
472464 SanitizerReport.AccessSize = access_size;
473- SanitizerReport.ErrorType = error_type;
474- SanitizerReport.MemoryType = memory_type;
465+ SanitizerReport.ErrorTy = error_type;
466+ SanitizerReport.MemoryTy = memory_type;
475467 SanitizerReport.IsRecover = is_recover;
476468
477469 // Show we've done copying
478470 atomicStore (&SanitizerReport.Flag , ASAN_REPORT_FINISH);
479471
480472 ASAN_DEBUG (__spirv_ocl_printf (__mem_sanitizer_report,
481- SanitizerReport.ErrorType ,
473+ SanitizerReport.ErrorTy ,
482474 SanitizerReport.IsRecover ));
483475 }
484476 __devicelib_exit ();
@@ -488,29 +480,29 @@ void __asan_internal_report_save(
488480// / ASAN Error Reporters
489481// /
490482
491- DeviceSanitizerMemoryType GetMemoryTypeByShadowValue (int shadow_value) {
483+ MemoryType GetMemoryTypeByShadowValue (int shadow_value) {
492484 switch (shadow_value) {
493485 case kUsmDeviceRedzoneMagic :
494486 case kUsmDeviceDeallocatedMagic :
495- return DeviceSanitizerMemoryType ::USM_DEVICE;
487+ return MemoryType ::USM_DEVICE;
496488 case kUsmHostRedzoneMagic :
497489 case kUsmHostDeallocatedMagic :
498- return DeviceSanitizerMemoryType ::USM_HOST;
490+ return MemoryType ::USM_HOST;
499491 case kUsmSharedRedzoneMagic :
500492 case kUsmSharedDeallocatedMagic :
501- return DeviceSanitizerMemoryType ::USM_SHARED;
493+ return MemoryType ::USM_SHARED;
502494 case kPrivateLeftRedzoneMagic :
503495 case kPrivateMidRedzoneMagic :
504496 case kPrivateRightRedzoneMagic :
505- return DeviceSanitizerMemoryType ::PRIVATE;
497+ return MemoryType ::PRIVATE;
506498 case kMemBufferRedzoneMagic :
507- return DeviceSanitizerMemoryType ::MEM_BUFFER;
499+ return MemoryType ::MEM_BUFFER;
508500 case kSharedLocalRedzoneMagic :
509- return DeviceSanitizerMemoryType ::LOCAL;
501+ return MemoryType ::LOCAL;
510502 case kDeviceGlobalRedzoneMagic :
511- return DeviceSanitizerMemoryType ::DEVICE_GLOBAL;
503+ return MemoryType ::DEVICE_GLOBAL;
512504 default :
513- return DeviceSanitizerMemoryType ::UNKNOWN;
505+ return MemoryType ::UNKNOWN;
514506 }
515507}
516508
@@ -528,9 +520,8 @@ void __asan_report_access_error(uptr addr, uint32_t as, size_t size,
528520 }
529521 // FIXME: check if shadow_address out-of-bound
530522
531- DeviceSanitizerMemoryType memory_type =
532- GetMemoryTypeByShadowValue (shadow_value);
533- DeviceSanitizerErrorType error_type;
523+ MemoryType memory_type = GetMemoryTypeByShadowValue (shadow_value);
524+ ErrorType error_type;
534525
535526 switch (shadow_value) {
536527 case kUsmDeviceRedzoneMagic :
@@ -542,18 +533,18 @@ void __asan_report_access_error(uptr addr, uint32_t as, size_t size,
542533 case kMemBufferRedzoneMagic :
543534 case kSharedLocalRedzoneMagic :
544535 case kDeviceGlobalRedzoneMagic :
545- error_type = DeviceSanitizerErrorType ::OUT_OF_BOUNDS;
536+ error_type = ErrorType ::OUT_OF_BOUNDS;
546537 break ;
547538 case kUsmDeviceDeallocatedMagic :
548539 case kUsmHostDeallocatedMagic :
549540 case kUsmSharedDeallocatedMagic :
550- error_type = DeviceSanitizerErrorType ::USE_AFTER_FREE;
541+ error_type = ErrorType ::USE_AFTER_FREE;
551542 break ;
552543 case kNullPointerRedzoneMagic :
553- error_type = DeviceSanitizerErrorType ::NULL_POINTER;
544+ error_type = ErrorType ::NULL_POINTER;
554545 break ;
555546 default :
556- error_type = DeviceSanitizerErrorType ::UNKNOWN;
547+ error_type = ErrorType ::UNKNOWN;
557548 }
558549
559550 __asan_internal_report_save (addr, as, file, line, func, is_write, size,
@@ -573,16 +564,15 @@ void __asan_report_misalign_error(uptr addr, uint32_t as, size_t size,
573564 }
574565 int shadow_value = *shadow;
575566
576- DeviceSanitizerErrorType error_type = DeviceSanitizerErrorType::MISALIGNED;
577- DeviceSanitizerMemoryType memory_type =
578- GetMemoryTypeByShadowValue (shadow_value);
567+ ErrorType error_type = ErrorType::MISALIGNED;
568+ MemoryType memory_type = GetMemoryTypeByShadowValue (shadow_value);
579569
580570 __asan_internal_report_save (addr, as, file, line, func, is_write, size,
581571 memory_type, error_type, is_recover);
582572}
583573
584574void __asan_report_unknown_device () {
585- __asan_internal_report_save (DeviceSanitizerErrorType ::UNKNOWN_DEVICE);
575+ __asan_internal_report_save (ErrorType ::UNKNOWN_DEVICE);
586576}
587577
588578// /
0 commit comments