*/
func chansend(t *chantype, c *hchan, ep unsafe.Pointer, block bool, callerpc uintptr) bool {
if raceenabled {
- fn := chansend
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- raceReadObjectPC(t.elem, ep, callerpc, pc)
+ raceReadObjectPC(t.elem, ep, callerpc, funcPC(chansend))
}
if c == nil {
}
if raceenabled {
- fn := chansend
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(c), pc, callerpc)
+ racereadpc(unsafe.Pointer(c), callerpc, funcPC(chansend))
}
// Fast path: check for failed non-blocking operation without acquiring the lock.
if raceenabled {
callerpc := getcallerpc(unsafe.Pointer(&c))
- fn := closechan
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racewritepc(unsafe.Pointer(c), callerpc, pc)
+ racewritepc(unsafe.Pointer(c), callerpc, funcPC(closechan))
racerelease(unsafe.Pointer(c))
}
log := &p.log[p.toggle]
q := uintptr(0)
if p.lost > 0 {
- f := lostProfileData
- lostPC := **(**uintptr)(unsafe.Pointer(&f))
+ lostPC := funcPC(lostProfileData)
log[0] = p.lost
log[1] = 1
log[2] = lostPC
mp := acquirem()
mp.ptrarg[0] = unsafe.Pointer(desc)
mp.ptrarg[1] = unsafe.Pointer(ctx)
- mp.ptrarg[2] = **(**unsafe.Pointer)(unsafe.Pointer(&body))
+ mp.ptrarg[2] = unsafe.Pointer(funcPC(body)) // TODO(rsc): Should be a scalar.
mp.scalararg[0] = uintptr(nthr)
mp.scalararg[1] = uintptr(n)
mp.scalararg[2] = 0
func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapaccess1
- pc := **(**uintptr)(unsafe.Pointer(&fn))
+ pc := funcPC(mapaccess1)
racereadpc(unsafe.Pointer(h), callerpc, pc)
raceReadObjectPC(t.key, key, callerpc, pc)
}
func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool) {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapaccess2
- pc := **(**uintptr)(unsafe.Pointer(&fn))
+ pc := funcPC(mapaccess2)
racereadpc(unsafe.Pointer(h), callerpc, pc)
raceReadObjectPC(t.key, key, callerpc, pc)
}
}
if raceenabled {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapassign1
- pc := **(**uintptr)(unsafe.Pointer(&fn))
+ pc := funcPC(mapassign1)
racewritepc(unsafe.Pointer(h), callerpc, pc)
raceReadObjectPC(t.key, key, callerpc, pc)
raceReadObjectPC(t.elem, val, callerpc, pc)
func mapdelete(t *maptype, h *hmap, key unsafe.Pointer) {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapdelete
- pc := **(**uintptr)(unsafe.Pointer(&fn))
+ pc := funcPC(mapdelete)
racewritepc(unsafe.Pointer(h), callerpc, pc)
raceReadObjectPC(t.key, key, callerpc, pc)
}
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapiterinit
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapiterinit))
}
if h == nil || h.count == 0 {
h := it.h
if raceenabled {
callerpc := getcallerpc(unsafe.Pointer(&it))
- fn := mapiternext
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapiternext))
}
t := it.t
bucket := it.bucket
}
if raceenabled {
callerpc := getcallerpc(unsafe.Pointer(&h))
- fn := reflect_maplen
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(reflect_maplen))
}
return h.count
}
func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapaccess1_fast32
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapaccess1_fast32))
}
if h == nil || h.count == 0 {
return unsafe.Pointer(t.elem.zero)
func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapaccess2_fast32
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapaccess2_fast32))
}
if h == nil || h.count == 0 {
return unsafe.Pointer(t.elem.zero), false
func mapaccess1_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapaccess1_fast64
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapaccess1_fast64))
}
if h == nil || h.count == 0 {
return unsafe.Pointer(t.elem.zero)
func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapaccess2_fast64
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapaccess2_fast64))
}
if h == nil || h.count == 0 {
return unsafe.Pointer(t.elem.zero), false
func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapaccess1_faststr
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapaccess1_faststr))
}
if h == nil || h.count == 0 {
return unsafe.Pointer(t.elem.zero)
func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
if raceenabled && h != nil {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := mapaccess2_faststr
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadpc(unsafe.Pointer(h), callerpc, pc)
+ racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapaccess2_faststr))
}
if h == nil || h.count == 0 {
return unsafe.Pointer(t.elem.zero), false
s.next = c.sudogcache
c.sudogcache = s
}
+
+// funcPC returns the entry PC of the function f.
+// It assumes that f is a func value. Otherwise the behavior is undefined.
+func funcPC(f interface{}) uintptr {
+ return **(**uintptr)(add(unsafe.Pointer(&f), ptrSize))
+}
)
var (
- chansendpc uintptr
- chanrecvpc uintptr
+ chansendpc = funcPC(chansend)
+ chanrecvpc = funcPC(chanrecv)
)
-func init() {
- f := chansend
- chansendpc = **(**uintptr)(unsafe.Pointer(&f))
- g := chanrecv
- chanrecvpc = **(**uintptr)(unsafe.Pointer(&g))
-}
-
func selectsize(size uintptr) uintptr {
selsize := unsafe.Sizeof(_select{}) +
(size-1)*unsafe.Sizeof(_select{}.scase[0]) +
k *scase
sglist *sudog
sgnext *sudog
- fn func(*g, *_select) bool
)
loop:
// wait for someone to wake us up
gp.param = nil
- fn = selparkcommit
- gopark(**(**unsafe.Pointer)(unsafe.Pointer(&fn)), unsafe.Pointer(sel), "select")
+ gopark(unsafe.Pointer(funcPC(selparkcommit)), unsafe.Pointer(sel), "select")
// someone woke us up
sellock(sel)
if raceenabled {
callerpc := getcallerpc(unsafe.Pointer(&t))
- fn := growslice
- pc := **(**uintptr)(unsafe.Pointer(&fn))
- racereadrangepc(old.array, old.len*int(t.elem.size), callerpc, pc)
+ racereadrangepc(old.array, old.len*int(t.elem.size), callerpc, funcPC(growslice))
}
et := t.elem
if raceenabled {
callerpc := getcallerpc(unsafe.Pointer(&to))
- fn := slicecopy
- pc := **(**uintptr)(unsafe.Pointer(&fn))
+ pc := funcPC(slicecopy)
racewriterangepc(to.array, n*int(width), callerpc, pc)
racereadrangepc(fm.array, n*int(width), callerpc, pc)
}
if raceenabled {
callerpc := getcallerpc(unsafe.Pointer(&to))
- fn := slicestringcopy
- pc := **(**uintptr)(unsafe.Pointer(&fn))
+ pc := funcPC(slicestringcopy)
racewriterangepc(unsafe.Pointer(&to[0]), n, callerpc, pc)
}
func slicebytetostring(b []byte) string {
if raceenabled && len(b) > 0 {
- fn := slicebytetostring
racereadrangepc(unsafe.Pointer(&b[0]),
len(b),
getcallerpc(unsafe.Pointer(&b)),
- **(**uintptr)(unsafe.Pointer(&fn)))
+ funcPC(slicebytetostring))
}
s, c := rawstring(len(b))
copy(c, b)
// m is a string-keyed map and k is a []byte.
if raceenabled && len(b) > 0 {
- fn := slicebytetostringtmp
racereadrangepc(unsafe.Pointer(&b[0]),
len(b),
getcallerpc(unsafe.Pointer(&b)),
- **(**uintptr)(unsafe.Pointer(&fn)))
+ funcPC(slicebytetostringtmp))
}
return *(*string)(unsafe.Pointer(&b))
}
func slicerunetostring(a []rune) string {
if raceenabled && len(a) > 0 {
- fn := slicerunetostring
racereadrangepc(unsafe.Pointer(&a[0]),
len(a)*int(unsafe.Sizeof(a[0])),
getcallerpc(unsafe.Pointer(&a)),
- **(**uintptr)(unsafe.Pointer(&fn)))
+ funcPC(slicerunetostring))
}
var dum [4]byte
size1 := 0