summaryrefslogtreecommitdiff
path: root/src/syscall/zsyscall_linux_386.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/zsyscall_linux_386.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/zsyscall_linux_386.go')
-rw-r--r--src/syscall/zsyscall_linux_386.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/syscall/zsyscall_linux_386.go b/src/syscall/zsyscall_linux_386.go
index bfac41655..dee834313 100644
--- a/src/syscall/zsyscall_linux_386.go
+++ b/src/syscall/zsyscall_linux_386.go
@@ -14,6 +14,7 @@ func open(path string, mode int, perm uint32) (fd int, err error) {
return
}
r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
+ use(unsafe.Pointer(_p0))
fd = int(r0)
if e1 != 0 {
err = e1
@@ -30,6 +31,7 @@ func openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
return
}
r0, _, e1 := Syscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(flags), uintptr(mode), 0, 0)
+ use(unsafe.Pointer(_p0))
fd = int(r0)
if e1 != 0 {
err = e1
@@ -66,6 +68,7 @@ func utimes(path string, times *[2]Timeval) (err error) {
return
}
_, _, e1 := Syscall(SYS_UTIMES, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -81,6 +84,7 @@ func utimensat(dirfd int, path string, times *[2]Timespec) (err error) {
return
}
_, _, e1 := Syscall(SYS_UTIMENSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(times)))
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -144,6 +148,7 @@ func reboot(magic1 uint, magic2 uint, cmd int, arg string) (err error) {
return
}
_, _, e1 := Syscall6(SYS_REBOOT, uintptr(magic1), uintptr(magic2), uintptr(cmd), uintptr(unsafe.Pointer(_p0)), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -169,6 +174,9 @@ func mount(source string, target string, fstype string, flags uintptr, data *byt
return
}
_, _, e1 := Syscall6(SYS_MOUNT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(unsafe.Pointer(_p2)), uintptr(flags), uintptr(unsafe.Pointer(data)), 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
+ use(unsafe.Pointer(_p2))
if e1 != 0 {
err = e1
}
@@ -184,6 +192,7 @@ func Access(path string, mode uint32) (err error) {
return
}
_, _, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -199,6 +208,7 @@ func Acct(path string) (err error) {
return
}
_, _, e1 := Syscall(SYS_ACCT, uintptr(unsafe.Pointer(_p0)), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -225,6 +235,7 @@ func Chdir(path string) (err error) {
return
}
_, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -240,6 +251,7 @@ func Chmod(path string, mode uint32) (err error) {
return
}
_, _, e1 := Syscall(SYS_CHMOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -255,6 +267,7 @@ func Chroot(path string) (err error) {
return
}
_, _, e1 := Syscall(SYS_CHROOT, uintptr(unsafe.Pointer(_p0)), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -280,6 +293,7 @@ func Creat(path string, mode uint32) (fd int, err error) {
return
}
r0, _, e1 := Syscall(SYS_CREAT, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
+ use(unsafe.Pointer(_p0))
fd = int(r0)
if e1 != 0 {
err = e1
@@ -383,6 +397,7 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
return
}
_, _, e1 := Syscall6(SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -428,6 +443,7 @@ func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
return
}
_, _, e1 := Syscall6(SYS_FCHMODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(flags), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -443,6 +459,7 @@ func Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error) {
return
}
_, _, e1 := Syscall6(SYS_FCHOWNAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid), uintptr(flags), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -591,6 +608,8 @@ func Getxattr(path string, attr string, dest []byte) (sz int, err error) {
_p2 = unsafe.Pointer(&_zero)
}
r0, _, e1 := Syscall6(SYS_GETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(dest)), 0, 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
sz = int(r0)
if e1 != 0 {
err = e1
@@ -607,6 +626,7 @@ func InotifyAddWatch(fd int, pathname string, mask uint32) (watchdesc int, err e
return
}
r0, _, e1 := Syscall(SYS_INOTIFY_ADD_WATCH, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(mask))
+ use(unsafe.Pointer(_p0))
watchdesc = int(r0)
if e1 != 0 {
err = e1
@@ -688,6 +708,8 @@ func Link(oldpath string, newpath string) (err error) {
return
}
_, _, e1 := Syscall(SYS_LINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
if e1 != 0 {
err = e1
}
@@ -709,6 +731,7 @@ func Listxattr(path string, dest []byte) (sz int, err error) {
_p1 = unsafe.Pointer(&_zero)
}
r0, _, e1 := Syscall(SYS_LISTXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(dest)))
+ use(unsafe.Pointer(_p0))
sz = int(r0)
if e1 != 0 {
err = e1
@@ -725,6 +748,7 @@ func Mkdir(path string, mode uint32) (err error) {
return
}
_, _, e1 := Syscall(SYS_MKDIR, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -740,6 +764,7 @@ func Mkdirat(dirfd int, path string, mode uint32) (err error) {
return
}
_, _, e1 := Syscall(SYS_MKDIRAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode))
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -755,6 +780,7 @@ func Mknod(path string, mode uint32, dev int) (err error) {
return
}
_, _, e1 := Syscall(SYS_MKNOD, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev))
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -770,6 +796,7 @@ func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) {
return
}
_, _, e1 := Syscall6(SYS_MKNODAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(dev), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -810,6 +837,8 @@ func PivotRoot(newroot string, putold string) (err error) {
return
}
_, _, e1 := Syscall(SYS_PIVOT_ROOT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
if e1 != 0 {
err = e1
}
@@ -858,6 +887,7 @@ func Readlink(path string, buf []byte) (n int, err error) {
_p1 = unsafe.Pointer(&_zero)
}
r0, _, e1 := Syscall(SYS_READLINK, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(buf)))
+ use(unsafe.Pointer(_p0))
n = int(r0)
if e1 != 0 {
err = e1
@@ -879,6 +909,8 @@ func Removexattr(path string, attr string) (err error) {
return
}
_, _, e1 := Syscall(SYS_REMOVEXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
if e1 != 0 {
err = e1
}
@@ -899,6 +931,8 @@ func Rename(oldpath string, newpath string) (err error) {
return
}
_, _, e1 := Syscall(SYS_RENAME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
if e1 != 0 {
err = e1
}
@@ -919,6 +953,8 @@ func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err e
return
}
_, _, e1 := Syscall6(SYS_RENAMEAT, uintptr(olddirfd), uintptr(unsafe.Pointer(_p0)), uintptr(newdirfd), uintptr(unsafe.Pointer(_p1)), 0, 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
if e1 != 0 {
err = e1
}
@@ -934,6 +970,7 @@ func Rmdir(path string) (err error) {
return
}
_, _, e1 := Syscall(SYS_RMDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1033,6 +1070,8 @@ func Setxattr(path string, attr string, data []byte, flags int) (err error) {
_p2 = unsafe.Pointer(&_zero)
}
_, _, e1 := Syscall6(SYS_SETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(_p2), uintptr(len(data)), uintptr(flags), 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
if e1 != 0 {
err = e1
}
@@ -1053,6 +1092,8 @@ func Symlink(oldpath string, newpath string) (err error) {
return
}
_, _, e1 := Syscall(SYS_SYMLINK, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
+ use(unsafe.Pointer(_p0))
+ use(unsafe.Pointer(_p1))
if e1 != 0 {
err = e1
}
@@ -1135,6 +1176,7 @@ func Unlink(path string) (err error) {
return
}
_, _, e1 := Syscall(SYS_UNLINK, uintptr(unsafe.Pointer(_p0)), 0, 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1150,6 +1192,7 @@ func Unlinkat(dirfd int, path string) (err error) {
return
}
_, _, e1 := Syscall(SYS_UNLINKAT, uintptr(dirfd), uintptr(unsafe.Pointer(_p0)), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1165,6 +1208,7 @@ func Unmount(target string, flags int) (err error) {
return
}
_, _, e1 := Syscall(SYS_UMOUNT2, uintptr(unsafe.Pointer(_p0)), uintptr(flags), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1200,6 +1244,7 @@ func Utime(path string, buf *Utimbuf) (err error) {
return
}
_, _, e1 := Syscall(SYS_UTIME, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(buf)), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1358,6 +1403,7 @@ func Chown(path string, uid int, gid int) (err error) {
return
}
_, _, e1 := Syscall(SYS_CHOWN32, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid))
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1455,6 +1501,7 @@ func Lchown(path string, uid int, gid int) (err error) {
return
}
_, _, e1 := Syscall(SYS_LCHOWN32, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid))
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1470,6 +1517,7 @@ func Lstat(path string, stat *Stat_t) (err error) {
return
}
_, _, e1 := Syscall(SYS_LSTAT64, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1601,6 +1649,7 @@ func Stat(path string, stat *Stat_t) (err error) {
return
}
_, _, e1 := Syscall(SYS_STAT64, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0)
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}
@@ -1626,6 +1675,7 @@ func Truncate(path string, length int64) (err error) {
return
}
_, _, e1 := Syscall(SYS_TRUNCATE64, uintptr(unsafe.Pointer(_p0)), uintptr(length), uintptr(length>>32))
+ use(unsafe.Pointer(_p0))
if e1 != 0 {
err = e1
}