github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/runtime/asan.go (about) 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:nosplit 33 func asanread(addr unsafe.Pointer, sz uintptr) { 34 sp := getcallersp() 35 pc := getcallerpc() 36 doasanread(addr, sz, sp, pc) 37 } 38 39 //go:nosplit 40 func asanwrite(addr unsafe.Pointer, sz uintptr) { 41 sp := getcallersp() 42 pc := getcallerpc() 43 doasanwrite(addr, sz, sp, pc) 44 } 45 46 //go:noescape 47 func doasanread(addr unsafe.Pointer, sz, sp, pc uintptr) 48 49 //go:noescape 50 func doasanwrite(addr unsafe.Pointer, sz, sp, pc uintptr) 51 52 //go:noescape 53 func asanunpoison(addr unsafe.Pointer, sz uintptr) 54 55 //go:noescape 56 func asanpoison(addr unsafe.Pointer, sz uintptr) 57 58 //go:noescape 59 func asanregisterglobals(addr unsafe.Pointer, n uintptr) 60 61 // These are called from asan_GOARCH.s 62 // 63 //go:cgo_import_static __asan_read_go 64 //go:cgo_import_static __asan_write_go 65 //go:cgo_import_static __asan_unpoison_go 66 //go:cgo_import_static __asan_poison_go 67 //go:cgo_import_static __asan_register_globals_go