1
0
mirror of https://github.com/golang/go synced 2024-11-15 02:20:32 -07:00

internal/race,runtime: linkname contents of internal/race

Rather than importing runtime directly, linkname the functions from
runtime. This allows importing internal/race from internal/runtime/*
packages, similar to internal/asan and internal/msan.

For #54766.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-swissmap
Change-Id: Ibd9644557782076e3cee7927c8a6e6d2909f0a6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/616458
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
Michael Pratt 2024-09-16 11:22:02 -04:00 committed by Gopher Robot
parent 3b424cfa9d
commit e25b913127
3 changed files with 87 additions and 33 deletions

View File

@ -83,6 +83,7 @@ var depsRules = `
< internal/stringslite
< internal/itoa
< internal/unsafeheader
< internal/race
< internal/msan
< internal/asan
< internal/runtime/sys
@ -92,7 +93,6 @@ var depsRules = `
< internal/runtime/math
< internal/runtime/maps
< runtime
< internal/race
< sync/atomic
< internal/weak
< sync
@ -102,7 +102,7 @@ var depsRules = `
< errors
< internal/oserror;
cmp, internal/race, runtime, math/bits
cmp, runtime, math/bits
< iter
< maps, slices;

View File

@ -7,48 +7,39 @@
package race
import (
"runtime"
"unsafe"
)
const Enabled = true
func Acquire(addr unsafe.Pointer) {
runtime.RaceAcquire(addr)
}
// Functions below pushed from runtime.
func Release(addr unsafe.Pointer) {
runtime.RaceRelease(addr)
}
//go:linkname Acquire
func Acquire(addr unsafe.Pointer)
func ReleaseMerge(addr unsafe.Pointer) {
runtime.RaceReleaseMerge(addr)
}
//go:linkname Release
func Release(addr unsafe.Pointer)
func Disable() {
runtime.RaceDisable()
}
//go:linkname ReleaseMerge
func ReleaseMerge(addr unsafe.Pointer)
func Enable() {
runtime.RaceEnable()
}
//go:linkname Disable
func Disable()
func Read(addr unsafe.Pointer) {
runtime.RaceRead(addr)
}
//go:linkname Enable
func Enable()
func Write(addr unsafe.Pointer) {
runtime.RaceWrite(addr)
}
//go:linkname Read
func Read(addr unsafe.Pointer)
func ReadRange(addr unsafe.Pointer, len int) {
runtime.RaceReadRange(addr, len)
}
//go:linkname Write
func Write(addr unsafe.Pointer)
func WriteRange(addr unsafe.Pointer, len int) {
runtime.RaceWriteRange(addr, len)
}
//go:linkname ReadRange
func ReadRange(addr unsafe.Pointer, len int)
func Errors() int {
return runtime.RaceErrors()
}
//go:linkname WriteRange
func WriteRange(addr unsafe.Pointer, len int)
//go:linkname Errors
func Errors() int

View File

@ -14,16 +14,49 @@ import (
// Public race detection API, present iff build with -race.
func RaceRead(addr unsafe.Pointer)
//go:linkname race_Read internal/race.Read
//go:nosplit
func race_Read(addr unsafe.Pointer) {
RaceRead(addr)
}
func RaceWrite(addr unsafe.Pointer)
//go:linkname race_Write internal/race.Write
//go:nosplit
func race_Write(addr unsafe.Pointer) {
RaceWrite(addr)
}
func RaceReadRange(addr unsafe.Pointer, len int)
//go:linkname race_ReadRange internal/race.ReadRange
//go:nosplit
func race_ReadRange(addr unsafe.Pointer, len int) {
RaceReadRange(addr, len)
}
func RaceWriteRange(addr unsafe.Pointer, len int)
//go:linkname race_WriteRange internal/race.WriteRange
//go:nosplit
func race_WriteRange(addr unsafe.Pointer, len int) {
RaceWriteRange(addr, len)
}
func RaceErrors() int {
var n uint64
racecall(&__tsan_report_count, uintptr(unsafe.Pointer(&n)), 0, 0, 0)
return int(n)
}
//go:linkname race_Errors internal/race.Errors
//go:nosplit
func race_Errors() int {
return RaceErrors()
}
// RaceAcquire/RaceRelease/RaceReleaseMerge establish happens-before relations
// between goroutines. These inform the race detector about actual synchronization
// that it can't see for some reason (e.g. synchronization within RaceDisable/RaceEnable
@ -38,6 +71,12 @@ func RaceAcquire(addr unsafe.Pointer) {
raceacquire(addr)
}
//go:linkname race_Acquire internal/race.Acquire
//go:nosplit
func race_Acquire(addr unsafe.Pointer) {
RaceAcquire(addr)
}
// RaceRelease performs a release operation on addr that
// can synchronize with a later RaceAcquire on addr.
//
@ -49,6 +88,12 @@ func RaceRelease(addr unsafe.Pointer) {
racerelease(addr)
}
//go:linkname race_Release internal/race.Release
//go:nosplit
func race_Release(addr unsafe.Pointer) {
RaceRelease(addr)
}
// RaceReleaseMerge is like RaceRelease, but also establishes a happens-before
// relation with the preceding RaceRelease or RaceReleaseMerge on addr.
//
@ -60,6 +105,12 @@ func RaceReleaseMerge(addr unsafe.Pointer) {
racereleasemerge(addr)
}
//go:linkname race_ReleaseMerge internal/race.ReleaseMerge
//go:nosplit
func race_ReleaseMerge(addr unsafe.Pointer) {
RaceReleaseMerge(addr)
}
// RaceDisable disables handling of race synchronization events in the current goroutine.
// Handling is re-enabled with RaceEnable. RaceDisable/RaceEnable can be nested.
// Non-synchronization events (memory accesses, function entry/exit) still affect
@ -74,6 +125,12 @@ func RaceDisable() {
gp.raceignore++
}
//go:linkname race_Disable internal/race.Disable
//go:nosplit
func race_Disable() {
RaceDisable()
}
// RaceEnable re-enables handling of race events in the current goroutine.
//
//go:nosplit
@ -85,6 +142,12 @@ func RaceEnable() {
}
}
//go:linkname race_Enable internal/race.Enable
//go:nosplit
func race_Enable() {
RaceEnable()
}
// Private interface for the runtime.
const raceenabled = true