Source File
cgocheck.go
Belonging Package
runtime
package runtime
import (
)
const cgoWriteBarrierFail = "Go pointer stored into non-Go memory"
func ( *uintptr, uintptr) {
if !cgoIsGoPointer(unsafe.Pointer()) {
return
}
if cgoIsGoPointer(unsafe.Pointer()) {
return
}
if inPersistentAlloc(uintptr(unsafe.Pointer())) {
return
}
systemstack(func() {
println("write of Go pointer", hex(), "to non-Go memory", hex(uintptr(unsafe.Pointer())))
throw(cgoWriteBarrierFail)
})
}
func ( *_type, , unsafe.Pointer, , uintptr) {
if .ptrdata == 0 {
return
}
if !cgoIsGoPointer() {
return
}
if cgoIsGoPointer() {
return
}
cgoCheckTypedBlock(, , , )
}
func ( *_type, , unsafe.Pointer, int) {
if .ptrdata == 0 {
return
}
if !cgoIsGoPointer() {
return
}
if cgoIsGoPointer() {
return
}
:=
for := 0; < ; ++ {
cgoCheckTypedBlock(, , 0, .size)
= add(, .size)
}
}
if .ptrdata <= {
return
}
if := .ptrdata - ; > {
=
}
if .kind&kindGCProg == 0 {
cgoCheckBits(, .gcdata, , )
return
}
for , := range activeModules() {
if cgoInRange(, .data, .edata) {
:= uintptr() - .data
cgoCheckBits(add(, -), .gcdatamask.bytedata, +, )
return
}
if cgoInRange(, .bss, .ebss) {
:= uintptr() - .bss
cgoCheckBits(add(, -), .gcbssmask.bytedata, +, )
return
}
}
:= spanOfUnchecked(uintptr())
systemstack(func() {
cgoCheckUsingType(, , , )
})
return
}
:= heapBitsForAddr(uintptr())
for := uintptr(0); < +; += sys.PtrSize {
:= .bits()
if >= && &bitPointer != 0 {
:= *(*unsafe.Pointer)(add(, ))
if cgoIsGoPointer() {
throw(cgoWriteBarrierFail)
}
}
= .next()
}
}
func ( unsafe.Pointer, *byte, , uintptr) {
:= / sys.PtrSize / 8
:= * sys.PtrSize * 8
:= addb(, )
= add(, )
-=
+=
var uint32
for := uintptr(0); < ; += sys.PtrSize {
if &(sys.PtrSize*8-1) == 0 {
= uint32(*)
= addb(, 1)
} else {
>>= 1
}
if > 0 {
-= sys.PtrSize
} else {
if &1 != 0 {
:= *(*unsafe.Pointer)(add(, ))
if cgoIsGoPointer() {
throw(cgoWriteBarrierFail)
}
}
}
}
}
if .ptrdata <= {
return
}
if := .ptrdata - ; > {
=
}
if .kind&kindGCProg == 0 {
cgoCheckBits(, .gcdata, , )
return
}
switch .kind & kindMask {
default:
throw("can't happen")
case kindArray:
:= (*arraytype)(unsafe.Pointer())
for := uintptr(0); < .len; ++ {
if < .elem.size {
(.elem, , , )
}
= add(, .elem.size)
:=
if > .elem.size {
= .elem.size
}
:= .elem.size -
-=
if <= {
return
}
-=
}
case kindStruct:
:= (*structtype)(unsafe.Pointer())
for , := range .fields {
if < .typ.size {
(.typ, , , )
}
= add(, .typ.size)
:=
if > .typ.size {
= .typ.size
}
:= .typ.size -
-=
if <= {
return
}
-=
}
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |