1
0
mirror of https://github.com/golang/go synced 2024-10-05 20:31:20 -06:00
go/src/runtime/msan.go
Ian Lance Taylor 880a689124 runtime: don't call msanread when running on the system stack
The runtime is not instrumented, but the calls to msanread in the
runtime can sometimes refer to the system stack.  An example is the call
to copy in stkbucket in mprof.go.  Depending on what C code has done,
the system stack may appear uninitialized to msan.

Change-Id: Ic21705b9ac504ae5cf7601a59189302f072e7db1
Reviewed-on: https://go-review.googlesource.com/16660
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-11-11 06:04:04 +00:00

56 lines
1.4 KiB
Go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build msan
package runtime
import (
"unsafe"
)
// Public memory sanitizer API.
func MSanRead(addr unsafe.Pointer, len int) {
msanread(addr, uintptr(len))
}
func MSanWrite(addr unsafe.Pointer, len int) {
msanwrite(addr, uintptr(len))
}
// Private interface for the runtime.
const msanenabled = true
// If we are running on the system stack, the C program may have
// marked part of that stack as uninitialized. We don't instrument
// the runtime, but operations like a slice copy can call msanread
// anyhow for values on the stack. Just ignore msanread when running
// on the system stack. The other msan functions are fine.
func msanread(addr unsafe.Pointer, sz uintptr) {
g := getg()
if g == g.m.g0 || g == g.m.gsignal {
return
}
domsanread(addr, sz)
}
//go:noescape
func domsanread(addr unsafe.Pointer, sz uintptr)
//go:noescape
func msanwrite(addr unsafe.Pointer, sz uintptr)
//go:noescape
func msanmalloc(addr unsafe.Pointer, sz uintptr)
//go:noescape
func msanfree(addr unsafe.Pointer, sz uintptr)
// These are called from msan_amd64.s
//go:cgo_import_static __msan_read_go
//go:cgo_import_static __msan_write_go
//go:cgo_import_static __msan_malloc_go
//go:cgo_import_static __msan_free_go