aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-03-16 14:55:10 -0400
committerAustin Clements <austin@google.com>2017-04-05 19:17:41 +0000
commit9741f0275c79786e16bdbe7b8ddfeecda421181f (patch)
treee8bf67e3a0bc304226ee1899bf54b238a11982c6 /src/runtime
parent92cf05daf3c96c854f8e2a32d6734a91ef7bb865 (diff)
downloadgo-9741f0275c79786e16bdbe7b8ddfeecda421181f.tar.xz
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>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/mheap.go8
-rw-r--r--src/runtime/stack.go4
2 files changed, 8 insertions, 4 deletions
diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go
index 6888406bee..df621549aa 100644
--- a/src/runtime/mheap.go
+++ b/src/runtime/mheap.go
@@ -326,10 +326,8 @@ func inHeapOrStack(b uintptr) bool {
return false
}
switch s.state {
- case mSpanInUse:
+ case mSpanInUse, _MSpanStack:
return b < s.limit
- case _MSpanStack:
- return b < s.base()+s.npages<<_PageShift
default:
return false
}
@@ -653,6 +651,10 @@ func (h *mheap) allocStack(npage uintptr) *mspan {
s.state = _MSpanStack
s.stackfreelist = 0
s.allocCount = 0
+ s.sizeclass = 0
+ s.nelems = 0
+ s.elemsize = 0
+ s.limit = s.base() + s.npages<<_PageShift
memstats.stacks_inuse += uint64(s.npages << _PageShift)
}
diff --git a/src/runtime/stack.go b/src/runtime/stack.go
index 830316b69a..e81bb5ba4c 100644
--- a/src/runtime/stack.go
+++ b/src/runtime/stack.go
@@ -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())
}