mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: get a better g0 stack bound in needm
Currently, when C calls into Go the first time, we grab an M using needm, which sets m.g0's stack bounds using the SP. We don't know how big the stack is, so we simply assume 32K. Previously, when the Go function returns to C, we drop the M, and the next time C calls into Go, we put a new stack bound on the g0 based on the current SP. After CL 392854, we don't drop the M, and the next time C calls into Go, we reuse the same g0, without recomputing the stack bounds. If the C code uses quite a bit of stack space before calling into Go, the SP may be well below the 32K stack bound we assumed, so the runtime thinks the g0 stack overflows. This CL makes needm get a more accurate stack bound from pthread. (In some platforms this may still be a guess as we don't know exactly where we are in the C stack), but it is probably better than simply assuming 32K. For #59294. Change-Id: Ie52a8f931e0648d8753e4c1dbe45468b8748b527 Reviewed-on: https://go-review.googlesource.com/c/go/+/479915 Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
c5ccff405e
commit
443eb9757c
10 changed files with 182 additions and 7 deletions
|
|
@ -585,7 +585,7 @@ func adjustSignalStack(sig uint32, mp *m, gsigStack *gsignalStack) bool {
|
|||
|
||||
// sp is not within gsignal stack, g0 stack, or sigaltstack. Bad.
|
||||
setg(nil)
|
||||
needm()
|
||||
needm(true)
|
||||
if st.ss_flags&_SS_DISABLE != 0 {
|
||||
noSignalStack(sig)
|
||||
} else {
|
||||
|
|
@ -1068,7 +1068,7 @@ func badsignal(sig uintptr, c *sigctxt) {
|
|||
exit(2)
|
||||
*(*uintptr)(unsafe.Pointer(uintptr(123))) = 2
|
||||
}
|
||||
needm()
|
||||
needm(true)
|
||||
if !sigsend(uint32(sig)) {
|
||||
// A foreign thread received the signal sig, and the
|
||||
// Go code does not want to handle it.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue