Source File
cgocall.go
Belonging Package
runtime
package runtime
import (
)
type cgoCallers [32]uintptr
.cgoCallers[0] = 0
osPreemptExtEnter()
.incgo = true
:= asmcgocall(, )
.incgo = false
.ncgo--
osPreemptExtExit()
exitsyscall()
if raceenabled {
raceacquire(unsafe.Pointer(&racecgosync))
}
:= unsafe.Pointer(.syscallsp)
:= .syscallpc
exitsyscall() // coming out of cgo call
.m.incgo = false
osPreemptExtExit(.m)
cgocallbackg1(, , )
reentersyscall(, uintptr())
.m.syscall =
}
func (, unsafe.Pointer, uintptr) {
:= getg()
if .m.needextram || atomic.Load(&extraMWaiters) > 0 {
.m.needextram = false
systemstack(newextram)
}
if != 0 {
:= append(.cgoCtxt, )
<-main_init_done
}
:= true
defer unwindm(&)
if raceenabled {
raceacquire(unsafe.Pointer(&racecgosync))
}
:= acquirem()
:= &.g0.sched
switch GOARCH {
default:
throw("unwindm not implemented")
case "386", "amd64", "arm", "ppc64", "ppc64le", "mips64", "mips64le", "s390x", "mips", "mipsle", "riscv64":
.sp = *(*uintptr)(unsafe.Pointer(.sp + sys.MinFrameSize))
case "arm64":
.sp = *(*uintptr)(unsafe.Pointer(.sp + 16))
}
unlockOSThread()
}
func () {
throw("misaligned stack in cgocallback")
}
func () {
throw("cgo not implemented")
}
var racecgosync uint64 // represents possible synchronization in C code
func ( interface{}, interface{}) {
if debug.cgocheck == 0 {
return
}
:= efaceOf(&)
:= ._type
:= true
if != nil && (.kind&kindMask == kindPtr || .kind&kindMask == kindUnsafePointer) {
:= .data
if .kind&kindDirectIface == 0 {
= *(*unsafe.Pointer)()
}
if == nil || !cgoIsGoPointer() {
return
}
:= efaceOf(&)
switch ._type.kind & kindMask {
case kindBool:
break
}
:= (*ptrtype)(unsafe.Pointer())
cgoCheckArg(.elem, , true, false, cgoCheckPointerFail)
return
=
= ._type
=
= ._type
= false
default:
throw("can't happen")
}
}
cgoCheckArg(, .data, .kind&kindDirectIface == 0, , cgoCheckPointerFail)
}
const cgoCheckPointerFail = "cgo argument has Go pointer to Go pointer"
const cgoResultFail = "cgo result has Go pointer"
panic(errorString())
case kindFunc:
if {
= *(*unsafe.Pointer)()
}
if !cgoIsGoPointer() {
return
}
panic(errorString())
case kindInterface:
:= *(**_type)()
if == nil {
return
if inheap(uintptr(unsafe.Pointer())) {
panic(errorString())
}
= *(*unsafe.Pointer)(add(, sys.PtrSize))
if !cgoIsGoPointer() {
return
}
if ! {
panic(errorString())
}
(, , .kind&kindDirectIface == 0, false, )
case kindSlice:
:= (*slicetype)(unsafe.Pointer())
:= (*slice)()
= .array
if == nil || !cgoIsGoPointer() {
return
}
if ! {
panic(errorString())
}
if .elem.ptrdata == 0 {
return
}
for := 0; < .cap; ++ {
(.elem, , true, false, )
= add(, .elem.size)
}
case kindString:
:= (*stringStruct)()
if !cgoIsGoPointer(.str) {
return
}
if ! {
panic(errorString())
}
case kindStruct:
:= (*structtype)(unsafe.Pointer())
if ! {
if len(.fields) != 1 {
throw("can't happen")
}
(.fields[0].typ, , .fields[0].typ.kind&kindDirectIface == 0, , )
return
}
for , := range .fields {
if .typ.ptrdata == 0 {
continue
}
(.typ, add(, .offset()), true, , )
}
case kindPtr, kindUnsafePointer:
if {
= *(*unsafe.Pointer)()
if == nil {
return
}
}
if !cgoIsGoPointer() {
return
}
if ! {
panic(errorString())
}
cgoCheckUnknownPointer(, )
}
}
break
}
if .isPointer() && cgoIsGoPointer(*(*unsafe.Pointer)(unsafe.Pointer( + ))) {
panic(errorString())
}
= .next()
}
return
}
for , := range activeModules() {
panic(errorString())
}
return
}
func ( unsafe.Pointer) bool {
if == nil {
return false
}
if inHeapOrStack(uintptr()) {
return true
}
for , := range activeModules() {
if cgoInRange(, .data, .edata) || cgoInRange(, .bss, .ebss) {
return true
}
}
return false
}
func ( interface{}) {
if debug.cgocheck == 0 {
return
}
:= efaceOf(&)
:= ._type
cgoCheckArg(, .data, .kind&kindDirectIface == 0, false, cgoResultFail)
![]() |
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. |