Source file src/runtime/asan.go

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build asan
     6  
     7  package runtime
     8  
     9  import (
    10  	"internal/runtime/sys"
    11  	"unsafe"
    12  )
    13  
    14  // Public address sanitizer API.
    15  func ASanRead(addr unsafe.Pointer, len int) {
    16  	sp := sys.GetCallerSP()
    17  	pc := sys.GetCallerPC()
    18  	doasanread(addr, uintptr(len), sp, pc)
    19  }
    20  
    21  func ASanWrite(addr unsafe.Pointer, len int) {
    22  	sp := sys.GetCallerSP()
    23  	pc := sys.GetCallerPC()
    24  	doasanwrite(addr, uintptr(len), sp, pc)
    25  }
    26  
    27  // Private interface for the runtime.
    28  const asanenabled = true
    29  const asanenabledBit = 1
    30  
    31  // asan{read,write} are nosplit because they may be called between
    32  // fork and exec, when the stack must not grow. See issue #50391.
    33  
    34  //go:linkname asanread
    35  //go:nosplit
    36  func asanread(addr unsafe.Pointer, sz uintptr) {
    37  	sp := sys.GetCallerSP()
    38  	pc := sys.GetCallerPC()
    39  	doasanread(addr, sz, sp, pc)
    40  }
    41  
    42  //go:linkname asanwrite
    43  //go:nosplit
    44  func asanwrite(addr unsafe.Pointer, sz uintptr) {
    45  	sp := sys.GetCallerSP()
    46  	pc := sys.GetCallerPC()
    47  	doasanwrite(addr, sz, sp, pc)
    48  }
    49  
    50  //go:noescape
    51  func doasanread(addr unsafe.Pointer, sz, sp, pc uintptr)
    52  
    53  //go:noescape
    54  func doasanwrite(addr unsafe.Pointer, sz, sp, pc uintptr)
    55  
    56  //go:noescape
    57  func asanunpoison(addr unsafe.Pointer, sz uintptr)
    58  
    59  //go:noescape
    60  func asanpoison(addr unsafe.Pointer, sz uintptr)
    61  
    62  //go:noescape
    63  func asanregisterglobals(addr unsafe.Pointer, n uintptr)
    64  
    65  //go:noescape
    66  func lsanregisterrootregion(addr unsafe.Pointer, n uintptr)
    67  
    68  //go:noescape
    69  func lsanunregisterrootregion(addr unsafe.Pointer, n uintptr)
    70  
    71  func lsandoleakcheck()
    72  
    73  // These are called from asan_GOARCH.s
    74  //
    75  //go:cgo_import_static __asan_read_go
    76  //go:cgo_import_static __asan_write_go
    77  //go:cgo_import_static __asan_unpoison_go
    78  //go:cgo_import_static __asan_poison_go
    79  //go:cgo_import_static __asan_register_globals_go
    80  //go:cgo_import_static __lsan_register_root_region_go
    81  //go:cgo_import_static __lsan_unregister_root_region_go
    82  //go:cgo_import_static __lsan_do_leak_check_go
    83  

View as plain text