1
0
mirror of https://github.com/golang/go synced 2024-11-17 05:24:53 -07:00

internal/msan: add new package

The internal/msan package contains helper functions for manually
instrumenting code for the memory sanitizer. It exports the private
msan routines in runtime unconditionally, making the functions a
no-op if the build flag "msan" is not present.

For #64611

Change-Id: If43f29e112ac79a47083c9dbdf2c61a0641e80b1
GitHub-Last-Rev: 0a644bd6f1
GitHub-Pull-Request: golang/go#64637
Reviewed-on: https://go-review.googlesource.com/c/go/+/548676
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Mauri de Souza Meneguzzo 2024-02-16 23:24:12 +00:00 committed by Cherry Mui
parent 4ce008d7d3
commit e1e466f80c
5 changed files with 71 additions and 0 deletions

View File

@ -75,6 +75,7 @@ var depsRules = `
< runtime < runtime
< sync/atomic < sync/atomic
< internal/race < internal/race
< internal/msan
< internal/asan < internal/asan
< sync < sync
< internal/bisect < internal/bisect

9
src/internal/msan/doc.go Normal file
View File

@ -0,0 +1,9 @@
// Copyright 2024 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.
// Package msan contains helper functions for manually instrumenting code
// for the memory sanitizer.
// This package exports the private msan routines in runtime unconditionally
// but without the "msan" build tag they are no-ops.
package msan

28
src/internal/msan/msan.go Normal file
View File

@ -0,0 +1,28 @@
// Copyright 2024 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.
//go:build msan
package msan
import (
"unsafe"
)
const Enabled = true
//go:linkname Read runtime.msanread
func Read(addr unsafe.Pointer, sz uintptr)
//go:linkname Write runtime.msanwrite
func Write(addr unsafe.Pointer, sz uintptr)
//go:linkname Malloc runtime.msanmalloc
func Malloc(addr unsafe.Pointer, sz uintptr)
//go:linkname Free runtime.msanfree
func Free(addr unsafe.Pointer, sz uintptr)
//go:linkname Move runtime.msanmove
func Move(dst, src unsafe.Pointer, sz uintptr)

View File

@ -0,0 +1,28 @@
// Copyright 2024 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.
//go:build !msan
package msan
import (
"unsafe"
)
const Enabled = false
func Read(addr unsafe.Pointer, sz uintptr) {
}
func Write(addr unsafe.Pointer, sz uintptr) {
}
func Malloc(addr unsafe.Pointer, sz uintptr) {
}
func Free(addr unsafe.Pointer, sz uintptr) {
}
func Move(dst, src unsafe.Pointer, sz uintptr) {
}

View File

@ -29,6 +29,7 @@ const msanenabled = true
// anyhow for values on the stack. Just ignore msanread when running // anyhow for values on the stack. Just ignore msanread when running
// on the system stack. The other msan functions are fine. // on the system stack. The other msan functions are fine.
// //
//go:linkname msanread
//go:nosplit //go:nosplit
func msanread(addr unsafe.Pointer, sz uintptr) { func msanread(addr unsafe.Pointer, sz uintptr) {
gp := getg() gp := getg()
@ -41,15 +42,19 @@ func msanread(addr unsafe.Pointer, sz uintptr) {
//go:noescape //go:noescape
func domsanread(addr unsafe.Pointer, sz uintptr) func domsanread(addr unsafe.Pointer, sz uintptr)
//go:linkname msanwrite
//go:noescape //go:noescape
func msanwrite(addr unsafe.Pointer, sz uintptr) func msanwrite(addr unsafe.Pointer, sz uintptr)
//go:linkname msanmalloc
//go:noescape //go:noescape
func msanmalloc(addr unsafe.Pointer, sz uintptr) func msanmalloc(addr unsafe.Pointer, sz uintptr)
//go:linkname msanfree
//go:noescape //go:noescape
func msanfree(addr unsafe.Pointer, sz uintptr) func msanfree(addr unsafe.Pointer, sz uintptr)
//go:linkname msanmove
//go:noescape //go:noescape
func msanmove(dst, src unsafe.Pointer, sz uintptr) func msanmove(dst, src unsafe.Pointer, sz uintptr)