Another interesting example is when you associate βnormalβ code, such as C, with some other version of the language using split stacks such as Go.
In Go, goroutines (light streams) have a rather small stack that expands as needed. Basically, each function prolog checks that the stack has enough free space, and increases the stack if it does not.
When Go calls C code through cgo, it automatically expands the stack to meet C expectations.
However, if the C code sets up signal handlers, they can be called at any time, including if there is not enough stack space.
Thus, any C code that references Go code must use SA_ONSTACK so as not to crash.
https://golang.org/pkg/os/signal/#hdr-Go_programs_that_use_cgo_or_SWIG
source share