Commit f335fcf0 authored by Shenghou Ma's avatar Shenghou Ma Committed by Brad Fitzpatrick

syscall: add Getexecname on Solaris for os.Executable

Change-Id: Icd77ccbfe6a31117a11effb949b5826950df75a9
Reviewed-on: https://go-review.googlesource.com/16550Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a9ce0f96
......@@ -509,6 +509,21 @@ func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error)
//sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) = libsocket.setsockopt
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) = libsocket.recvfrom
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) = libsocket.__xnet_recvmsg
//sys getexecname() (path unsafe.Pointer, err error) = libc.getexecname
func Getexecname() (path string, err error) {
ptr, err := getexecname()
if err != nil {
return "", err
}
bytes := (*[1 << 29]byte)(ptr)[:]
for i, b := range bytes {
if b == 0 {
return string(bytes[:i]), nil
}
}
panic("unreachable")
}
func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_read)), 3, uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf), 0, 0, 0)
......
......@@ -89,6 +89,7 @@ import "unsafe"
//go:cgo_import_dynamic libc_setsockopt setsockopt "libsocket.so"
//go:cgo_import_dynamic libc_recvfrom recvfrom "libsocket.so"
//go:cgo_import_dynamic libc___xnet_recvmsg __xnet_recvmsg "libsocket.so"
//go:cgo_import_dynamic libc_getexecname getexecname "libc.so"
//go:linkname libc_Getcwd libc_Getcwd
//go:linkname libc_getgroups libc_getgroups
......@@ -172,6 +173,7 @@ import "unsafe"
//go:linkname libc_setsockopt libc_setsockopt
//go:linkname libc_recvfrom libc_recvfrom
//go:linkname libc___xnet_recvmsg libc___xnet_recvmsg
//go:linkname libc_getexecname libc_getexecname
type libcFunc uintptr
......@@ -257,7 +259,8 @@ var (
libc_getsockname,
libc_setsockopt,
libc_recvfrom,
libc___xnet_recvmsg libcFunc
libc___xnet_recvmsg,
libc_getexecname libcFunc
)
func Getcwd(buf []byte) (n int, err error) {
......@@ -1095,3 +1098,12 @@ func recvmsg(s int, msg *Msghdr, flags int) (n int, err error) {
}
return
}
func getexecname() (path unsafe.Pointer, err error) {
r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_getexecname)), 0, 0, 0, 0, 0, 0, 0)
path = unsafe.Pointer(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment