]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/runtime/atomic_pointer.go
runtime: reimplement GODEBUG=cgocheck=2 as a GOEXPERIMENT
[gostls13.git] / src / runtime / atomic_pointer.go
index 25e0e651b461017655db8fe5f5b4cbcbed85b321..26dfbfc2cc008f01de596e6ae4208fd0fcbac2af 100644 (file)
@@ -5,6 +5,7 @@
 package runtime
 
 import (
+       "internal/goexperiment"
        "runtime/internal/atomic"
        "unsafe"
 )
@@ -21,7 +22,7 @@ import (
 func atomicwb(ptr *unsafe.Pointer, new unsafe.Pointer) {
        slot := (*uintptr)(unsafe.Pointer(ptr))
        if !getg().m.p.ptr().wbBuf.putFast(*slot, uintptr(new)) {
-               wbBufFlush(slot, uintptr(new))
+               wbBufFlush()
        }
 }
 
@@ -32,6 +33,9 @@ func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer) {
        if writeBarrier.enabled {
                atomicwb((*unsafe.Pointer)(ptr), new)
        }
+       if goexperiment.CgoCheck2 {
+               cgoCheckPtrWrite((*unsafe.Pointer)(ptr), new)
+       }
        atomic.StorepNoWB(noescape(ptr), new)
 }
 
@@ -53,6 +57,9 @@ func atomic_casPointer(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
        if writeBarrier.enabled {
                atomicwb(ptr, new)
        }
+       if goexperiment.CgoCheck2 {
+               cgoCheckPtrWrite(ptr, new)
+       }
        return atomic.Casp1(ptr, old, new)
 }
 
@@ -69,6 +76,9 @@ func sync_atomic_StorePointer(ptr *unsafe.Pointer, new unsafe.Pointer) {
        if writeBarrier.enabled {
                atomicwb(ptr, new)
        }
+       if goexperiment.CgoCheck2 {
+               cgoCheckPtrWrite(ptr, new)
+       }
        sync_atomic_StoreUintptr((*uintptr)(unsafe.Pointer(ptr)), uintptr(new))
 }
 
@@ -81,6 +91,9 @@ func sync_atomic_SwapPointer(ptr *unsafe.Pointer, new unsafe.Pointer) unsafe.Poi
        if writeBarrier.enabled {
                atomicwb(ptr, new)
        }
+       if goexperiment.CgoCheck2 {
+               cgoCheckPtrWrite(ptr, new)
+       }
        old := unsafe.Pointer(sync_atomic_SwapUintptr((*uintptr)(noescape(unsafe.Pointer(ptr))), uintptr(new)))
        return old
 }
@@ -94,5 +107,8 @@ func sync_atomic_CompareAndSwapPointer(ptr *unsafe.Pointer, old, new unsafe.Poin
        if writeBarrier.enabled {
                atomicwb(ptr, new)
        }
+       if goexperiment.CgoCheck2 {
+               cgoCheckPtrWrite(ptr, new)
+       }
        return sync_atomic_CompareAndSwapUintptr((*uintptr)(noescape(unsafe.Pointer(ptr))), uintptr(old), uintptr(new))
 }