Skip to content

Commit

Permalink
internal/asan: add new package
Browse files Browse the repository at this point in the history
The internal/asan package contains helper functions for manually
instrumenting code for the address sanitizer. It reexports the asan
routines in runtime uncoditionally, making the functions a no-op if the
build flag "asan" is disabled.

For [reserved]
  • Loading branch information
mauri870 committed Dec 10, 2023
1 parent 46ea4ab commit 7f7c9eb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/internal/asan/asan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2023 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 asan

package asan

import (
"runtime"
"unsafe"
)

const Enabled = true

func Read(addr unsafe.Pointer, len int) {
runtime.ASanRead(addr, len)
}

func Write(addr unsafe.Pointer, len int) {
runtime.ASanWrite(addr, len)
}
11 changes: 11 additions & 0 deletions src/internal/asan/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2023 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 asan contains helper functions for manually instrumenting code for the address sanitizer.
The runtime package intentionally exports these functions only in the asan build;
this package exports them unconditionally but without the "asan" build tag they are no-ops.
*/
package asan
19 changes: 19 additions & 0 deletions src/internal/asan/noasan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 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 !asan

package asan

import (
"unsafe"
)

const Enabled = false

func Read(addr unsafe.Pointer, len int) {
}

func Write(addr unsafe.Pointer, len int) {
}

0 comments on commit 7f7c9eb

Please sign in to comment.