diff options
| author | Dmitriy Vyukov <dvyukov@google.com> | 2014-03-12 10:21:34 +0400 |
|---|---|---|
| committer | Dmitriy Vyukov <dvyukov@google.com> | 2014-03-12 10:21:34 +0400 |
| commit | 1f4d2e79b0aaef6a9be08b01a97fe7b40b398ae7 (patch) | |
| tree | 29a2484e585e79ec73586a75df1d9acaf4ef5446 /src/pkg/runtime/stack.c | |
| parent | 00e6fc1e9e709a5c29b79d9aed8ae135cd54a445 (diff) | |
| download | go-1f4d2e79b0aaef6a9be08b01a97fe7b40b398ae7.tar.xz | |
runtime: efence support for growable stacks
1. Fix the bug that shrinkstack returns memory to heap.
This causes growslice to misbehave (it manually initialized
blocks, and in efence mode shrinkstack's free leads to
partially-initialized blocks coming out of growslice.
Which in turn causes GC to crash while treating the garbage
as Eface/Iface.
2. Enable efence for stack segments.
LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews, khr
https://golang.org/cl/74080043
Diffstat (limited to 'src/pkg/runtime/stack.c')
| -rw-r--r-- | src/pkg/runtime/stack.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/pkg/runtime/stack.c b/src/pkg/runtime/stack.c index 4d699f1101..4bdc24107c 100644 --- a/src/pkg/runtime/stack.c +++ b/src/pkg/runtime/stack.c @@ -102,7 +102,7 @@ runtime·stackalloc(G *gp, uint32 n) runtime·printf("stackalloc %d\n", n); gp->stacksize += n; - if(StackFromSystem) + if(runtime·debug.efence || StackFromSystem) return runtime·SysAlloc(ROUND(n, PageSize), &mstats.stacks_sys); // Minimum-sized stacks are allocated with a fixed-size free-list allocator, @@ -143,8 +143,8 @@ runtime·stackfree(G *gp, void *v, Stktop *top) if(StackDebug >= 1) runtime·printf("stackfree %p %d\n", v, (int32)n); gp->stacksize -= n; - if(StackFromSystem) { - if(StackFaultOnFree) + if(runtime·debug.efence || StackFromSystem) { + if(runtime·debug.efence || StackFaultOnFree) runtime·SysFault(v, n); else runtime·SysFree(v, n, &mstats.stacks_sys); @@ -819,7 +819,15 @@ runtime·shrinkstack(G *gp) gp->stack0 = (uintptr)oldstk + newsize; gp->stacksize -= oldsize - newsize; - // Free bottom half of the stack. First, we trick malloc into thinking + // Free bottom half of the stack. + if(runtime·debug.efence || StackFromSystem) { + if(runtime·debug.efence || StackFaultOnFree) + runtime·SysFault(oldstk, newsize); + else + runtime·SysFree(oldstk, newsize, &mstats.stacks_sys); + return; + } + // First, we trick malloc into thinking // we allocated the stack as two separate half-size allocs. Then the // free() call does the rest of the work for us. if(oldsize == PageSize) { |
