runtime: initialize more fields of stack spans

Stack spans don't internally use many of the fields of the mspan,
which means things like the size class and element size get left over
from whatever last used the mspan. This can lead to confusing crashes
and debugging.

Zero these fields or initialize them to something reasonable. This
also lets us simplify some code that currently has to distinguish
between heap and stack spans.

Change-Id: I9bd114e76c147bb32de497045b932f8bf1988bbf
Reviewed-on: https://go-review.googlesource.com/38573
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
This commit is contained in:
Austin Clements 2017-03-16 14:55:10 -04:00
parent 92cf05daf3
commit 9741f0275c
2 changed files with 8 additions and 4 deletions

View file

@ -196,7 +196,8 @@ func stackpoolalloc(order uint8) gclinkptr {
if s.stackfreelist.ptr() != nil {
throw("bad stackfreelist")
}
for i := uintptr(0); i < _StackCacheSize; i += _FixedStack << order {
s.elemsize = _FixedStack << order
for i := uintptr(0); i < _StackCacheSize; i += s.elemsize {
x := gclinkptr(s.base() + i)
x.ptr().next = s.stackfreelist
s.stackfreelist = x
@ -393,6 +394,7 @@ func stackalloc(n uint32) stack {
if s == nil {
throw("out of memory")
}
s.elemsize = uintptr(n)
}
v = unsafe.Pointer(s.base())
}