Skip to content

Commit 7f7c9eb

Browse files
committed
internal/asan: add new package
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]
1 parent 46ea4ab commit 7f7c9eb

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/internal/asan/asan.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2023 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+
//go:build asan
6+
7+
package asan
8+
9+
import (
10+
"runtime"
11+
"unsafe"
12+
)
13+
14+
const Enabled = true
15+
16+
func Read(addr unsafe.Pointer, len int) {
17+
runtime.ASanRead(addr, len)
18+
}
19+
20+
func Write(addr unsafe.Pointer, len int) {
21+
runtime.ASanWrite(addr, len)
22+
}

src/internal/asan/doc.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2023 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+
/*
6+
Package asan contains helper functions for manually instrumenting code for the address sanitizer.
7+
8+
The runtime package intentionally exports these functions only in the asan build;
9+
this package exports them unconditionally but without the "asan" build tag they are no-ops.
10+
*/
11+
package asan

src/internal/asan/noasan.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2023 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+
//go:build !asan
6+
7+
package asan
8+
9+
import (
10+
"unsafe"
11+
)
12+
13+
const Enabled = false
14+
15+
func Read(addr unsafe.Pointer, len int) {
16+
}
17+
18+
func Write(addr unsafe.Pointer, len int) {
19+
}

0 commit comments

Comments
 (0)