]> Cypherpunks repositories - gostls13.git/commitdiff
os, internal/syscall/unix: use pipe2 instead of pipe on illumos
authorTobias Klauser <tklauser@distanz.ch>
Tue, 15 Sep 2020 11:49:45 +0000 (13:49 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Wed, 16 Sep 2020 08:49:14 +0000 (08:49 +0000)
Illumos provides the pipe2 syscall. Add a wrapper to
internal/syscall/unix and use it to implement os.Pipe.

Change-Id: I26ecdbcae1e8d51f80e2bc8a86fb129826387b1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/254981
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/internal/syscall/unix/pipe2_illumos.go [new file with mode: 0644]
src/os/pipe2_illumos.go [new file with mode: 0644]
src/os/pipe_bsd.go

diff --git a/src/internal/syscall/unix/pipe2_illumos.go b/src/internal/syscall/unix/pipe2_illumos.go
new file mode 100644 (file)
index 0000000..f3ac8d2
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2020 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 illumos
+
+package unix
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+//go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so"
+
+//go:linkname procpipe2 libc_pipe2
+
+var procpipe2 uintptr
+
+type _C_int int32
+
+func Pipe2(p []int, flags int) error {
+       if len(p) != 2 {
+               return syscall.EINVAL
+       }
+       var pp [2]_C_int
+       _, _, errno := syscall6(uintptr(unsafe.Pointer(&procpipe2)), 2, uintptr(unsafe.Pointer(&pp)), uintptr(flags), 0, 0, 0, 0)
+       if errno != 0 {
+               return errno
+       }
+       p[0] = int(pp[0])
+       p[1] = int(pp[1])
+       return nil
+}
diff --git a/src/os/pipe2_illumos.go b/src/os/pipe2_illumos.go
new file mode 100644 (file)
index 0000000..026ce62
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2020 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 illumos
+
+package os
+
+import (
+       "internal/syscall/unix"
+       "syscall"
+)
+
+// Pipe returns a connected pair of Files; reads from r return bytes written to w.
+// It returns the files and an error, if any.
+func Pipe() (r *File, w *File, err error) {
+       var p [2]int
+
+       e := unix.Pipe2(p[0:], syscall.O_CLOEXEC)
+       if e != nil {
+               return nil, nil, NewSyscallError("pipe", e)
+       }
+
+       return newFile(uintptr(p[0]), "|0", kindPipe), newFile(uintptr(p[1]), "|1", kindPipe), nil
+}
index 0d2d82feb951991ad8bee25831a3d0671ca5cda2..115d6baa190a272123d3573cca6a66464c686181 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 js,wasm solaris
+// +build aix darwin dragonfly js,wasm solaris,!illumos
 
 package os