]> Cypherpunks repositories - gostls13.git/commitdiff
internal/asan: add new package
authorMauri de Souza Meneguzzo <mauri870@gmail.com>
Wed, 7 Feb 2024 22:51:00 +0000 (22:51 +0000)
committerCherry Mui <cherryyz@google.com>
Tue, 13 Feb 2024 20:39:58 +0000 (20:39 +0000)
The internal/asan package contains helper functions for manually
instrumenting code for the address sanitizer. It reexports the asan
routines in runtime unconditionally, making the functions a no-op if the
build flag "asan" is not present.

For #64611

Change-Id: Ie79e698aea7a6d969afd2a5f008c084c9545b1a5
GitHub-Last-Rev: e658670c146adb5a5496afe4a2425dd5291fd7ac
GitHub-Pull-Request: golang/go#64635
Reviewed-on: https://go-review.googlesource.com/c/go/+/548695
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>

src/go/build/deps_test.go
src/internal/asan/asan.go [new file with mode: 0644]
src/internal/asan/doc.go [new file with mode: 0644]
src/internal/asan/noasan.go [new file with mode: 0644]
src/runtime/asan.go

index 47a0f3a0b409d4f464a5e856c5a7347b87d7067f..34b0522812d89854845036aa1f5da87f552eba01 100644 (file)
@@ -75,6 +75,7 @@ var depsRules = `
        < runtime
        < sync/atomic
        < internal/race
+       < internal/asan
        < sync
        < internal/bisect
        < internal/godebug
diff --git a/src/internal/asan/asan.go b/src/internal/asan/asan.go
new file mode 100644 (file)
index 0000000..0a8148e
--- /dev/null
@@ -0,0 +1,19 @@
+// 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 asan
+
+package asan
+
+import (
+       "unsafe"
+)
+
+const Enabled = true
+
+//go:linkname Read runtime.asanread
+func Read(addr unsafe.Pointer, len int)
+
+//go:linkname Write runtime.asanwrite
+func Write(addr unsafe.Pointer, len int)
diff --git a/src/internal/asan/doc.go b/src/internal/asan/doc.go
new file mode 100644 (file)
index 0000000..21b1bc9
--- /dev/null
@@ -0,0 +1,10 @@
+// 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 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
diff --git a/src/internal/asan/noasan.go b/src/internal/asan/noasan.go
new file mode 100644 (file)
index 0000000..e01b46a
--- /dev/null
@@ -0,0 +1,19 @@
+// 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 !asan
+
+package asan
+
+import (
+       "unsafe"
+)
+
+const Enabled = false
+
+func Read(addr unsafe.Pointer, len int) {
+}
+
+func Write(addr unsafe.Pointer, len int) {
+}
index 25b83277e6d7a1ef638e136ec06a52cd094c2cf7..d79637a334db519bb36a0b0a62fc1f74fb49191d 100644 (file)
@@ -29,6 +29,7 @@ const asanenabled = true
 // asan{read,write} are nosplit because they may be called between
 // fork and exec, when the stack must not grow. See issue #50391.
 
+//go:linkname asanread
 //go:nosplit
 func asanread(addr unsafe.Pointer, sz uintptr) {
        sp := getcallersp()
@@ -36,6 +37,7 @@ func asanread(addr unsafe.Pointer, sz uintptr) {
        doasanread(addr, sz, sp, pc)
 }
 
+//go:linkname asanwrite
 //go:nosplit
 func asanwrite(addr unsafe.Pointer, sz uintptr) {
        sp := getcallersp()