mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: make morestack less subtle
morestack writes the context pointer to gobuf.ctxt, but since morestack is written in assembly (and has to be very careful with state), it does *not* invoke the requisite write barrier for this write. Instead, we patch this up later, in newstack, where we invoke an explicit write barrier for ctxt. This already requires some subtle reasoning, and it's going to get a lot hairier with the hybrid barrier. Fix this by simplifying the whole mechanism. Instead of writing gobuf.ctxt in morestack, just pass the value of the context register to newstack and let it write it to gobuf.ctxt. This is a normal Go pointer write, so it gets the normal Go write barrier. No subtle reasoning required. Updates #17503. Change-Id: Ia6bf8459bfefc6828f53682ade32c02412e4db63 Reviewed-on: https://go-review.googlesource.com/31550 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
cdccd6a79c
commit
bf9c71cb43
9 changed files with 39 additions and 19 deletions
|
|
@ -925,7 +925,10 @@ func round2(x int32) int32 {
|
|||
//
|
||||
// g->atomicstatus will be Grunning or Gscanrunning upon entry.
|
||||
// If the GC is trying to stop this g then it will set preemptscan to true.
|
||||
func newstack() {
|
||||
//
|
||||
// ctxt is the value of the context register on morestack. newstack
|
||||
// will write it to g.sched.ctxt.
|
||||
func newstack(ctxt unsafe.Pointer) {
|
||||
thisg := getg()
|
||||
// TODO: double check all gp. shouldn't be getg().
|
||||
if thisg.m.morebuf.g.ptr().stackguard0 == stackFork {
|
||||
|
|
@ -937,8 +940,13 @@ func newstack() {
|
|||
traceback(morebuf.pc, morebuf.sp, morebuf.lr, morebuf.g.ptr())
|
||||
throw("runtime: wrong goroutine in newstack")
|
||||
}
|
||||
|
||||
gp := thisg.m.curg
|
||||
// Write ctxt to gp.sched. We do this here instead of in
|
||||
// morestack so it has the necessary write barrier.
|
||||
gp.sched.ctxt = ctxt
|
||||
|
||||
if thisg.m.curg.throwsplit {
|
||||
gp := thisg.m.curg
|
||||
// Update syscallsp, syscallpc in case traceback uses them.
|
||||
morebuf := thisg.m.morebuf
|
||||
gp.syscallsp = morebuf.sp
|
||||
|
|
@ -951,7 +959,6 @@ func newstack() {
|
|||
throw("runtime: stack split at bad time")
|
||||
}
|
||||
|
||||
gp := thisg.m.curg
|
||||
morebuf := thisg.m.morebuf
|
||||
thisg.m.morebuf.pc = 0
|
||||
thisg.m.morebuf.lr = 0
|
||||
|
|
@ -1003,14 +1010,6 @@ func newstack() {
|
|||
throw("runtime: split stack overflow")
|
||||
}
|
||||
|
||||
if gp.sched.ctxt != nil {
|
||||
// morestack wrote sched.ctxt on its way in here,
|
||||
// without a write barrier. Run the write barrier now.
|
||||
// It is not possible to be preempted between then
|
||||
// and now, so it's okay.
|
||||
writebarrierptr_nostore((*uintptr)(unsafe.Pointer(&gp.sched.ctxt)), uintptr(gp.sched.ctxt))
|
||||
}
|
||||
|
||||
if preempt {
|
||||
if gp == thisg.m.g0 {
|
||||
throw("runtime: preempt g0")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue