]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: define nonblockingPipe
authorIan Lance Taylor <iant@golang.org>
Wed, 3 Apr 2019 23:31:13 +0000 (16:31 -0700)
committerIan Lance Taylor <iant@golang.org>
Sun, 20 Oct 2019 21:15:55 +0000 (21:15 +0000)
This requires defining pipe, pipe2, and setNonblock for various platforms.

The new function is currently only used on AIX. It will be used by
later CLs in this series.

Updates #27707

Change-Id: Id2f987b66b4c66a3ef40c22484ff1d14f58e9b31
Reviewed-on: https://go-review.googlesource.com/c/go/+/171822
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
59 files changed:
src/runtime/defs1_linux.go
src/runtime/defs1_netbsd_386.go
src/runtime/defs1_netbsd_amd64.go
src/runtime/defs1_netbsd_arm.go
src/runtime/defs1_netbsd_arm64.go
src/runtime/defs_aix.go
src/runtime/defs_aix_ppc64.go
src/runtime/defs_freebsd.go
src/runtime/defs_freebsd_386.go
src/runtime/defs_freebsd_amd64.go
src/runtime/defs_freebsd_arm.go
src/runtime/defs_linux.go
src/runtime/defs_linux_386.go
src/runtime/defs_linux_amd64.go
src/runtime/defs_linux_arm.go
src/runtime/defs_linux_arm64.go
src/runtime/defs_linux_mips64x.go
src/runtime/defs_linux_mipsx.go
src/runtime/defs_linux_ppc64.go
src/runtime/defs_linux_ppc64le.go
src/runtime/defs_linux_s390x.go
src/runtime/defs_netbsd.go
src/runtime/defs_openbsd.go
src/runtime/defs_openbsd_386.go
src/runtime/defs_openbsd_amd64.go
src/runtime/defs_openbsd_arm.go
src/runtime/defs_openbsd_arm64.go
src/runtime/export_nbpipe_test.go [new file with mode: 0644]
src/runtime/nbpipe_pipe.go [new file with mode: 0644]
src/runtime/nbpipe_pipe2.go [new file with mode: 0644]
src/runtime/nbpipe_test.go [new file with mode: 0644]
src/runtime/netpoll_aix.go
src/runtime/os2_aix.go
src/runtime/os_aix.go
src/runtime/os_dragonfly.go
src/runtime/os_freebsd.go
src/runtime/os_linux.go
src/runtime/os_netbsd.go
src/runtime/os_openbsd.go
src/runtime/sys_dragonfly_amd64.s
src/runtime/sys_freebsd_386.s
src/runtime/sys_freebsd_amd64.s
src/runtime/sys_freebsd_arm.s
src/runtime/sys_linux_386.s
src/runtime/sys_linux_amd64.s
src/runtime/sys_linux_arm.s
src/runtime/sys_linux_arm64.s
src/runtime/sys_linux_mips64x.s
src/runtime/sys_linux_mipsx.s
src/runtime/sys_linux_ppc64x.s
src/runtime/sys_linux_s390x.s
src/runtime/sys_netbsd_386.s
src/runtime/sys_netbsd_amd64.s
src/runtime/sys_netbsd_arm.s
src/runtime/sys_netbsd_arm64.s
src/runtime/sys_openbsd_386.s
src/runtime/sys_openbsd_amd64.s
src/runtime/sys_openbsd_arm.s
src/runtime/sys_openbsd_arm64.s

index e136d96e78dacdcb55fea6a333aa2113727de32a..4085d6f41827cfba50345969e60e51c984d2bb0f 100644 (file)
@@ -21,6 +21,7 @@ import "C"
 
 const (
        O_RDONLY    = C.O_RDONLY
+       O_NONBLOCK  = C.O_NONBLOCK
        O_CLOEXEC   = C.O_CLOEXEC
        SA_RESTORER = C.SA_RESTORER
 )
index 3eae12eed0ef6c67206b7300b711eeddf52387fa..da48cc84c27dd80fe7994a178a4340650e305f1e 100644 (file)
@@ -6,6 +6,10 @@ package runtime
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x400000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index 51d55c91f935ee966180db224f8123f540c6aa9f..0b25b8da7c44514452452d7eb7ebfa0101ad1b57 100644 (file)
@@ -6,6 +6,10 @@ package runtime
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x400000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index fadb3415b33f3cd29cec496825fd7118ff81b8f7..4738b546d17f0ed49acdc2db11416959e2c9d1fb 100644 (file)
@@ -6,6 +6,10 @@ package runtime
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x400000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index 41b7aaca6cc1ff51e184c9c7e51137394727c9b0..14c07d17040db2ecf0c1abbd47e5d8a31b7ecbfb 100644 (file)
@@ -6,6 +6,10 @@ package runtime
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x400000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index bc5101f35d0d49553667077f2f2f93dc803f12bc..a8924133c51c9d490e915c27115081ee93c9bc28 100644 (file)
@@ -123,7 +123,8 @@ const (
        _ITIMER_VIRTUAL = C.ITIMER_VIRTUAL
        _ITIMER_PROF    = C.ITIMER_PROF
 
-       _O_RDONLY = C.O_RDONLY
+       _O_RDONLY   = C.O_RDONLY
+       _O_NONBLOCK = C.O_NONBLOCK
 
        _SS_DISABLE  = C.SS_DISABLE
        _SI_USER     = C.SI_USER
index dccc3a5926490da5902741c35fe4d45c49966c9b..a53fcc59336381644592a52de320c22e558897f8 100644 (file)
@@ -80,7 +80,8 @@ const (
        _ITIMER_VIRTUAL = 0x1
        _ITIMER_PROF    = 0x2
 
-       _O_RDONLY = 0x0
+       _O_RDONLY   = 0x0
+       _O_NONBLOCK = 0x4
 
        _SS_DISABLE  = 0x2
        _SI_USER     = 0x0
index 53c1508eb798faf67be4e2f5fa0c1e1b11a18d53..700e06eb8094d7a0dd68a1f4c49f4184ca07f541 100644 (file)
@@ -47,6 +47,10 @@ const (
 const (
        EINTR  = C.EINTR
        EFAULT = C.EFAULT
+       ENOSYS = C.ENOSYS
+
+       O_NONBLOCK = C.O_NONBLOCK
+       O_CLOEXEC  = C.O_CLOEXEC
 
        PROT_NONE  = C.PROT_NONE
        PROT_READ  = C.PROT_READ
index c4d5c897d3ea980a35cfa88b5181476170db02cc..c113eee34c87503495fb848da66df974eee5eda4 100644 (file)
@@ -15,6 +15,10 @@ const (
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x100000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index 89d36c270db8d99d401e7efc711a816bd9f09caf..9105cc392b1bb6c938095594cfb7aeb6fb9718f1 100644 (file)
@@ -15,6 +15,10 @@ const (
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x100000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index cc8c924c3710a300d7097c1738440a8a4f7f8c1a..cf7ca696f4f7ddb0b0f032eb7f03819e90cda3c8 100644 (file)
@@ -15,6 +15,10 @@ const (
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x100000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index 2d810136d987133e71eaf75eaa602fae9cc0039f..5b46cb42a2ee3286d43646c70a7c427043fd697f 100644 (file)
@@ -37,6 +37,7 @@ const (
        EINTR  = C.EINTR
        EAGAIN = C.EAGAIN
        ENOMEM = C.ENOMEM
+       ENOSYS = C.ENOSYS
 
        PROT_NONE  = C.PROT_NONE
        PROT_READ  = C.PROT_READ
index e2fcbcac7187a5a232441e5727edb8399c933593..ba349845cfd3d66d5b5e973825e1350c07b584c7 100644 (file)
@@ -7,6 +7,7 @@ const (
        _EINTR  = 0x4
        _EAGAIN = 0xb
        _ENOMEM = 0xc
+       _ENOSYS = 0x26
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -78,8 +79,9 @@ const (
        _ITIMER_VIRTUAL = 0x1
        _ITIMER_PROF    = 0x2
 
-       _O_RDONLY  = 0x0
-       _O_CLOEXEC = 0x80000
+       _O_RDONLY   = 0x0
+       _O_NONBLOCK = 0x800
+       _O_CLOEXEC  = 0x80000
 
        _EPOLLIN       = 0x1
        _EPOLLOUT      = 0x4
index ddad7fddd442e63b5bc3d6ff7c28027c3d89736d..9eb5646ca32d239a390a8a18bc5d3f64b14173bb 100644 (file)
@@ -7,6 +7,7 @@ const (
        _EINTR  = 0x4
        _EAGAIN = 0xb
        _ENOMEM = 0xc
+       _ENOSYS = 0x26
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -143,8 +144,9 @@ type epollevent struct {
 // cgo -cdefs defs_linux.go defs1_linux.go
 
 const (
-       _O_RDONLY  = 0x0
-       _O_CLOEXEC = 0x80000
+       _O_RDONLY   = 0x0
+       _O_NONBLOCK = 0x800
+       _O_CLOEXEC  = 0x80000
 )
 
 type usigset struct {
index 9d10d664e1703c78b2b6c659c06d33c29b90801f..d24e0a9d6e66f6a5193e60de5f87f4542deda6d6 100644 (file)
@@ -5,6 +5,7 @@ const (
        _EINTR  = 0x4
        _ENOMEM = 0xc
        _EAGAIN = 0xb
+       _ENOSYS = 0x26
 
        _PROT_NONE  = 0
        _PROT_READ  = 0x1
@@ -71,6 +72,7 @@ const (
        _ITIMER_PROF    = 0x2
        _ITIMER_VIRTUAL = 0x1
        _O_RDONLY       = 0
+       _O_NONBLOCK     = 0x800
        _O_CLOEXEC      = 0x80000
 
        _EPOLLIN       = 0x1
index b325a229a1d990df5873f05e20e9c29459ea5531..182887d8d5ea837e0de0b6ff8abea84f431a4521 100644 (file)
@@ -7,6 +7,7 @@ const (
        _EINTR  = 0x4
        _EAGAIN = 0xb
        _ENOMEM = 0xc
+       _ENOSYS = 0x26
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -144,8 +145,9 @@ type epollevent struct {
 // ../cmd/cgo/cgo -cdefs defs_linux.go defs1_linux.go defs2_linux.go
 
 const (
-       _O_RDONLY  = 0x0
-       _O_CLOEXEC = 0x80000
+       _O_RDONLY   = 0x0
+       _O_NONBLOCK = 0x800
+       _O_CLOEXEC  = 0x80000
 )
 
 type usigset struct {
index a52d0d40cf249788e43d548790e6659310c0248a..0fb53d573703c83749eca5035af3b2f0572c4fb2 100644 (file)
@@ -7,6 +7,7 @@ const (
        _EINTR  = 0x4
        _EAGAIN = 0xb
        _ENOMEM = 0xc
+       _ENOSYS = 0x59
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -145,6 +146,7 @@ type epollevent struct {
 
 const (
        _O_RDONLY    = 0x0
+       _O_NONBLOCK  = 0x80
        _O_CLOEXEC   = 0x80000
        _SA_RESTORER = 0
 )
index f3a1dd0cf0d7acfb09d89686d48da67af1f5d702..9315ba9346a41f5543cb09ce9f9760bc811364de 100644 (file)
@@ -11,6 +11,7 @@ const (
        _EINTR  = 0x4
        _EAGAIN = 0xb
        _ENOMEM = 0xc
+       _ENOSYS = 0x59
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -143,6 +144,7 @@ type epollevent struct {
 
 const (
        _O_RDONLY    = 0x0
+       _O_NONBLOCK  = 0x80
        _O_CLOEXEC   = 0x80000
        _SA_RESTORER = 0
 )
index f438993721728e8c64d9ff34e13c14d3c75ea08e..90b1dc1ff9d84edc4143b8793331c992965e9720 100644 (file)
@@ -7,6 +7,7 @@ const (
        _EINTR  = 0x4
        _EAGAIN = 0xb
        _ENOMEM = 0xc
+       _ENOSYS = 0x26
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -145,6 +146,7 @@ type epollevent struct {
 
 const (
        _O_RDONLY    = 0x0
+       _O_NONBLOCK  = 0x800
        _O_CLOEXEC   = 0x80000
        _SA_RESTORER = 0
 )
index f438993721728e8c64d9ff34e13c14d3c75ea08e..90b1dc1ff9d84edc4143b8793331c992965e9720 100644 (file)
@@ -7,6 +7,7 @@ const (
        _EINTR  = 0x4
        _EAGAIN = 0xb
        _ENOMEM = 0xc
+       _ENOSYS = 0x26
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -145,6 +146,7 @@ type epollevent struct {
 
 const (
        _O_RDONLY    = 0x0
+       _O_NONBLOCK  = 0x800
        _O_CLOEXEC   = 0x80000
        _SA_RESTORER = 0
 )
index 19b99b5bdfb8c707d44e7b01b6f298d94b38a8fb..fa289d531c074bbef57c54892d64c5082daa8889 100644 (file)
@@ -8,6 +8,7 @@ const (
        _EINTR  = 0x4
        _EAGAIN = 0xb
        _ENOMEM = 0xc
+       _ENOSYS = 0x26
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
@@ -138,6 +139,7 @@ type epollevent struct {
 
 const (
        _O_RDONLY    = 0x0
+       _O_NONBLOCK  = 0x800
        _O_CLOEXEC   = 0x80000
        _SA_RESTORER = 0
 )
index 41aa07af98ef14dfc0646506624155ae73b81ae0..40eeb8c70f0fdca01017a8bf55af06ca2550a70a 100644 (file)
@@ -32,6 +32,10 @@ import "C"
 const (
        EINTR  = C.EINTR
        EFAULT = C.EFAULT
+       ENOSYS = C.ENOSYS
+
+       O_NONBLOCK = C.O_NONBLOCK
+       O_CLOEXEC  = C.O_CLOEXEC
 
        PROT_NONE  = C.PROT_NONE
        PROT_READ  = C.PROT_READ
index a328d25db3e0d8f1f6ebf96882b58d0e6ccf1c3f..c425864b214fb3dfc65c10851c86762093a37bf5 100644 (file)
@@ -28,6 +28,10 @@ import "C"
 const (
        EINTR  = C.EINTR
        EFAULT = C.EFAULT
+       ENOSYS = C.ENOSYS
+
+       O_NONBLOCK = C.O_NONBLOCK
+       O_CLOEXEC  = C.O_CLOEXEC
 
        PROT_NONE  = C.PROT_NONE
        PROT_READ  = C.PROT_READ
index 0e59a0591a76815edca39d3941e36ad44afe0c32..0c89bf28ccf6398977f734eb70032411f651dce1 100644 (file)
@@ -8,6 +8,10 @@ import "unsafe"
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x10000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index 5cefac5858a606f1ccc6ec82b7dbdbf475cf5343..8d3523bf98cc6d0c607e73a7adf9ab201f008b95 100644 (file)
@@ -8,6 +8,10 @@ import "unsafe"
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x10000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index b187e9776f56c9eda0ce56d8c6699718b34d4c1f..8f5a5d6e9de16a7b6e813cff72cfb40667fb68e2 100644 (file)
@@ -8,6 +8,10 @@ import "unsafe"
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x10000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
index 6b9d60110ab15ea78ef3358442f546e47f398af8..c4ddefbd74d4e65c9186d5c2caa6cf64a8b42977 100644 (file)
@@ -5,6 +5,10 @@ import "unsafe"
 const (
        _EINTR  = 0x4
        _EFAULT = 0xe
+       _ENOSYS = 0x4e
+
+       _O_NONBLOCK = 0x4
+       _O_CLOEXEC  = 0x10000
 
        _PROT_NONE  = 0x0
        _PROT_READ  = 0x1
diff --git a/src/runtime/export_nbpipe_test.go b/src/runtime/export_nbpipe_test.go
new file mode 100644 (file)
index 0000000..cf78635
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// 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
diff --git a/src/runtime/nbpipe_pipe.go b/src/runtime/nbpipe_pipe.go
new file mode 100644 (file)
index 0000000..822b294
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build aix darwin dragonfly
+
+package runtime
+
+func nonblockingPipe() (r, w int32, errno int32) {
+       r, w, errno = pipe()
+       if errno != 0 {
+               return -1, -1, errno
+       }
+       closeonexec(r)
+       setNonblock(r)
+       closeonexec(w)
+       setNonblock(w)
+       return r, w, errno
+}
diff --git a/src/runtime/nbpipe_pipe2.go b/src/runtime/nbpipe_pipe2.go
new file mode 100644 (file)
index 0000000..f4c862c
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// 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
+
+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 {
+               r, w, errno = pipe()
+               if errno != 0 {
+                       return -1, -1, errno
+               }
+               closeonexec(r)
+               setNonblock(r)
+               closeonexec(w)
+               setNonblock(w)
+       }
+       return r, w, errno
+}
diff --git a/src/runtime/nbpipe_test.go b/src/runtime/nbpipe_test.go
new file mode 100644 (file)
index 0000000..bd0d578
--- /dev/null
@@ -0,0 +1,93 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// 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_test
+
+import (
+       "runtime"
+       "syscall"
+       "testing"
+       "unsafe"
+)
+
+func TestNonblockingPipe(t *testing.T) {
+       t.Parallel()
+
+       // NonblockingPipe is the test name for nonblockingPipe.
+       r, w, errno := runtime.NonblockingPipe()
+       if errno != 0 {
+               t.Fatal(syscall.Errno(errno))
+       }
+       defer func() {
+               runtime.Close(r)
+               runtime.Close(w)
+       }()
+
+       checkIsPipe(t, r, w)
+       checkNonblocking(t, r, "reader")
+       checkCloseonexec(t, r, "reader")
+       checkNonblocking(t, w, "writer")
+       checkCloseonexec(t, w, "writer")
+}
+
+func checkIsPipe(t *testing.T, r, w int32) {
+       bw := byte(42)
+       if n := runtime.Write(uintptr(w), unsafe.Pointer(&bw), 1); n != 1 {
+               t.Fatalf("Write(w, &b, 1) == %d, expected 1", n)
+       }
+       var br byte
+       if n := runtime.Read(r, unsafe.Pointer(&br), 1); n != 1 {
+               t.Fatalf("Read(r, &b, 1) == %d, expected 1", n)
+       }
+       if br != bw {
+               t.Errorf("pipe read %d, expected %d", br, bw)
+       }
+}
+
+func checkNonblocking(t *testing.T, fd int32, name string) {
+       t.Helper()
+       flags, _, errno := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), syscall.F_GETFL, 0)
+       if errno != 0 {
+               t.Errorf("fcntl(%s, F_GETFL) failed: %v", name, syscall.Errno(errno))
+       } else if flags&syscall.O_NONBLOCK == 0 {
+               t.Errorf("O_NONBLOCK not set in %s flags %#x", name, flags)
+       }
+}
+
+func checkCloseonexec(t *testing.T, fd int32, name string) {
+       t.Helper()
+       flags, _, errno := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), syscall.F_GETFD, 0)
+       if errno != 0 {
+               t.Errorf("fcntl(%s, F_GETFD) failed: %v", name, syscall.Errno(errno))
+       } else if flags&syscall.FD_CLOEXEC == 0 {
+               t.Errorf("FD_CLOEXEC not set in %s flags %#x", name, flags)
+       }
+}
+
+func TestSetNonblock(t *testing.T) {
+       t.Parallel()
+
+       r, w, errno := runtime.Pipe()
+       if errno != 0 {
+               t.Fatal(syscall.Errno(errno))
+       }
+       defer func() {
+               runtime.Close(r)
+               runtime.Close(w)
+       }()
+
+       checkIsPipe(t, r, w)
+
+       runtime.SetNonblock(r)
+       runtime.SetNonblock(w)
+       checkNonblocking(t, r, "reader")
+       checkNonblocking(t, w, "writer")
+
+       runtime.Closeonexec(r)
+       runtime.Closeonexec(w)
+       checkCloseonexec(t, r, "reader")
+       checkCloseonexec(t, w, "writer")
+}
index 08a9e42dd2e075ea22974b4526b5fff3d555283c..6feda27b80577b8318bcc05fd4013f94e27d1cb1 100644 (file)
@@ -21,12 +21,6 @@ func poll(pfds *pollfd, npfds uintptr, timeout uintptr) (int32, int32) {
        return int32(r), int32(err)
 }
 
-//go:nosplit
-func fcntl(fd, cmd int32, arg uintptr) int32 {
-       r, _ := syscall3(&libc_fcntl, uintptr(fd), uintptr(cmd), arg)
-       return int32(r)
-}
-
 // pollfd represents the poll structure for AIX operating system.
 type pollfd struct {
        fd      int32
@@ -38,7 +32,6 @@ const _POLLIN = 0x0001
 const _POLLOUT = 0x0002
 const _POLLHUP = 0x2000
 const _POLLERR = 0x4000
-const _O_NONBLOCK = 0x4
 
 var (
        pfds           []pollfd
@@ -51,22 +44,13 @@ var (
 )
 
 func netpollinit() {
-       var p [2]int32
-
        // Create the pipe we use to wakeup poll.
-       if err := pipe(&p[0]); err < 0 {
+       r, w, errno := nonblockingPipe()
+       if errno != 0 {
                throw("netpollinit: failed to create pipe")
        }
-       rdwake = p[0]
-       wrwake = p[1]
-
-       fl := uintptr(fcntl(rdwake, _F_GETFL, 0))
-       fcntl(rdwake, _F_SETFL, fl|_O_NONBLOCK)
-       fcntl(rdwake, _F_SETFD, _FD_CLOEXEC)
-
-       fl = uintptr(fcntl(wrwake, _F_GETFL, 0))
-       fcntl(wrwake, _F_SETFL, fl|_O_NONBLOCK)
-       fcntl(wrwake, _F_SETFD, _FD_CLOEXEC)
+       rdwake = r
+       wrwake = w
 
        // Pre-allocate array of pollfd structures for poll.
        pfds = make([]pollfd, 1, 128)
index b79fa08dc2ff691d26a2be08812ab0787c28ad01..9f5c185bacd7a414f91443f611461c81a7b14d61 100644 (file)
@@ -425,9 +425,10 @@ func closefd(fd int32) int32 {
 }
 
 //go:nosplit
-func pipe(fd *int32) int32 {
-       r, _ := syscall1(&libc_pipe, uintptr(unsafe.Pointer(fd)))
-       return int32(r)
+func pipe() (r, w int32, errno int32) {
+       var p [2]int32
+       _, err := syscall1(&libc_pipe, uintptr(noescape(unsafe.Pointer(&p[0]))))
+       return p[0], p[1], int32(err)
 }
 
 // mmap calls the mmap system call.
index 84d86e5ff1207979d0b2fec30887cad6ce8748ad..855ae6ff469328299466fd81004b4f76d2ea6792 100644 (file)
@@ -357,3 +357,20 @@ func setupSystemConf() {
                cpu.HWCap2 |= cpu.PPC_FEATURE2_ARCH_3_00
        }
 }
+
+//go:nosplit
+func fcntl(fd, cmd int32, arg uintptr) int32 {
+       r, _ := syscall3(&libc_fcntl, uintptr(fd), uintptr(cmd), arg)
+       return int32(r)
+}
+
+//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, uintptr(flags|_O_NONBLOCK))
+}
index 4fda7ea8060a467e1355384d99454f50c052307a..3266b2623a5eecffd19a94a7f8d2ae946767f71b 100644 (file)
@@ -54,6 +54,9 @@ func kqueue() int32
 //go:noescape
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
 func closeonexec(fd int32)
+func setNonblock(fd int32)
+
+func pipe() (r, w int32, errno int32)
 
 const stackSystem = 0
 
index cbb72cf55e66472833c03f1f0e6c2c267d532351..183d8ab9c7c72f4ed84367e05749ea5184a2e50a 100644 (file)
@@ -39,6 +39,7 @@ func kqueue() int32
 //go:noescape
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
 func closeonexec(fd int32)
+func setNonblock(fd int32)
 
 // From FreeBSD's <sys/sysctl.h>
 const (
index d4a9bd4ff5f4c274ab761cfc83af961bdc023aff..b1ddf53dd1d2a1bec36b74b768dc011d17121a63 100644 (file)
@@ -372,6 +372,8 @@ func raiseproc(sig uint32)
 func sched_getaffinity(pid, len uintptr, buf *byte) int32
 func osyield()
 
+func setNonblock(fd int32)
+
 //go:nosplit
 //go:nowritebarrierrec
 func setsig(i uint32, fn uintptr) {
index da024cd309b302904ef7f1ad9a819117e1294657..17742207661497788b74a43a330880af5ba33c2d 100644 (file)
@@ -73,6 +73,7 @@ func kqueue() int32
 //go:noescape
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
 func closeonexec(fd int32)
+func setNonblock(fd int32)
 
 const (
        _ESRCH     = 3
index 2d6334ec8631e69b5266d87955c72d909d693bb6..be887a549d7a4fdb4608e7a5a1bd64ec2f63c205 100644 (file)
@@ -61,6 +61,7 @@ func kqueue() int32
 //go:noescape
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
 func closeonexec(fd int32)
+func setNonblock(fd int32)
 
 const (
        _ESRCH       = 3
index ab9ca3795ff6d820ca511efcb58b91e74372d7df..b3f9f1eb01885ce19801f7ab8fca20a065ae1020 100644 (file)
@@ -108,6 +108,21 @@ TEXT runtime·read(SB),NOSPLIT,$-8
        MOVL    AX, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVL    $42, AX
+       SYSCALL
+       JCC     pipeok
+       MOVL    $-1,r+0(FP)
+       MOVL    $-1,w+4(FP)
+       MOVL    AX, errno+8(FP)
+       RET
+pipeok:
+       MOVL    AX, r+0(FP)
+       MOVL    DX, w+4(FP)
+       MOVL    $0, errno+8(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT,$-8
        MOVQ    fd+0(FP), DI            // arg 1 fd
        MOVQ    p+8(FP), SI             // arg 2 buf
@@ -371,3 +386,18 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVL    $92, AX         // fcntl
        SYSCALL
        RET
+
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVL    fd+0(FP), DI  // fd
+       MOVQ    $3, SI  // F_GETFL
+       MOVQ    $0, DX
+       MOVL    $92, AX // fcntl
+       SYSCALL
+       MOVL    fd+0(FP), DI // fd
+       MOVQ    $4, SI // F_SETFL
+       MOVQ    $4, DX // O_NONBLOCK
+       ORL     AX, DX
+       MOVL    $92, AX // fcntl
+       SYSCALL
+       RET
index 7ff4016de3e22082291e3d3d2affa463bd0e0f64..d8474546fb58d8eec16197ebf75f017a3fc916d7 100644 (file)
@@ -97,6 +97,32 @@ TEXT runtime·read(SB),NOSPLIT,$-4
        MOVL    AX, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$8-12
+       MOVL    $42, AX
+       INT     $0x80
+       JAE     ok
+       MOVL    $0, r+0(FP)
+       MOVL    $0, w+4(FP)
+       MOVL    AX, errno+8(FP)
+       RET
+ok:
+       MOVL    AX, r+0(FP)
+       MOVL    DX, w+4(FP)
+       MOVL    $0, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$12-16
+       MOVL    $542, AX
+       LEAL    r+4(FP), BX
+       MOVL    BX, 4(SP)
+       MOVL    flags+0(FP), BX
+       MOVL    BX, 8(SP)
+       INT     $0x80
+       MOVL    AX, errno+12(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT,$-4
        MOVL    $4, AX
        INT     $0x80
@@ -412,6 +438,23 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$32
        NEGL    AX
        RET
 
+// func runtime·setNonblock(fd int32)
+TEXT runtime·setNonblock(SB),NOSPLIT,$16-4
+       MOVL    $92, AX // fcntl
+       MOVL    fd+0(FP), BX // fd
+       MOVL    BX, 4(SP)
+       MOVL    $3, 8(SP) // F_GETFL
+       MOVL    $0, 12(SP)
+       INT     $0x80
+       MOVL    fd+0(FP), BX // fd
+       MOVL    BX, 4(SP)
+       MOVL    $4, 8(SP) // F_SETFL
+       ORL     $4, AX // O_NONBLOCK
+       MOVL    AX, 12(SP)
+       MOVL    $92, AX // fcntl
+       INT     $0x80
+       RET
+
 // func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
 TEXT runtime·cpuset_getaffinity(SB), NOSPLIT, $0-28
        MOVL    $487, AX
index 6f6da480d86f20ae8dd6e6f623bb19045bb904fa..7d6d7164f40c46b58b9c8844ccb2ef0163e20e84 100644 (file)
@@ -97,6 +97,30 @@ TEXT runtime·read(SB),NOSPLIT,$-8
        MOVL    AX, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVL    $42, AX
+       SYSCALL
+       JCC     ok
+       MOVL    $0, r+0(FP)
+       MOVL    $0, w+4(FP)
+       MOVL    AX, errno+8(FP)
+       RET
+ok:
+       MOVL    AX, r+0(FP)
+       MOVL    DX, w+4(FP)
+       MOVL    $0, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-20
+       LEAQ    r+8(FP), DI
+       MOVL    flags+0(FP), SI
+       MOVL    $542, AX
+       SYSCALL
+       MOVL    AX, errno+16(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT,$-8
        MOVQ    fd+0(FP), DI            // arg 1 fd
        MOVQ    p+8(FP), SI             // arg 2 buf
@@ -447,6 +471,21 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        SYSCALL
        RET
 
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVL    fd+0(FP), DI  // fd
+       MOVQ    $3, SI  // F_GETFL
+       MOVQ    $0, DX
+       MOVL    $92, AX // fcntl
+       SYSCALL
+       MOVL    fd+0(FP), DI // fd
+       MOVQ    $4, SI // F_SETFL
+       MOVQ    $4, DX // O_NONBLOCK
+       ORL     AX, DX
+       MOVL    $92, AX // fcntl
+       SYSCALL
+       RET
+
 // func cpuset_getaffinity(level int, which int, id int64, size int, mask *byte) int32
 TEXT runtime·cpuset_getaffinity(SB), NOSPLIT, $0-44
        MOVQ    level+0(FP), DI
index 1bdc10681a7ca0cbd0a03566b583957f77ea24bc..27b45888f42d0c19a2670980930911319e84b7d6 100644 (file)
@@ -20,6 +20,7 @@
 #define SYS_close (SYS_BASE + 6)
 #define SYS_getpid (SYS_BASE + 20)
 #define SYS_kill (SYS_BASE + 37)
+#define SYS_pipe (SYS_BASE + 42)
 #define SYS_sigaltstack (SYS_BASE + 53)
 #define SYS_munmap (SYS_BASE + 73)
 #define SYS_madvise (SYS_BASE + 75)
@@ -40,6 +41,7 @@
 #define SYS_thr_new (SYS_BASE + 455)
 #define SYS_mmap (SYS_BASE + 477)
 #define SYS_cpuset_getaffinity (SYS_BASE + 487)
+#define SYS_pipe2 (SYS_BASE + 542)
 
 TEXT runtime·sys_umtx_op(SB),NOSPLIT,$0
        MOVW addr+0(FP), R0
@@ -119,6 +121,32 @@ TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
        MOVW    R0, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVW    $SYS_pipe, R7
+       SWI     $0
+       BCC     ok
+       MOVW    $0, R1
+       MOVW    R1, r+0(FP)
+       MOVW    R1, w+4(FP)
+       MOVW    R0, errno+8(FP)
+       RET
+ok:
+       MOVW    R0, r+0(FP)
+       MOVW    R1, w+4(FP)
+       MOVW    $0, R1
+       MOVW    R1, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-16
+       MOVW    $r+4(FP), R0
+       MOVW    flags+0(FP), R1
+       MOVW    $SYS_pipe2, R7
+       SWI     $0
+       MOVW    R0, errno+12(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0
        MOVW fd+0(FP), R0       // arg 1 fd
        MOVW p+4(FP), R1        // arg 2 buf
@@ -371,6 +399,20 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        SWI $0
        RET
 
+// func runtime·setNonblock(fd int32)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVW    fd+0(FP), R0    // fd
+       MOVW    $3, R1  // F_GETFL
+       MOVW    $0, R2
+       MOVW    $SYS_fcntl, R7
+       SWI     $0
+       ORR     $0x4, R0, R2    // O_NONBLOCK
+       MOVW    fd+0(FP), R0    // fd
+       MOVW    $4, R1  // F_SETFL
+       MOVW    $SYS_fcntl, R7
+       SWI     $0
+       RET
+
 // TODO: this is only valid for ARMv7+
 TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
        B       runtime·armPublicationBarrier(SB)
index 882f31cd641e8b3bc5f53238a824711a9b40ecd6..2e4f66c55afc8a4fa88285642a65548d5d987fbe 100644 (file)
@@ -32,6 +32,7 @@
 #define SYS_getpid             20
 #define SYS_access             33
 #define SYS_kill               37
+#define SYS_pipe               42
 #define SYS_brk                45
 #define SYS_fcntl              55
 #define SYS_munmap             91
@@ -58,6 +59,7 @@
 #define SYS_clock_gettime      265
 #define SYS_tgkill             270
 #define SYS_epoll_create1      329
+#define SYS_pipe2              331
 
 TEXT runtime·exit(SB),NOSPLIT,$0
        MOVL    $SYS_exit_group, AX
@@ -131,6 +133,23 @@ TEXT runtime·read(SB),NOSPLIT,$0
        MOVL    AX, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVL    $SYS_pipe, AX
+       LEAL    r+0(FP), BX
+       INVOKE_SYSCALL
+       MOVL    AX, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-16
+       MOVL    $SYS_pipe2, AX
+       LEAL    r+4(FP), BX
+       MOVL    flags+0(FP), CX
+       INVOKE_SYSCALL
+       MOVL    AX, errno+12(FP)
+       RET
+
 TEXT runtime·usleep(SB),NOSPLIT,$8
        MOVL    $0, DX
        MOVL    usec+0(FP), AX
@@ -695,6 +714,21 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        INVOKE_SYSCALL
        RET
 
+// func runtime·setNonblock(fd int32)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVL    $SYS_fcntl, AX
+       MOVL    fd+0(FP), BX // fd
+       MOVL    $3, CX // F_GETFL
+       MOVL    $0, DX
+       INVOKE_SYSCALL
+       MOVL    fd+0(FP), BX // fd
+       MOVL    $4, CX // F_SETFL
+       MOVL    $0x800, DX // O_NONBLOCK
+       ORL     AX, DX
+       MOVL    $SYS_fcntl, AX
+       INVOKE_SYSCALL
+       RET
+
 // int access(const char *name, int mode)
 TEXT runtime·access(SB),NOSPLIT,$0
        MOVL    $SYS_access, AX
index 7e8f5279cacd1a5edeaeb0a8246c1aaa9fce9db9..ae4d0ef060cfc029198f3e2487f415cf2c828755 100644 (file)
@@ -21,6 +21,7 @@
 #define SYS_rt_sigaction       13
 #define SYS_rt_sigprocmask     14
 #define SYS_rt_sigreturn       15
+#define SYS_pipe               22
 #define SYS_sched_yield        24
 #define SYS_mincore            27
 #define SYS_madvise            28
@@ -46,6 +47,7 @@
 #define SYS_faccessat          269
 #define SYS_epoll_pwait                281
 #define SYS_epoll_create1      291
+#define SYS_pipe2              293
 
 TEXT runtime·exit(SB),NOSPLIT,$0-4
        MOVL    code+0(FP), DI
@@ -113,6 +115,23 @@ TEXT runtime·read(SB),NOSPLIT,$0-28
        MOVL    AX, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       LEAQ    r+0(FP), DI
+       MOVL    $SYS_pipe, AX
+       SYSCALL
+       MOVL    AX, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-20
+       LEAQ    r+8(FP), DI
+       MOVL    flags+0(FP), SI
+       MOVL    $SYS_pipe2, AX
+       SYSCALL
+       MOVL    AX, errno+16(FP)
+       RET
+
 TEXT runtime·usleep(SB),NOSPLIT,$16
        MOVL    $0, DX
        MOVL    usec+0(FP), AX
@@ -682,6 +701,20 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        SYSCALL
        RET
 
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVL    fd+0(FP), DI  // fd
+       MOVQ    $3, SI  // F_GETFL
+       MOVQ    $0, DX
+       MOVL    $SYS_fcntl, AX
+       SYSCALL
+       MOVL    fd+0(FP), DI // fd
+       MOVQ    $4, SI // F_SETFL
+       MOVQ    $0x800, DX // O_NONBLOCK
+       ORL     AX, DX
+       MOVL    $SYS_fcntl, AX
+       SYSCALL
+       RET
 
 // int access(const char *name, int mode)
 TEXT runtime·access(SB),NOSPLIT,$0
index c7d83a6d3aced89564e90851118f264c25d2fe9e..047dfed4977fe42141c91976ce6c5bc06279ed33 100644 (file)
@@ -23,6 +23,7 @@
 #define SYS_close (SYS_BASE + 6)
 #define SYS_getpid (SYS_BASE + 20)
 #define SYS_kill (SYS_BASE + 37)
+#define SYS_pipe (SYS_BASE + 42)
 #define SYS_clone (SYS_BASE + 120)
 #define SYS_rt_sigreturn (SYS_BASE + 173)
 #define SYS_rt_sigaction (SYS_BASE + 174)
@@ -45,6 +46,7 @@
 #define SYS_epoll_ctl (SYS_BASE + 251)
 #define SYS_epoll_wait (SYS_BASE + 252)
 #define SYS_epoll_create1 (SYS_BASE + 357)
+#define SYS_pipe2 (SYS_BASE + 359)
 #define SYS_fcntl (SYS_BASE + 55)
 #define SYS_access (SYS_BASE + 33)
 #define SYS_connect (SYS_BASE + 283)
@@ -99,6 +101,23 @@ TEXT runtime·read(SB),NOSPLIT,$0
        MOVW    R0, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVW    $r+0(FP), R0
+       MOVW    $SYS_pipe, R7
+       SWI     $0
+       MOVW    R0, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-16
+       MOVW    $r+4(FP), R0
+       MOVW    flags+0(FP), R1
+       MOVW    $SYS_pipe2, R7
+       SWI     $0
+       MOVW    R0, errno+12(FP)
+       RET
+
 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0
        MOVW    code+0(FP), R0
        MOVW    $SYS_exit_group, R7
@@ -567,6 +586,20 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        SWI     $0
        RET
 
+// func runtime·setNonblock(fd int32)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVW    fd+0(FP), R0    // fd
+       MOVW    $3, R1  // F_GETFL
+       MOVW    $0, R2
+       MOVW    $SYS_fcntl, R7
+       SWI     $0
+       ORR     $0x800, R0, R2  // O_NONBLOCK
+       MOVW    fd+0(FP), R0    // fd
+       MOVW    $4, R1  // F_SETFL
+       MOVW    $SYS_fcntl, R7
+       SWI     $0
+       RET
+
 // b __kuser_get_tls @ 0xffff0fe0
 TEXT runtime·read_tls_fallback(SB),NOSPLIT|NOFRAME,$0
        MOVW    $0xffff0fe0, R0
index bce948a91e042787b6fb32cbc0d966cafa2fc60d..d5ffe7fd579704013ad4fadf32c6d37fe615e7cf 100644 (file)
@@ -20,6 +20,7 @@
 #define SYS_write              64
 #define SYS_openat             56
 #define SYS_close              57
+#define SYS_pipe2              59
 #define SYS_fcntl              25
 #define SYS_nanosleep          101
 #define SYS_mmap               222
@@ -117,6 +118,24 @@ done:
        MOVW    R0, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
+       ADD     $8, RSP, R0
+       MOVW    $0, R1
+       MOVW    $SYS_pipe2, R8
+       SVC
+       MOVW    R0, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
+       ADD     $16, RSP, R0
+       MOVW    flags+0(FP), R1
+       MOVW    $SYS_pipe2, R8
+       SVC
+       MOVW    R0, errno+16(FP)
+       RET
+
 TEXT runtime·usleep(SB),NOSPLIT,$24-4
        MOVWU   usec+0(FP), R3
        MOVD    R3, R5
@@ -605,6 +624,21 @@ TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
        SVC
        RET
 
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
+       MOVW    fd+0(FP), R0 // fd
+       MOVD    $3, R1  // F_GETFL
+       MOVD    $0, R2
+       MOVD    $SYS_fcntl, R8
+       SVC
+       MOVD    $0x800, R2 // O_NONBLOCK
+       EOR     R0, R2
+       MOVW    fd+0(FP), R0 // fd
+       MOVD    $4, R1  // F_SETFL
+       MOVD    $SYS_fcntl, R8
+       SVC
+       RET
+
 // int access(const char *name, int mode)
 TEXT runtime·access(SB),NOSPLIT,$0-20
        MOVD    $AT_FDCWD, R0
index 26b619e238fa92b7c9c463a0a524ed7fccfb0300..37e4842f08912182f199c8b4cdb9b4ba96c97657 100644 (file)
@@ -19,6 +19,7 @@
 #define SYS_read               5000
 #define SYS_write              5001
 #define SYS_close              5003
+#define SYS_pipe               5021
 #define SYS_getpid             5038
 #define SYS_kill               5060
 #define SYS_fcntl              5080
@@ -46,6 +47,7 @@
 #define SYS_clock_gettime      5222
 #define SYS_epoll_create1      5285
 #define SYS_brk                        5012
+#define SYS_pipe2              5287
 
 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
        MOVW    code+0(FP), R4
@@ -110,6 +112,23 @@ TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
        MOVW    R2, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
+       MOVV    $r+0(FP), R4
+       MOVV    $SYS_pipe, R2
+       SYSCALL
+       MOVW    R2, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
+       MOVV    $r+8(FP), R4
+       MOVW    flags+0(FP), R5
+       MOVV    $SYS_pipe2, R2
+       SYSCALL
+       MOVW    R2, errno+16(FP)
+       RET
+
 TEXT runtime·usleep(SB),NOSPLIT,$16-4
        MOVWU   usec+0(FP), R3
        MOVV    R3, R5
@@ -454,6 +473,21 @@ TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
        SYSCALL
        RET
 
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
+       MOVW    fd+0(FP), R4 // fd
+       MOVV    $3, R5  // F_GETFL
+       MOVV    $0, R6
+       MOVV    $SYS_fcntl, R2
+       SYSCALL
+       MOVW    $0x80, R6 // O_NONBLOCK
+       OR      R2, R6
+       MOVW    fd+0(FP), R4 // fd
+       MOVV    $4, R5  // F_SETFL
+       MOVV    $SYS_fcntl, R2
+       SYSCALL
+       RET
+
 // func sbrk0() uintptr
 TEXT runtime·sbrk0(SB),NOSPLIT|NOFRAME,$0-8
        // Implemented as brk(NULL).
index 30d962c325043d4e893c502f540bbae88a549336..b1cfafb4c95ef6db4d029e74b5832816eefc0870 100644 (file)
@@ -20,6 +20,7 @@
 #define SYS_close              4006
 #define SYS_getpid             4020
 #define SYS_kill               4037
+#define SYS_pipe               4042
 #define SYS_brk                        4045
 #define SYS_fcntl              4055
 #define SYS_mmap               4090
@@ -44,6 +45,7 @@
 #define SYS_clock_gettime      4263
 #define SYS_tgkill             4266
 #define SYS_epoll_create1      4326
+#define SYS_pipe2              4328
 
 TEXT runtime·exit(SB),NOSPLIT,$0-4
        MOVW    code+0(FP), R4
@@ -108,6 +110,23 @@ TEXT runtime·read(SB),NOSPLIT,$0-16
        MOVW    R2, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVW    $r+0(FP), R4
+       MOVW    $SYS_pipe, R2
+       SYSCALL
+       MOVW    R2, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-16
+       MOVW    $r+4(FP), R4
+       MOVW    flags+0(FP), R5
+       MOVW    $SYS_pipe2, R2
+       SYSCALL
+       MOVW    R2, errno+12(FP)
+       RET
+
 TEXT runtime·usleep(SB),NOSPLIT,$28-4
        MOVW    usec+0(FP), R3
        MOVW    R3, R5
@@ -487,6 +506,21 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0-4
        SYSCALL
        RET
 
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVW    fd+0(FP), R4 // fd
+       MOVW    $3, R5  // F_GETFL
+       MOVW    $0, R6
+       MOVW    $SYS_fcntl, R2
+       SYSCALL
+       MOVW    $0x80, R6 // O_NONBLOCK
+       OR      R2, R6
+       MOVW    fd+0(FP), R4 // fd
+       MOVW    $4, R5  // F_SETFL
+       MOVW    $SYS_fcntl, R2
+       SYSCALL
+       RET
+
 // func sbrk0() uintptr
 TEXT runtime·sbrk0(SB),NOSPLIT,$0-4
        // Implemented as brk(NULL).
index cda195687582a7b8f154bc5f238a5e727a3f0596..d4908a127cb64068287afae95a3c3ac857af3ef7 100644 (file)
@@ -21,6 +21,7 @@
 #define SYS_close                6
 #define SYS_getpid              20
 #define SYS_kill                37
+#define SYS_pipe                42
 #define SYS_brk                         45
 #define SYS_fcntl               55
 #define SYS_mmap                90
@@ -45,6 +46,7 @@
 #define SYS_clock_gettime      246
 #define SYS_tgkill             250
 #define SYS_epoll_create1      315
+#define SYS_pipe2              317
 
 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
        MOVW    code+0(FP), R3
@@ -100,6 +102,21 @@ TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
        MOVW    R3, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
+       ADD     $FIXED_FRAME, R1, R3
+       SYSCALL $SYS_pipe
+       MOVW    R3, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
+       ADD     $FIXED_FRAME+8, R1, R3
+       MOVW    flags+0(FP), R4
+       SYSCALL $SYS_pipe2
+       MOVW    R3, errno+16(FP)
+       RET
+
 TEXT runtime·usleep(SB),NOSPLIT,$16-4
        MOVW    usec+0(FP), R3
        MOVD    R3, R5
@@ -612,6 +629,18 @@ TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
        SYSCALL $SYS_fcntl
        RET
 
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
+       MOVW    fd+0(FP), R3 // fd
+       MOVD    $3, R4  // F_GETFL
+       MOVD    $0, R5
+       SYSCALL $SYS_fcntl
+       OR      $0x800, R3, R5 // O_NONBLOCK
+       MOVW    fd+0(FP), R3 // fd
+       MOVD    $4, R4  // F_SETFL
+       SYSCALL $SYS_fcntl
+       RET
+
 // func sbrk0() uintptr
 TEXT runtime·sbrk0(SB),NOSPLIT|NOFRAME,$0
        // Implemented as brk(NULL).
index f8ef4eca3220232069b2f7537f4d60b99b010d74..01f408e70bfd4eb570f21c3dcaf965cfdd69ea14 100644 (file)
@@ -16,6 +16,7 @@
 #define SYS_close                 6
 #define SYS_getpid               20
 #define SYS_kill                 37
+#define SYS_pipe                42
 #define SYS_brk                         45
 #define SYS_fcntl                55
 #define SYS_mmap                 90
@@ -39,6 +40,7 @@
 #define SYS_epoll_ctl           250
 #define SYS_epoll_wait          251
 #define SYS_clock_gettime       260
+#define SYS_pipe2              325
 #define SYS_epoll_create1       327
 
 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4
@@ -104,6 +106,23 @@ TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28
        MOVW    R2, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
+       MOVD    $r+0(FP), R2
+       MOVW    $SYS_pipe, R1
+       SYSCALL
+       MOVW    R2, errno+8(FP)
+       RET
+
+// func pipe2() (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
+       MOVD    $r+8(FP), R2
+       MOVW    flags+0(FP), R3
+       MOVW    $SYS_pipe2, R1
+       SYSCALL
+       MOVW    R2, errno+16(FP)
+       RET
+
 TEXT runtime·usleep(SB),NOSPLIT,$16-4
        MOVW    usec+0(FP), R2
        MOVD    R2, R4
@@ -441,6 +460,21 @@ TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
        SYSCALL
        RET
 
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
+       MOVW    fd+0(FP), R2 // fd
+       MOVD    $3, R3  // F_GETFL
+       XOR     R4, R4
+       MOVW    $SYS_fcntl, R1
+       SYSCALL
+       MOVD    $0x800, R4 // O_NONBLOCK
+       OR      R2, R4
+       MOVW    fd+0(FP), R2 // fd
+       MOVD    $4, R3  // F_SETFL
+       MOVW    $SYS_fcntl, R1
+       SYSCALL
+       RET
+
 // func sbrk0() uintptr
 TEXT runtime·sbrk0(SB),NOSPLIT|NOFRAME,$0-8
        // Implemented as brk(NULL).
index b8c5a92a4fb813c68713f9a0b6a025e87fa00d92..c882d1332b6ed8a463fac040a7aa184e862f4bae 100644 (file)
@@ -87,6 +87,32 @@ TEXT runtime·read(SB),NOSPLIT,$-4
        MOVL    AX, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVL    $42, AX
+       INT     $0x80
+       JCC     pipeok
+       MOVL    $-1, r+0(FP)
+       MOVL    $-1, w+4(FP)
+       MOVL    AX, errno+8(FP)
+       RET
+pipeok:
+       MOVL    AX, r+0(FP)
+       MOVL    DX, w+4(FP)
+       MOVL    $0, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$12-16
+       MOVL    $453, AX
+       LEAL    r+4(FP), BX
+       MOVL    BX, 4(SP)
+       MOVL    flags+0(FP), BX
+       MOVL    BX, 8(SP)
+       INT     $0x80
+       MOVL    AX, errno+12(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT,$-4
        MOVL    $SYS_write, AX
        INT     $0x80
@@ -455,3 +481,20 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$32
        JAE     2(PC)
        NEGL    AX
        RET
+
+// func runtime·setNonblock(fd int32)
+TEXT runtime·setNonblock(SB),NOSPLIT,$16-4
+       MOVL    $92, AX // fcntl
+       MOVL    fd+0(FP), BX // fd
+       MOVL    BX, 4(SP)
+       MOVL    $3, 8(SP) // F_GETFL
+       MOVL    $0, 12(SP)
+       INT     $0x80
+       MOVL    fd+0(FP), BX // fd
+       MOVL    BX, 4(SP)
+       MOVL    $4, 8(SP) // F_SETFL
+       ORL     $4, AX // O_NONBLOCK
+       MOVL    AX, 12(SP)
+       MOVL    $92, AX // fcntl
+       INT     $0x80
+       RET
index b1b50ab4a9917e4388e653376053204dc29a7ec8..0784b8445547d17a6d4ecbf84e14681bc53c6214 100644 (file)
@@ -158,6 +158,30 @@ TEXT runtime·read(SB),NOSPLIT,$-8
        MOVL    AX, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVL    $42, AX
+       SYSCALL
+       JCC     pipeok
+       MOVL    $-1, r+0(FP)
+       MOVL    $-1, w+4(FP)
+       MOVL    AX, errno+8(FP)
+       RET
+pipeok:
+       MOVL    AX, r+0(FP)
+       MOVL    DX, w+4(FP)
+       MOVL    $0, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-20
+       LEAQ    r+8(FP), DI
+       MOVL    flags+0(FP), SI
+       MOVL    $453, AX
+       SYSCALL
+       MOVL    AX, errno+16(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT,$-8
        MOVQ    fd+0(FP), DI            // arg 1 - fd
        MOVQ    p+8(FP), SI             // arg 2 - buf
@@ -429,3 +453,18 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVL    $SYS_fcntl, AX
        SYSCALL
        RET
+
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVL    fd+0(FP), DI  // fd
+       MOVQ    $3, SI  // F_GETFL
+       MOVQ    $0, DX
+       MOVL    $92, AX // fcntl
+       SYSCALL
+       MOVL    fd+0(FP), DI // fd
+       MOVQ    $4, SI // F_SETFL
+       MOVQ    $4, DX // O_NONBLOCK
+       ORL     AX, DX
+       MOVL    $92, AX // fcntl
+       SYSCALL
+       RET
index 90f37e1a0560a1fe108653d9dd2bbee8dcff45cd..ce2afc2d881ca7643728f4a9f38fca98abeaec2b 100644 (file)
@@ -96,6 +96,30 @@ TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
        MOVW    R0, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       SWI $0xa0002a
+       BCC pipeok
+       MOVW $-1,R2
+       MOVW R2, r+0(FP)
+       MOVW R2, w+4(FP)
+       MOVW R0, errno+8(FP)
+       RET
+pipeok:
+       MOVW $0, R2
+       MOVW R0, r+0(FP)
+       MOVW R1, w+4(FP)
+       MOVW R2, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-16
+       MOVW $r+4(FP), R0
+       MOVW flags+0(FP), R1
+       SWI $0xa001c5
+       MOVW R0, errno+12(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0
        MOVW    fd+0(FP), R0    // arg 1 - fd
        MOVW    p+4(FP), R1     // arg 2 - buf
@@ -385,6 +409,18 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        SWI $SYS_fcntl
        RET
 
+// func runtime·setNonblock(fd int32)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVW fd+0(FP), R0       // fd
+       MOVW $3, R1     // F_GETFL
+       MOVW $0, R2
+       SWI $0xa0005c   // sys_fcntl
+       ORR $0x4, R0, R2        // O_NONBLOCK
+       MOVW fd+0(FP), R0       // fd
+       MOVW $4, R1     // F_SETFL
+       SWI $0xa0005c   // sys_fcntl
+       RET
+
 // TODO: this is only valid for ARMv7+
 TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
        B       runtime·armPublicationBarrier(SB)
index 55abdd52d6f92907912ecf3de8b1cae579a7965b..ab0579772b36c13e5e8216f7658e2173a4e8229d 100644 (file)
@@ -14,6 +14,9 @@
 #define CLOCK_MONOTONIC                3
 #define FD_CLOEXEC             1
 #define F_SETFD                        2
+#define F_GETFL                        3
+#define F_SETFL                        4
+#define O_NONBLOCK             4
 
 #define SYS_exit                       1
 #define SYS_read                       3
@@ -43,6 +46,7 @@
 #define SYS___clock_gettime50          427
 #define SYS___nanosleep50              430
 #define SYS___kevent50                 435
+#define SYS_pipe2                      453
 #define SYS_openat                     468
 #define SYS____lwp_park60              478
 
@@ -146,6 +150,33 @@ ok:
        MOVW    R0, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
+       MOVW    $0, R0
+       SVC     $SYS_pipe2
+       BCC     pipeok
+       MOVW    $-1,R1
+       MOVW    R1, r+0(FP)
+       MOVW    R1, w+4(FP)
+       NEG     R0, R0
+       MOVW    R0, errno+8(FP)
+       RET
+pipeok:
+       MOVW    R0, r+0(FP)
+       MOVW    R1, w+4(FP)
+       MOVW    ZR, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
+       ADD     $8, RSP, R0
+       MOVW    flags+0(FP), R1
+       SVC     $SYS_pipe2
+       BCC     2(PC)
+       NEG     R0, R0
+       MOVW    R0, errno+16(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT,$-8
        MOVD    fd+0(FP), R0            // arg 1 - fd
        MOVD    p+8(FP), R1             // arg 2 - buf
@@ -431,3 +462,16 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVW    $FD_CLOEXEC, R2
        SVC     $SYS_fcntl
        RET
+
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
+       MOVW    fd+0(FP), R0            // arg 1 - fd
+       MOVD    $F_GETFL, R1            // arg 2 - cmd
+       MOVD    $0, R2                  // arg 3
+       SVC     $SYS_fcntl
+       MOVD    $O_NONBLOCK, R2
+       EOR     R0, R2                  // arg 3 - flags
+       MOVW    fd+0(FP), R0            // arg 1 - fd
+       MOVD    $F_SETFL, R1            // arg 2 - cmd
+       SVC     $SYS_fcntl
+       RET
index 31c837cd81d06860c3da7f5af77058a102810190..1a216a572f265c526e73bc0b938ff1a079773d4f 100644 (file)
@@ -50,6 +50,26 @@ TEXT runtime·read(SB),NOSPLIT,$-4
        MOVL    AX, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$8-12
+       MOVL    $263, AX
+       LEAL    r+0(FP), BX
+       MOVL    BX, 4(SP)
+       INT     $0x80
+       MOVL    AX, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$12-16
+       MOVL    $101, AX
+       LEAL    r+4(FP), BX
+       MOVL    BX, 4(SP)
+       MOVL    flags+0(FP), BX
+       MOVL    BX, 8(SP)
+       INT     $0x80
+       MOVL    AX, errno+12(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT,$-4
        MOVL    $4, AX                  // sys_write
        INT     $0x80
@@ -416,4 +436,21 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$32
        NEGL    AX
        RET
 
+// func runtime·setNonblock(fd int32)
+TEXT runtime·setNonblock(SB),NOSPLIT,$16-4
+       MOVL    $92, AX // fcntl
+       MOVL    fd+0(FP), BX // fd
+       MOVL    BX, 4(SP)
+       MOVL    $3, 8(SP) // F_GETFL
+       MOVL    $0, 12(SP)
+       INT     $0x80
+       MOVL    fd+0(FP), BX // fd
+       MOVL    BX, 4(SP)
+       MOVL    $4, 8(SP) // F_SETFL
+       ORL     $4, AX // O_NONBLOCK
+       MOVL    AX, 12(SP)
+       MOVL    $92, AX // fcntl
+       INT     $0x80
+       RET
+
 GLOBL runtime·tlsoffset(SB),NOPTR,$4
index 17dd9e86a0c344c217f49b78080a66b36af8650a..8bb2b265be5e34f25fdef88e6c875e563378e247 100644 (file)
@@ -127,6 +127,23 @@ TEXT runtime·read(SB),NOSPLIT,$-8
        MOVL    AX, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       LEAQ    r+0(FP), DI
+       MOVL    $263, AX
+       SYSCALL
+       MOVL    AX, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-20
+       LEAQ    r+8(FP), DI
+       MOVL    flags+0(FP), SI
+       MOVL    $101, AX
+       SYSCALL
+       MOVL    AX, errno+16(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT,$-8
        MOVQ    fd+0(FP), DI            // arg 1 - fd
        MOVQ    p+8(FP), SI             // arg 2 - buf
@@ -378,3 +395,18 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVL    $92, AX         // fcntl
        SYSCALL
        RET
+
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVL    fd+0(FP), DI  // fd
+       MOVQ    $3, SI  // F_GETFL
+       MOVQ    $0, DX
+       MOVL    $92, AX // fcntl
+       SYSCALL
+       MOVL    fd+0(FP), DI // fd
+       MOVQ    $4, SI // F_SETFL
+       MOVQ    $4, DX // O_NONBLOCK
+       ORL     AX, DX
+       MOVL    $92, AX // fcntl
+       SYSCALL
+       RET
index 69a5f4cf76a98dd1fd8b42407d8e8d10ecb21400..16de1efd03bcb94843610bad680217c14ad8e274 100644 (file)
@@ -59,6 +59,23 @@ TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
        MOVW    R0, ret+12(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT,$0-12
+       MOVW    $r+0(FP), R0
+       MOVW    $263, R12
+       SWI     $0
+       MOVW    R0, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT,$0-16
+       MOVW    $r+4(FP), R0
+       MOVW    flags+0(FP), R1
+       MOVW    $101, R12
+       SWI     $0
+       MOVW    R0, errno+12(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0
        MOVW    fd+0(FP), R0            // arg 1 - fd
        MOVW    p+4(FP), R1             // arg 2 - buf
@@ -368,6 +385,20 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        SWI     $0
        RET
 
+// func runtime·setNonblock(fd int32)
+TEXT runtime·setNonblock(SB),NOSPLIT,$0-4
+       MOVW    fd+0(FP), R0    // fd
+       MOVW    $3, R1  // F_GETFL
+       MOVW    $0, R2
+       MOVW    $92, R12
+       SWI     $0
+       ORR     $0x4, R0, R2    // O_NONBLOCK
+       MOVW    fd+0(FP), R0    // fd
+       MOVW    $4, R1  // F_SETFL
+       MOVW    $92, R12
+       SWI     $0
+       RET
+
 TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
        B       runtime·armPublicationBarrier(SB)
 
index e9c2a8b62c1260b6f1cf5e3016bb7e9ff13ade59..66b4e89388a118f8ec1aba86e052dd73a34b9204 100644 (file)
@@ -63,6 +63,28 @@ TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0
        MOVW    R0, ret+24(FP)
        RET
 
+// func pipe() (r, w int32, errno int32)
+TEXT runtime·pipe(SB),NOSPLIT|NOFRAME,$0-12
+       MOVD    RSP, R0
+       MOVW    $0, R1
+       MOVD    $101, R8                // sys_pipe2
+       SVC
+       BCC     2(PC)
+       NEG     R0, R0
+       MOVW    R0, errno+8(FP)
+       RET
+
+// func pipe2(flags int32) (r, w int32, errno int32)
+TEXT runtime·pipe2(SB),NOSPLIT|NOFRAME,$0-20
+       ADD     $8, RSP, R0
+       MOVW    flags+0(FP), R1
+       MOVD    $101, R8                // sys_pipe2
+       SVC
+       BCC     2(PC)
+       NEG     R0, R0
+       MOVW    R0, errno+16(FP)
+       RET
+
 TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0
        MOVW    fd+0(FP), R0            // arg 1 - fd
        MOVD    p+8(FP), R1             // arg 2 - buf
@@ -394,3 +416,18 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVD    $92, R8                 // sys_fcntl
        SVC
        RET
+
+// func runtime·setNonblock(int32 fd)
+TEXT runtime·setNonblock(SB),NOSPLIT|NOFRAME,$0-4
+       MOVW    fd+0(FP), R0            // arg 1 - fd
+       MOVD    $3, R1                  // arg 2 - cmd (F_GETFL)
+       MOVD    $0, R2                  // arg 3
+       MOVD    $92, R8                 // sys_fcntl
+       SVC
+       MOVD    $0x800, R2              // O_NONBLOCK
+       EOR     R0, R2                  // arg 3 - flags
+       MOVW    fd+0(FP), R0            // arg 1 - fd
+       MOVD    $4, R1                  // arg 2 - cmd (F_SETFL)
+       MOVD    $92, R8                 // sys_fcntl
+       SVC
+       RET