From 57c1edcaec010874ed4a8491ca4ba3a2dda77339 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 12 Aug 2022 16:38:56 +0700 Subject: [PATCH] runtime: mark atomic methods which call nosplit functions as nosplit Fixes #54411 Change-Id: I482ebca7365862bfb82a9daf8111c6f395aa1170 Reviewed-on: https://go-review.googlesource.com/c/go/+/423255 Reviewed-by: Michael Knyszek Reviewed-by: Michael Pratt Run-TryBot: Cuong Manh Le TryBot-Result: Gopher Robot --- src/runtime/internal/atomic/types.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/runtime/internal/atomic/types.go b/src/runtime/internal/atomic/types.go index 784acaadc1d..dbacb86704a 100644 --- a/src/runtime/internal/atomic/types.go +++ b/src/runtime/internal/atomic/types.go @@ -100,6 +100,8 @@ type Uint8 struct { } // Load accesses and returns the value atomically. +// +//go:nosplit func (u *Uint8) Load() uint8 { return Load8(&u.value) } @@ -136,6 +138,8 @@ type Bool struct { } // Load accesses and returns the value atomically. +// +//go:nosplit func (b *Bool) Load() bool { return b.u.Load() != 0 } @@ -158,6 +162,8 @@ type Uint32 struct { } // Load accesses and returns the value atomically. +// +//go:nosplit func (u *Uint32) Load() uint32 { return Load(&u.value) } @@ -169,6 +175,8 @@ func (u *Uint32) Load() uint32 { // on this thread can be observed to occur before it. // // WARNING: Use sparingly and with great care. +// +//go:nosplit func (u *Uint32) LoadAcquire() uint32 { return LoadAcq(&u.value) } @@ -255,6 +263,8 @@ type Uint64 struct { } // Load accesses and returns the value atomically. +// +//go:nosplit func (u *Uint64) Load() uint64 { return Load64(&u.value) } @@ -283,6 +293,8 @@ func (u *Uint64) Swap(value uint64) uint64 { // // This operation wraps around in the usual // two's-complement way. +// +//go:nosplit func (u *Uint64) Add(delta int64) uint64 { return Xadd64(&u.value, delta) } @@ -307,6 +319,8 @@ func (u *Uintptr) Load() uintptr { // on this thread can be observed to occur before it. // // WARNING: Use sparingly and with great care. +// +//go:nosplit func (u *Uintptr) LoadAcquire() uintptr { return LoadAcquintptr(&u.value) } @@ -361,6 +375,8 @@ type Float64 struct { } // Load accesses and returns the value atomically. +// +//go:nosplit func (f *Float64) Load() float64 { r := f.u.Load() return *(*float64)(unsafe.Pointer(&r)) @@ -386,6 +402,8 @@ type UnsafePointer struct { } // Load accesses and returns the value atomically. +// +//go:nosplit func (u *UnsafePointer) Load() unsafe.Pointer { return Loadp(unsafe.Pointer(&u.value)) } @@ -420,6 +438,8 @@ type Pointer[T any] struct { } // Load accesses and returns the value atomically. +// +//go:nosplit func (p *Pointer[T]) Load() *T { return (*T)(p.u.Load()) }