...

Source file src/runtime/asan.go

Documentation: runtime

     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  	"unsafe"
    11  )
    12  
    13  // Public address sanitizer API.
    14  func ASanRead(addr unsafe.Pointer, len int) {
    15  	sp := getcallersp()
    16  	pc := getcallerpc()
    17  	doasanread(addr, uintptr(len), sp, pc)
    18  }
    19  
    20  func ASanWrite(addr unsafe.Pointer, len int) {
    21  	sp := getcallersp()
    22  	pc := getcallerpc()
    23  	doasanwrite(addr, uintptr(len), sp, pc)
    24  }
    25  
    26  // Private interface for the runtime.
    27  const asanenabled = true
    28  
    29  // asan{read,write} are nosplit because they may be called between
    30  // fork and exec, when the stack must not grow. See issue #50391.
    31  
    32  //go:linkname asanread
    33  //go:nosplit
    34  func asanread(addr unsafe.Pointer, sz uintptr) {
    35  	sp := getcallersp()
    36  	pc := getcallerpc()
    37  	doasanread(addr, sz, sp, pc)
    38  }
    39  
    40  //go:linkname asanwrite
    41  //go:nosplit
    42  func asanwrite(addr unsafe.Pointer, sz uintptr) {
    43  	sp := getcallersp()
    44  	pc := getcallerpc()
    45  	doasanwrite(addr, sz, sp, pc)
    46  }
    47  
    48  //go:noescape
    49  func doasanread(addr unsafe.Pointer, sz, sp, pc uintptr)
    50  
    51  //go:noescape
    52  func doasanwrite(addr unsafe.Pointer, sz, sp, pc uintptr)
    53  
    54  //go:noescape
    55  func asanunpoison(addr unsafe.Pointer, sz uintptr)
    56  
    57  //go:noescape
    58  func asanpoison(addr unsafe.Pointer, sz uintptr)
    59  
    60  //go:noescape
    61  func asanregisterglobals(addr unsafe.Pointer, n uintptr)
    62  
    63  // These are called from asan_GOARCH.s
    64  //
    65  //go:cgo_import_static __asan_read_go
    66  //go:cgo_import_static __asan_write_go
    67  //go:cgo_import_static __asan_unpoison_go
    68  //go:cgo_import_static __asan_poison_go
    69  //go:cgo_import_static __asan_register_globals_go
    70  

View as plain text