- 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
masincgo asmcgocall- KeepAlive CGO-related
fn,arg, andmp
asmcgocall
- Set-up the stack.
C -> Go
cgocallback
- Set-up the stack for
cgocallbackg, aftercgocallbackg, thespwill point to the previous code calledcgocallback
cgocallbackg
- callbackUpdateSystemStack
- lockOSThread to pin the
gon the currentm exitsyscallcgocallbackg1- undo the previous steps
reentersyscall