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  
    30  // asan{read,write} are nosplit because they may be called between
    31  // fork and exec, when the stack must not grow. See issue #50391.
    32  
    33  //go:linkname asanread
    34  //go:nosplit
    35  func asanread(addr unsafe.Pointer, sz uintptr) {
    36  	sp := sys.GetCallerSP()
    37  	pc := sys.GetCallerPC()
    38  	doasanread(addr, sz, sp, pc)
    39  }
    40  
    41  //go:linkname asanwrite
    42  //go:nosplit
    43  func asanwrite(addr unsafe.Pointer, sz uintptr) {
    44  	sp := sys.GetCallerSP()
    45  	pc := sys.GetCallerPC()
    46  	doasanwrite(addr, sz, sp, pc)
    47  }
    48  
    49  //go:noescape
    50  func doasanread(addr unsafe.Pointer, sz, sp, pc uintptr)
    51  
    52  //go:noescape
    53  func doasanwrite(addr unsafe.Pointer, sz, sp, pc uintptr)
    54  
    55  //go:noescape
    56  func asanunpoison(addr unsafe.Pointer, sz uintptr)
    57  
    58  //go:noescape
    59  func asanpoison(addr unsafe.Pointer, sz uintptr)
    60  
    61  //go:noescape
    62  func asanregisterglobals(addr unsafe.Pointer, n uintptr)
    63  
    64  // These are called from asan_GOARCH.s
    65  //
    66  //go:cgo_import_static __asan_read_go
    67  //go:cgo_import_static __asan_write_go
    68  //go:cgo_import_static __asan_unpoison_go
    69  //go:cgo_import_static __asan_poison_go
    70  //go:cgo_import_static __asan_register_globals_go
    71  

View as plain text