Skip to content

internal/msan: add new package #64637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/go/build/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var depsRules = `
< runtime
< sync/atomic
< internal/race
< internal/msan
< internal/asan
< sync
< internal/bisect
Expand Down
9 changes: 9 additions & 0 deletions src/internal/msan/doc.go
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions src/internal/msan/msan.go
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 28 additions & 0 deletions src/internal/msan/nomsan.go
Original file line number Diff line number Diff line change
@@ -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) {
}
5 changes: 5 additions & 0 deletions src/runtime/msan.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const msanenabled = true
// anyhow for values on the stack. Just ignore msanread when running
// on the system stack. The other msan functions are fine.
//
//go:linkname msanread
//go:nosplit
func msanread(addr unsafe.Pointer, sz uintptr) {
gp := getg()
Expand All @@ -41,15 +42,19 @@ func msanread(addr unsafe.Pointer, sz uintptr) {
//go:noescape
func domsanread(addr unsafe.Pointer, sz uintptr)

//go:linkname msanwrite
//go:noescape
func msanwrite(addr unsafe.Pointer, sz uintptr)

//go:linkname msanmalloc
//go:noescape
func msanmalloc(addr unsafe.Pointer, sz uintptr)

//go:linkname msanfree
//go:noescape
func msanfree(addr unsafe.Pointer, sz uintptr)

//go:linkname msanmove
//go:noescape
func msanmove(dst, src unsafe.Pointer, sz uintptr)

Expand Down