mirror of
https://github.com/golang/go
synced 2024-11-19 01:44:40 -07:00
cf622d758c
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
293 lines
6.4 KiB
Go
293 lines
6.4 KiB
Go
// mksyscall.pl -l32 -plan9 syscall_plan9.go
|
|
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
|
|
|
package syscall
|
|
|
|
import "unsafe"
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func fd2path(fd int, buf []byte) (err error) {
|
|
var _p0 unsafe.Pointer
|
|
if len(buf) > 0 {
|
|
_p0 = unsafe.Pointer(&buf[0])
|
|
} else {
|
|
_p0 = unsafe.Pointer(&_zero)
|
|
}
|
|
r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func pipe(p *[2]_C_int) (err error) {
|
|
r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func await(s []byte) (n int, err error) {
|
|
var _p0 unsafe.Pointer
|
|
if len(s) > 0 {
|
|
_p0 = unsafe.Pointer(&s[0])
|
|
} else {
|
|
_p0 = unsafe.Pointer(&_zero)
|
|
}
|
|
r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
|
|
n = int(r0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Dup(oldfd int, newfd int) (fd int, err error) {
|
|
r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
|
|
fd = int(r0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Open(path string, mode int) (fd int, err error) {
|
|
var _p0 *byte
|
|
_p0, err = BytePtrFromString(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
|
|
use(unsafe.Pointer(_p0))
|
|
fd = int(r0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Create(path string, mode int, perm uint32) (fd int, err error) {
|
|
var _p0 *byte
|
|
_p0, err = BytePtrFromString(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
|
|
use(unsafe.Pointer(_p0))
|
|
fd = int(r0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Remove(path string) (err error) {
|
|
var _p0 *byte
|
|
_p0, err = BytePtrFromString(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
|
use(unsafe.Pointer(_p0))
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Pread(fd int, p []byte, offset int64) (n int, err error) {
|
|
var _p0 unsafe.Pointer
|
|
if len(p) > 0 {
|
|
_p0 = unsafe.Pointer(&p[0])
|
|
} else {
|
|
_p0 = unsafe.Pointer(&_zero)
|
|
}
|
|
r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
|
|
n = int(r0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
|
|
var _p0 unsafe.Pointer
|
|
if len(p) > 0 {
|
|
_p0 = unsafe.Pointer(&p[0])
|
|
} else {
|
|
_p0 = unsafe.Pointer(&_zero)
|
|
}
|
|
r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
|
|
n = int(r0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Close(fd int) (err error) {
|
|
r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Chdir(path string) (err error) {
|
|
var _p0 *byte
|
|
_p0, err = BytePtrFromString(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
|
|
use(unsafe.Pointer(_p0))
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Bind(name string, old string, flag int) (err error) {
|
|
var _p0 *byte
|
|
_p0, err = BytePtrFromString(name)
|
|
if err != nil {
|
|
return
|
|
}
|
|
var _p1 *byte
|
|
_p1, err = BytePtrFromString(old)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
|
|
use(unsafe.Pointer(_p0))
|
|
use(unsafe.Pointer(_p1))
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Mount(fd int, afd int, old string, flag int, aname string) (err error) {
|
|
var _p0 *byte
|
|
_p0, err = BytePtrFromString(old)
|
|
if err != nil {
|
|
return
|
|
}
|
|
var _p1 *byte
|
|
_p1, err = BytePtrFromString(aname)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
|
|
use(unsafe.Pointer(_p0))
|
|
use(unsafe.Pointer(_p1))
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Stat(path string, edir []byte) (n int, err error) {
|
|
var _p0 *byte
|
|
_p0, err = BytePtrFromString(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
var _p1 unsafe.Pointer
|
|
if len(edir) > 0 {
|
|
_p1 = unsafe.Pointer(&edir[0])
|
|
} else {
|
|
_p1 = unsafe.Pointer(&_zero)
|
|
}
|
|
r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
|
|
use(unsafe.Pointer(_p0))
|
|
n = int(r0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Fstat(fd int, edir []byte) (n int, err error) {
|
|
var _p0 unsafe.Pointer
|
|
if len(edir) > 0 {
|
|
_p0 = unsafe.Pointer(&edir[0])
|
|
} else {
|
|
_p0 = unsafe.Pointer(&_zero)
|
|
}
|
|
r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
|
|
n = int(r0)
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Wstat(path string, edir []byte) (err error) {
|
|
var _p0 *byte
|
|
_p0, err = BytePtrFromString(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
var _p1 unsafe.Pointer
|
|
if len(edir) > 0 {
|
|
_p1 = unsafe.Pointer(&edir[0])
|
|
} else {
|
|
_p1 = unsafe.Pointer(&_zero)
|
|
}
|
|
r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
|
|
use(unsafe.Pointer(_p0))
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|
|
|
|
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
|
|
|
func Fwstat(fd int, edir []byte) (err error) {
|
|
var _p0 unsafe.Pointer
|
|
if len(edir) > 0 {
|
|
_p0 = unsafe.Pointer(&edir[0])
|
|
} else {
|
|
_p0 = unsafe.Pointer(&_zero)
|
|
}
|
|
r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
|
|
if int32(r0) == -1 {
|
|
err = e1
|
|
}
|
|
return
|
|
}
|