summaryrefslogtreecommitdiff
path: root/src/syscall/so_solaris.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-08 16:59:59 -0400
committerRuss Cox <rsc@golang.org>2014-09-08 16:59:59 -0400
commitcf68c86ed9b58d520f423ba7859ca78bbbeafe75 (patch)
tree1e9db0155e423a7b2c6380231aa033af41a38890 /src/syscall/so_solaris.go
parent13d89ea50fbfcf3ee71dba797c49e157453981b4 (diff)
downloadgo-cf68c86ed9b58d520f423ba7859ca78bbbeafe75.tar.gz
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://codereview.appspot.com/139360044
Diffstat (limited to 'src/syscall/so_solaris.go')
-rw-r--r--src/syscall/so_solaris.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/syscall/so_solaris.go b/src/syscall/so_solaris.go
index bf1b75604..8b1980fb4 100644
--- a/src/syscall/so_solaris.go
+++ b/src/syscall/so_solaris.go
@@ -39,6 +39,7 @@ func loadSO(name string) (*so, error) {
return nil, err
}
h, e := dlopen(namep, 1) // RTLD_LAZY
+ use(unsafe.Pointer(namep))
if e != 0 {
return nil, &soError{
Err: e,
@@ -70,6 +71,7 @@ func (d *so) FindProc(name string) (*proc, error) {
return nil, err
}
a, _ := dlsym(uintptr(d.Handle), namep)
+ use(unsafe.Pointer(namep))
if a == 0 {
return nil, &soError{
Err: ENOSYS,