- Code Path:
src/runtime/cgocall.go
The key part here is to switch the stack between Go
and CGO
Go -> C
cgocall
entersyscall
: this will ensure that CGO codes will not block the Go runtime.- mark
m
asincgo
asmcgocall
- KeepAlive CGO-related
fn
,arg
, andmp
asmcgocall
- Set-up the stack.
C -> Go
cgocallback
- Set-up the stack for
cgocallbackg
, aftercgocallbackg
, thesp
will point to the previous code calledcgocallback
cgocallbackg
- callbackUpdateSystemStack
- lockOSThread to pin the
g
on the currentm
exitsyscall
cgocallbackg1
- undo the previous steps
reentersyscall