1
0
mirror of https://github.com/golang/go synced 2024-10-04 04:31:21 -06:00
go/src
Russ Cox cf622d758c syscall: keep allocated C string live across call to Syscall
Given:

        p := alloc()
        fn_taking_ptr(p)

p is NOT recorded as live at the call to fn_taking_ptr:
it's not needed by the code following the call.
p was passed to fn_taking_ptr, and fn_taking_ptr must keep
it alive as long as it needs it.
In practice, fn_taking_ptr will keep its own arguments live
for as long as the function is executing.

But if instead you have:

        p := alloc()
        i := uintptr(unsafe.Pointer(p))
        fn_taking_int(i)

p is STILL NOT recorded as live at the call to fn_taking_int:
it's not needed by the code following the call.
fn_taking_int is responsible for keeping its own arguments
live, but fn_taking_int is written to take an integer, so even
though fn_taking_int does keep its argument live, that argument
does not keep the allocated memory live, because the garbage
collector does not dereference integers.

The shorter form:

        p := alloc()
        fn_taking_int(uintptr(unsafe.Pointer(p)))

and the even shorter form:

        fn_taking_int(uintptr(unsafe.Pointer(alloc())))

are both the same as the 3-line form above.

syscall.Syscall is like fn_taking_int: it is written to take a list
of integers, and yet those integers are sometimes pointers.
If there is no other copy of those pointers being kept live,
the memory they point at may be garbage collected during
the call to syscall.Syscall.

This is happening on Solaris: for whatever reason, the timing
is such that the garbage collector manages to free the string
argument to the open(2) system call before the system call
has been invoked.

Change the system call wrappers to insert explicit references
that will keep the allocations alive in the original frame
(and therefore preserve the memory) until after syscall.Syscall
has returned.

Should fix Solaris flakiness.

This is not a problem for cgo, because cgo wrappers have
correctly typed arguments.

LGTM=iant, khr, aram, rlh
R=iant, khr, bradfitz, aram, rlh
CC=dvyukov, golang-codereviews, r
https://golang.org/cl/139360044
2014-09-08 16:59:59 -04:00
..
archive build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
bufio build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
builtin build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
bytes build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
cmd cmd/cc: fix undefined behaviour warning in bv.c 2014-09-08 16:06:41 +10:00
compress build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
container build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
crypto build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
database/sql build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
debug build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
encoding build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
errors build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
expvar build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
flag build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
fmt build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
go build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
hash build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
html build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
image build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
index/suffixarray build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
internal/syscall build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
io build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
lib9 lib9: format %#04x, 0 as 0x0000 not 000000. 2014-07-23 10:17:47 -04:00
libbio
liblink liblink, runtime: diagnose and fix C code running on Go stack 2014-09-08 14:05:23 -04:00
log build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
math build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
mime build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
net build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
os build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
path build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
reflect build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
regexp build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
runtime runtime: run sighandler on g0 stack on windows 2014-09-08 16:56:46 -04:00
sort build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
strconv build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
strings build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
sync build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
syscall syscall: keep allocated C string live across call to Syscall 2014-09-08 16:59:59 -04:00
testing build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
text build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
time build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
unicode build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
unsafe build: move package sources from src/pkg to src 2014-09-08 00:08:51 -04:00
all.bash build: make nacl pass 2014-05-20 12:10:19 -04:00
all.bat
all.rc
androidtest.bash androidtest.bash: adjustment for move from src/pkg to src 2014-09-08 10:07:26 -04:00
clean.bash
clean.bat
clean.rc
make.bash build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
make.bat build: fix windows make.bat 2014-09-07 07:31:53 -04:00
Make.dist
make.rc build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
nacltest.bash build: more adjustments for move from src/pkg to src 2014-09-08 00:22:40 -04:00
race.bash race.bash: support freebsd 2014-06-24 15:47:22 -07:00
race.bat
run.bash run.bash: run misc/cgo/testgodefs/test.bash 2014-08-12 07:13:52 -07:00
run.bat build: remove goplay from run.bash and run.bat 2014-06-02 08:44:47 +10:00
run.rc build: be verbose when running tests on Plan 9 2014-07-20 13:14:53 +03:00
sudo.bash