1// Copyright 2015 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 msan 6 7package runtime 8 9import ( 10 "unsafe" 11) 12 13// Public memory sanitizer API. 14 15func MSanRead(addr unsafe.Pointer, len int) { 16 msanread(addr, uintptr(len)) 17} 18 19func MSanWrite(addr unsafe.Pointer, len int) { 20 msanwrite(addr, uintptr(len)) 21} 22 23// Private interface for the runtime. 24const msanenabled = true 25 26// If we are running on the system stack, the C program may have 27// marked part of that stack as uninitialized. We don't instrument 28// the runtime, but operations like a slice copy can call msanread 29// anyhow for values on the stack. Just ignore msanread when running 30// on the system stack. The other msan functions are fine. 31// 32//go:linkname msanread 33//go:nosplit 34func msanread(addr unsafe.Pointer, sz uintptr) { 35 gp := getg() 36 if gp == nil || gp.m == nil || gp == gp.m.g0 || gp == gp.m.gsignal { 37 return 38 } 39 domsanread(addr, sz) 40} 41 42//go:noescape 43func domsanread(addr unsafe.Pointer, sz uintptr) 44 45//go:linkname msanwrite 46//go:noescape 47func msanwrite(addr unsafe.Pointer, sz uintptr) 48 49//go:linkname msanmalloc 50//go:noescape 51func msanmalloc(addr unsafe.Pointer, sz uintptr) 52 53//go:linkname msanfree 54//go:noescape 55func msanfree(addr unsafe.Pointer, sz uintptr) 56 57//go:linkname msanmove 58//go:noescape 59func msanmove(dst, src unsafe.Pointer, sz uintptr) 60 61// These are called from msan_GOARCH.s 62// 63//go:cgo_import_static __msan_read_go 64//go:cgo_import_static __msan_write_go 65//go:cgo_import_static __msan_malloc_go 66//go:cgo_import_static __msan_free_go 67//go:cgo_import_static __msan_memmove 68