1
- // ==--- sanitizer_utils .cpp - device sanitizer util inserted by compiler ---==//
1
+ // ==--- asan_rtl .cpp - device address sanitizer runtime library --------- ---==//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
- #include " asan_libdevice.hpp"
9
+ #include " include/asan_rtl.hpp"
10
+ #include " asan/asan_libdevice.hpp"
10
11
#include " atomic.hpp"
11
12
#include " device.h"
12
13
#include " spirv_vars.h"
13
14
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
-
22
15
// Save the pointer to LaunchInfo
23
16
__SYCL_GLOBAL__ uptr *__SYCL_LOCAL__ __AsanLaunchInfo;
24
17
@@ -375,7 +368,7 @@ bool MemIsZero(__SYCL_GLOBAL__ const char *beg, uptr size) {
375
368
static __SYCL_CONSTANT__ const char __mem_sanitizer_report[] =
376
369
" [kernel] SanitizerReport (ErrorType=%d, IsRecover=%d)\n " ;
377
370
378
- void __asan_internal_report_save (DeviceSanitizerErrorType error_type) {
371
+ void __asan_internal_report_save (ErrorType error_type) {
379
372
const int Expected = ASAN_REPORT_NONE;
380
373
int Desired = ASAN_REPORT_START;
381
374
@@ -387,21 +380,21 @@ void __asan_internal_report_save(DeviceSanitizerErrorType error_type) {
387
380
__spirv_BuiltInWorkgroupId.z ;
388
381
389
382
auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)
390
- ->SanitizerReport [WG_LID % ASAN_MAX_NUM_REPORTS];
383
+ ->Report [WG_LID % ASAN_MAX_NUM_REPORTS];
391
384
392
385
if (atomicCompareAndSet (
393
386
&(((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)->ReportFlag ), 1 ,
394
387
0 ) == 0 &&
395
388
atomicCompareAndSet (&SanitizerReport.Flag , Desired, Expected) ==
396
389
Expected) {
397
- SanitizerReport.ErrorType = error_type;
390
+ SanitizerReport.ErrorTy = error_type;
398
391
SanitizerReport.IsRecover = false ;
399
392
400
393
// Show we've done copying
401
394
atomicStore (&SanitizerReport.Flag , ASAN_REPORT_FINISH);
402
395
403
396
ASAN_DEBUG (__spirv_ocl_printf (__mem_sanitizer_report,
404
- SanitizerReport.ErrorType ,
397
+ SanitizerReport.ErrorTy ,
405
398
SanitizerReport.IsRecover ));
406
399
}
407
400
__devicelib_exit ();
@@ -410,8 +403,7 @@ void __asan_internal_report_save(DeviceSanitizerErrorType error_type) {
410
403
void __asan_internal_report_save (
411
404
uptr ptr, uint32_t as, const char __SYCL_CONSTANT__ *file, uint32_t line,
412
405
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 ) {
415
407
416
408
const int Expected = ASAN_REPORT_NONE;
417
409
int Desired = ASAN_REPORT_START;
@@ -424,7 +416,7 @@ void __asan_internal_report_save(
424
416
__spirv_BuiltInWorkgroupId.z ;
425
417
426
418
auto &SanitizerReport = ((__SYCL_GLOBAL__ LaunchInfo *)__AsanLaunchInfo)
427
- ->SanitizerReport [WG_LID % ASAN_MAX_NUM_REPORTS];
419
+ ->Report [WG_LID % ASAN_MAX_NUM_REPORTS];
428
420
429
421
if ((is_recover ||
430
422
atomicCompareAndSet (
@@ -470,15 +462,15 @@ void __asan_internal_report_save(
470
462
SanitizerReport.Address = ptr;
471
463
SanitizerReport.IsWrite = is_write;
472
464
SanitizerReport.AccessSize = access_size;
473
- SanitizerReport.ErrorType = error_type;
474
- SanitizerReport.MemoryType = memory_type;
465
+ SanitizerReport.ErrorTy = error_type;
466
+ SanitizerReport.MemoryTy = memory_type;
475
467
SanitizerReport.IsRecover = is_recover;
476
468
477
469
// Show we've done copying
478
470
atomicStore (&SanitizerReport.Flag , ASAN_REPORT_FINISH);
479
471
480
472
ASAN_DEBUG (__spirv_ocl_printf (__mem_sanitizer_report,
481
- SanitizerReport.ErrorType ,
473
+ SanitizerReport.ErrorTy ,
482
474
SanitizerReport.IsRecover ));
483
475
}
484
476
__devicelib_exit ();
@@ -488,29 +480,29 @@ void __asan_internal_report_save(
488
480
// / ASAN Error Reporters
489
481
// /
490
482
491
- DeviceSanitizerMemoryType GetMemoryTypeByShadowValue (int shadow_value) {
483
+ MemoryType GetMemoryTypeByShadowValue (int shadow_value) {
492
484
switch (shadow_value) {
493
485
case kUsmDeviceRedzoneMagic :
494
486
case kUsmDeviceDeallocatedMagic :
495
- return DeviceSanitizerMemoryType ::USM_DEVICE;
487
+ return MemoryType ::USM_DEVICE;
496
488
case kUsmHostRedzoneMagic :
497
489
case kUsmHostDeallocatedMagic :
498
- return DeviceSanitizerMemoryType ::USM_HOST;
490
+ return MemoryType ::USM_HOST;
499
491
case kUsmSharedRedzoneMagic :
500
492
case kUsmSharedDeallocatedMagic :
501
- return DeviceSanitizerMemoryType ::USM_SHARED;
493
+ return MemoryType ::USM_SHARED;
502
494
case kPrivateLeftRedzoneMagic :
503
495
case kPrivateMidRedzoneMagic :
504
496
case kPrivateRightRedzoneMagic :
505
- return DeviceSanitizerMemoryType ::PRIVATE;
497
+ return MemoryType ::PRIVATE;
506
498
case kMemBufferRedzoneMagic :
507
- return DeviceSanitizerMemoryType ::MEM_BUFFER;
499
+ return MemoryType ::MEM_BUFFER;
508
500
case kSharedLocalRedzoneMagic :
509
- return DeviceSanitizerMemoryType ::LOCAL;
501
+ return MemoryType ::LOCAL;
510
502
case kDeviceGlobalRedzoneMagic :
511
- return DeviceSanitizerMemoryType ::DEVICE_GLOBAL;
503
+ return MemoryType ::DEVICE_GLOBAL;
512
504
default :
513
- return DeviceSanitizerMemoryType ::UNKNOWN;
505
+ return MemoryType ::UNKNOWN;
514
506
}
515
507
}
516
508
@@ -528,9 +520,8 @@ void __asan_report_access_error(uptr addr, uint32_t as, size_t size,
528
520
}
529
521
// FIXME: check if shadow_address out-of-bound
530
522
531
- DeviceSanitizerMemoryType memory_type =
532
- GetMemoryTypeByShadowValue (shadow_value);
533
- DeviceSanitizerErrorType error_type;
523
+ MemoryType memory_type = GetMemoryTypeByShadowValue (shadow_value);
524
+ ErrorType error_type;
534
525
535
526
switch (shadow_value) {
536
527
case kUsmDeviceRedzoneMagic :
@@ -542,18 +533,18 @@ void __asan_report_access_error(uptr addr, uint32_t as, size_t size,
542
533
case kMemBufferRedzoneMagic :
543
534
case kSharedLocalRedzoneMagic :
544
535
case kDeviceGlobalRedzoneMagic :
545
- error_type = DeviceSanitizerErrorType ::OUT_OF_BOUNDS;
536
+ error_type = ErrorType ::OUT_OF_BOUNDS;
546
537
break ;
547
538
case kUsmDeviceDeallocatedMagic :
548
539
case kUsmHostDeallocatedMagic :
549
540
case kUsmSharedDeallocatedMagic :
550
- error_type = DeviceSanitizerErrorType ::USE_AFTER_FREE;
541
+ error_type = ErrorType ::USE_AFTER_FREE;
551
542
break ;
552
543
case kNullPointerRedzoneMagic :
553
- error_type = DeviceSanitizerErrorType ::NULL_POINTER;
544
+ error_type = ErrorType ::NULL_POINTER;
554
545
break ;
555
546
default :
556
- error_type = DeviceSanitizerErrorType ::UNKNOWN;
547
+ error_type = ErrorType ::UNKNOWN;
557
548
}
558
549
559
550
__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,
573
564
}
574
565
int shadow_value = *shadow;
575
566
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);
579
569
580
570
__asan_internal_report_save (addr, as, file, line, func, is_write, size,
581
571
memory_type, error_type, is_recover);
582
572
}
583
573
584
574
void __asan_report_unknown_device () {
585
- __asan_internal_report_save (DeviceSanitizerErrorType ::UNKNOWN_DEVICE);
575
+ __asan_internal_report_save (ErrorType ::UNKNOWN_DEVICE);
586
576
}
587
577
588
578
// /
0 commit comments