]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add pipe/pipe2 on Solaris
authorIan Lance Taylor <iant@golang.org>
Fri, 8 Nov 2019 05:04:53 +0000 (21:04 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 8 Nov 2019 19:28:57 +0000 (19:28 +0000)
This adds pipe/pipe2 on Solaris as they exist on other Unix systems.
They were not added previously because Solaris does not need them
for netpollBreak. They are added now in preparation for using pipes
in TestSignalM.

Updates #35276

Change-Id: I53dfdf077430153155f0a79715af98b0972a841c
Reviewed-on: https://go-review.googlesource.com/c/go/+/206077
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
14 files changed:
src/runtime/defs1_solaris_amd64.go
src/runtime/defs_solaris.go
src/runtime/export_solaris_test.go [moved from src/runtime/export_nbpipe_test.go with 50% similarity]
src/runtime/export_unix_test.go
src/runtime/nbpipe_fcntl_libc_test.go [moved from src/runtime/nbpipe_fcntl_aix_test.go with 76% similarity]
src/runtime/nbpipe_pipe2.go
src/runtime/nbpipe_test.go
src/runtime/os3_solaris.go
src/runtime/os_freebsd.go
src/runtime/os_linux.go
src/runtime/os_netbsd.go
src/runtime/os_openbsd.go
src/runtime/os_solaris.go
src/runtime/syscall_solaris.go

index ee6c45e5242b6d8b97313ceaef33c61767182643..19e8a2512e9df225d82b3366262fbb4b445d7391 100644 (file)
@@ -13,6 +13,7 @@ const (
        _ETIMEDOUT   = 0x91
        _EWOULDBLOCK = 0xb
        _EINPROGRESS = 0x96
+       _ENOSYS      = 0x59
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -91,6 +92,7 @@ const (
        _MAXHOSTNAMELEN = 0x100
 
        _O_NONBLOCK = 0x80
+       _O_CLOEXEC  = 0x800000
        _FD_CLOEXEC = 0x1
        _F_GETFL    = 0x3
        _F_SETFL    = 0x4
index f42adebee37202b0bb37304c8bc37e5d40cd362b..22df59094d7cb59e866b145954c022462c6737ed 100644 (file)
@@ -43,6 +43,7 @@ const (
        ETIMEDOUT   = C.ETIMEDOUT
        EWOULDBLOCK = C.EWOULDBLOCK
        EINPROGRESS = C.EINPROGRESS
+       ENOSYS      = C.ENOSYS
 
        PROT_NONE  = C.PROT_NONE
        PROT_READ  = C.PROT_READ
@@ -120,6 +121,7 @@ const (
        MAXHOSTNAMELEN = C.MAXHOSTNAMELEN
 
        O_NONBLOCK = C.O_NONBLOCK
+       O_CLOEXEC  = C.O_CLOEXEC
        FD_CLOEXEC = C.FD_CLOEXEC
        F_GETFL    = C.F_GETFL
        F_SETFL    = C.F_SETFL
similarity index 50%
rename from src/runtime/export_nbpipe_test.go
rename to src/runtime/export_solaris_test.go
index cf7863566a90f82c7324e32e8b6ca0f75b53ccd2..e865c77691e6bb2f90ed867040d40d4143abf04e 100644 (file)
@@ -2,11 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build aix darwin dragonfly freebsd linux netbsd openbsd
-
 package runtime
 
-var NonblockingPipe = nonblockingPipe
-var Pipe = pipe
-var SetNonblock = setNonblock
-var Closeonexec = closeonexec
+func Fcntl(fd, cmd, arg uintptr) (uintptr, uintptr) {
+       return sysvicall3Err(&libc_fcntl, fd, cmd, arg)
+}
index 5e59e406c687456d2b1720e144e395a4f973c236..375513337ee9526e7f14e073ad469fec9dc3de87 100644 (file)
@@ -6,6 +6,11 @@
 
 package runtime
 
+var NonblockingPipe = nonblockingPipe
+var Pipe = pipe
+var SetNonblock = setNonblock
+var Closeonexec = closeonexec
+
 func sigismember(mask *sigset, i int) bool {
        clear := *mask
        sigdelset(&clear, i)
similarity index 76%
rename from src/runtime/nbpipe_fcntl_aix_test.go
rename to src/runtime/nbpipe_fcntl_libc_test.go
index 4276ed5b531bfefde604a485e2a5260192113694..70f4b8348baa5880d5144c3d2a09a547b0b82977 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build aix solaris
+
 package runtime_test
 
 import (
@@ -9,8 +11,7 @@ import (
        "syscall"
 )
 
-// We can't call syscall.Syscall on AIX. Therefore, fcntl is exported from the
-// runtime in export_aix_test.go.
+// Call fcntl libc function rather than calling syscall.
 func fcntl(fd uintptr, cmd int, arg uintptr) (uintptr, syscall.Errno) {
        res, errno := runtime.Fcntl(fd, uintptr(cmd), arg)
        return res, syscall.Errno(errno)
index f4c862cbff94bdd53441e467c114b55cdc11a177..e3639d99b158ab5e565ce3b4312a7c4ed26b4e43 100644 (file)
@@ -2,13 +2,10 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build freebsd linux netbsd openbsd
+// +build freebsd linux netbsd openbsd solaris
 
 package runtime
 
-func pipe() (r, w int32, errno int32)
-func pipe2(flags int32) (r, w int32, errno int32)
-
 func nonblockingPipe() (r, w int32, errno int32) {
        r, w, errno = pipe2(_O_NONBLOCK | _O_CLOEXEC)
        if errno == -_ENOSYS {
index 00dc11e937b590e724675555024488700ffc68de..d739f57864aafc6f2d6e9242019df7519393b3b2 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build aix darwin dragonfly freebsd linux netbsd openbsd
+// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
 
 package runtime_test
 
index 373c682f05c6649dc5ffe951b0dac8bbcc31edbd..d6e36fbfbbe51fa7d57ce5e4eaf39e897204d9c7 100644 (file)
@@ -46,6 +46,8 @@ import (
 //go:cgo_import_dynamic libc_sysconf sysconf "libc.so"
 //go:cgo_import_dynamic libc_usleep usleep "libc.so"
 //go:cgo_import_dynamic libc_write write "libc.so"
+//go:cgo_import_dynamic libc_pipe pipe "libc.so"
+//go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so"
 
 //go:linkname libc____errno libc____errno
 //go:linkname libc_clock_gettime libc_clock_gettime
@@ -80,6 +82,8 @@ import (
 //go:linkname libc_sysconf libc_sysconf
 //go:linkname libc_usleep libc_usleep
 //go:linkname libc_write libc_write
+//go:linkname libc_pipe libc_pipe
+//go:linkname libc_pipe2 libc_pipe2
 
 var (
        libc____errno,
@@ -114,7 +118,9 @@ var (
        libc_sigprocmask,
        libc_sysconf,
        libc_usleep,
-       libc_write libcFunc
+       libc_write,
+       libc_pipe,
+       libc_pipe2 libcFunc
 )
 
 var sigset_all = sigset{[4]uint32{^uint32(0), ^uint32(0), ^uint32(0), ^uint32(0)}}
@@ -530,6 +536,31 @@ func write1(fd uintptr, buf unsafe.Pointer, nbyte int32) int32 {
        return -int32(err)
 }
 
+//go:nosplit
+func pipe() (r, w int32, errno int32) {
+       var p [2]int32
+       _, e := sysvicall1Err(&libc_pipe, uintptr(noescape(unsafe.Pointer(&p))))
+       return p[0], p[1], int32(e)
+}
+
+//go:nosplit
+func pipe2(flags int32) (r, w int32, errno int32) {
+       var p [2]int32
+       _, e := sysvicall2Err(&libc_pipe2, uintptr(noescape(unsafe.Pointer(&p))), uintptr(flags))
+       return p[0], p[1], int32(e)
+}
+
+//go:nosplit
+func closeonexec(fd int32) {
+       fcntl(fd, _F_SETFD, _FD_CLOEXEC)
+}
+
+//go:nosplit
+func setNonblock(fd int32) {
+       flags := fcntl(fd, _F_GETFL, 0)
+       fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
+}
+
 func osyield1()
 
 //go:nosplit
index 69e05b66a2842a531a2327056bed87afaa183c72..730973a20296fc3c85da49e4698694b96f59d658 100644 (file)
@@ -40,6 +40,9 @@ func kqueue() int32
 
 //go:noescape
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
+
+func pipe() (r, w int32, errno int32)
+func pipe2(flags int32) (r, w int32, errno int32)
 func closeonexec(fd int32)
 func setNonblock(fd int32)
 
index 20b947f2500bb938ecfcfb48145f710e3cac172e..27c66f7449ac8291d60338bafadc7f749cd39748 100644 (file)
@@ -374,6 +374,8 @@ func raiseproc(sig uint32)
 func sched_getaffinity(pid, len uintptr, buf *byte) int32
 func osyield()
 
+func pipe() (r, w int32, errno int32)
+func pipe2(flags int32) (r, w int32, errno int32)
 func setNonblock(fd int32)
 
 //go:nosplit
index b50cf237fb920e91c97b91a71ff1ef99a5d9c480..97106c7b9ddcf5c3b1691efd8e38da1a22a867fe 100644 (file)
@@ -71,6 +71,9 @@ func kqueue() int32
 
 //go:noescape
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
+
+func pipe() (r, w int32, errno int32)
+func pipe2(flags int32) (r, w int32, errno int32)
 func closeonexec(fd int32)
 func setNonblock(fd int32)
 
index f26b39575d37e0a84cb635684372dd432b510db9..b486b83688bc7d202e4c48c354d66b61687d59e8 100644 (file)
@@ -62,6 +62,9 @@ func kqueue() int32
 
 //go:noescape
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
+
+func pipe() (r, w int32, errno int32)
+func pipe2(flags int32) (r, w int32, errno int32)
 func closeonexec(fd int32)
 func setNonblock(fd int32)
 
index d6c09156bd55df564499ecc647c75b9e04a552cc..89129e5f1acfa164f55efae7ebc6e3a4bcda98f0 100644 (file)
@@ -63,6 +63,15 @@ func sysvicall0(fn *libcFunc) uintptr {
 
 //go:nosplit
 func sysvicall1(fn *libcFunc, a1 uintptr) uintptr {
+       r1, _ := sysvicall1Err(fn, a1)
+       return r1
+}
+
+//go:nosplit
+
+// sysvicall1Err returns both the system call result and the errno value.
+// This is used by sysvicall1 and pipe.
+func sysvicall1Err(fn *libcFunc, a1 uintptr) (r1, err uintptr) {
        // Leave caller's PC/SP around for traceback.
        gp := getg()
        var mp *m
@@ -88,11 +97,21 @@ func sysvicall1(fn *libcFunc, a1 uintptr) uintptr {
        if mp != nil {
                mp.libcallsp = 0
        }
-       return libcall.r1
+       return libcall.r1, libcall.err
 }
 
 //go:nosplit
 func sysvicall2(fn *libcFunc, a1, a2 uintptr) uintptr {
+       r1, _ := sysvicall2Err(fn, a1, a2)
+       return r1
+}
+
+//go:nosplit
+//go:cgo_unsafe_args
+
+// sysvicall2Err returns both the system call result and the errno value.
+// This is used by sysvicall2 and pipe2.
+func sysvicall2Err(fn *libcFunc, a1, a2 uintptr) (uintptr, uintptr) {
        // Leave caller's PC/SP around for traceback.
        gp := getg()
        var mp *m
@@ -117,7 +136,7 @@ func sysvicall2(fn *libcFunc, a1, a2 uintptr) uintptr {
        if mp != nil {
                mp.libcallsp = 0
        }
-       return libcall.r1
+       return libcall.r1, libcall.err
 }
 
 //go:nosplit
index 35381801c55b808e6aa512bdecf6291106625fbd..76db54d274aca8d365f4ceb0cba6e30b2f7e2ec0 100644 (file)
@@ -16,7 +16,6 @@ var (
        libc_gethostname,
        libc_getpid,
        libc_ioctl,
-       libc_pipe,
        libc_setgid,
        libc_setgroups,
        libc_setsid,