github.com/rakyll/go@v0.0.0-20170216000551-64c02460d703/src/runtime/msan.go (about)

     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  // +build msan
     6  
     7  package runtime
     8  
     9  import (
    10  	"unsafe"
    11  )
    12  
    13  // Public memory sanitizer API.
    14  
    15  func MSanRead(addr unsafe.Pointer, len int) {
    16  	msanread(addr, uintptr(len))
    17  }
    18  
    19  func MSanWrite(addr unsafe.Pointer, len int) {
    20  	msanwrite(addr, uintptr(len))
    21  }
    22  
    23  // Private interface for the runtime.
    24  const 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:nosplit
    33  func msanread(addr unsafe.Pointer, sz uintptr) {
    34  	g := getg()
    35  	if g == nil || g.m == nil || g == g.m.g0 || g == g.m.gsignal {
    36  		return
    37  	}
    38  	domsanread(addr, sz)
    39  }
    40  
    41  //go:noescape
    42  func domsanread(addr unsafe.Pointer, sz uintptr)
    43  
    44  //go:noescape
    45  func msanwrite(addr unsafe.Pointer, sz uintptr)
    46  
    47  //go:noescape
    48  func msanmalloc(addr unsafe.Pointer, sz uintptr)
    49  
    50  //go:noescape
    51  func msanfree(addr unsafe.Pointer, sz uintptr)
    52  
    53  // These are called from msan_amd64.s
    54  //go:cgo_import_static __msan_read_go
    55  //go:cgo_import_static __msan_write_go
    56  //go:cgo_import_static __msan_malloc_go
    57  //go:cgo_import_static __msan_free_go