Skip to content

internal/asan: add new package #64635

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 5 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/asan
< sync
< internal/bisect
< internal/godebug
Expand Down
19 changes: 19 additions & 0 deletions src/internal/asan/asan.go
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/internal/asan/doc.go
Original file line number Diff line number Diff line change
@@ -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 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 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) {
}
2 changes: 2 additions & 0 deletions src/runtime/asan.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ 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()
pc := getcallerpc()
doasanread(addr, sz, sp, pc)
}

//go:linkname asanwrite
//go:nosplit
func asanwrite(addr unsafe.Pointer, sz uintptr) {
sp := getcallersp()
Expand Down