mirror of
https://github.com/golang/go
synced 2024-11-23 00:20:12 -07:00
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 unconditionally, making the functions a no-op if the
build flag "asan" is not present.
For #64611
Change-Id: Ie79e698aea7a6d969afd2a5f008c084c9545b1a5
GitHub-Last-Rev: e658670c14
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>
This commit is contained in:
parent
1b541502c2
commit
db99b9b17c
@ -75,6 +75,7 @@ var depsRules = `
|
|||||||
< runtime
|
< runtime
|
||||||
< sync/atomic
|
< sync/atomic
|
||||||
< internal/race
|
< internal/race
|
||||||
|
< internal/asan
|
||||||
< sync
|
< sync
|
||||||
< internal/bisect
|
< internal/bisect
|
||||||
< internal/godebug
|
< internal/godebug
|
||||||
|
19
src/internal/asan/asan.go
Normal file
19
src/internal/asan/asan.go
Normal file
@ -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)
|
10
src/internal/asan/doc.go
Normal file
10
src/internal/asan/doc.go
Normal file
@ -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
|
19
src/internal/asan/noasan.go
Normal file
19
src/internal/asan/noasan.go
Normal file
@ -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) {
|
||||||
|
}
|
@ -29,6 +29,7 @@ const asanenabled = true
|
|||||||
// asan{read,write} are nosplit because they may be called between
|
// asan{read,write} are nosplit because they may be called between
|
||||||
// fork and exec, when the stack must not grow. See issue #50391.
|
// fork and exec, when the stack must not grow. See issue #50391.
|
||||||
|
|
||||||
|
//go:linkname asanread
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func asanread(addr unsafe.Pointer, sz uintptr) {
|
func asanread(addr unsafe.Pointer, sz uintptr) {
|
||||||
sp := getcallersp()
|
sp := getcallersp()
|
||||||
@ -36,6 +37,7 @@ func asanread(addr unsafe.Pointer, sz uintptr) {
|
|||||||
doasanread(addr, sz, sp, pc)
|
doasanread(addr, sz, sp, pc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:linkname asanwrite
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func asanwrite(addr unsafe.Pointer, sz uintptr) {
|
func asanwrite(addr unsafe.Pointer, sz uintptr) {
|
||||||
sp := getcallersp()
|
sp := getcallersp()
|
||||||
|
Loading…
Reference in New Issue
Block a user