diff options
| author | Keith Randall <khr@golang.org> | 2014-09-25 07:59:01 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2014-09-25 07:59:01 -0700 |
| commit | 1b6807bb069c528447270c3d6c66c5c7597f388f (patch) | |
| tree | b88dfe211ed127362e616742a4b957f32e77ee50 /src/runtime/stack.c | |
| parent | dfaf1f71e67de2807e07c880060b457d32a66b8b (diff) | |
| download | go-1b6807bb069c528447270c3d6c66c5c7597f388f.tar.xz | |
cgo: adjust return value location to account for stack copies.
During a cgo call, the stack can be copied. This copy invalidates
the pointer that cgo has into the return value area. To fix this
problem, pass the address of the location containing the stack
top value (which is in the G struct). For cgo functions which
return values, read the stktop before and after the cgo call to
compute the adjustment necessary to write the return value.
Fixes #8771
LGTM=iant, rsc
R=iant, rsc, khr
CC=golang-codereviews
https://golang.org/cl/144130043
Diffstat (limited to 'src/runtime/stack.c')
| -rw-r--r-- | src/runtime/stack.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/runtime/stack.c b/src/runtime/stack.c index 0d8814731c..2d23c717bd 100644 --- a/src/runtime/stack.c +++ b/src/runtime/stack.c @@ -827,7 +827,9 @@ runtime·shrinkstack(G *gp) if(used >= oldsize / 4) return; // still using at least 1/4 of the segment. - if(gp->syscallsp != 0) // TODO: can we handle this case? + // We can't copy the stack if we're in a syscall. + // The syscall might have pointers into the stack. + if(gp->syscallsp != 0) return; #ifdef GOOS_windows |
