From 974b0166d6a7c20b98f7e517e49197bea46fc5e2 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 17 Sep 2021 14:25:54 +0200 Subject: syscall: implement Pipe using pipe2 syscall on all linux platforms Most architectures currently already implement Pipe using the pipe2 syscall. Only 386, amd64 and mips{,le} still use the pipe syscall. However, some systems (e.g. Android seccomp policies) block that syscall, see #40828 for an example. The pipe2 syscall was added in Linux kernel version 2.6.27. The minimum required Linux kernel version for Go 1.18 will be changed to 2.6.32 per #45964 so it is possible to unify the implementation of Pipe using the pipe2 syscall. For #45964 Change-Id: I8ed6a391300c95f3107b4ec6b27d320e42fb535b Reviewed-on: https://go-review.googlesource.com/c/go/+/350530 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor --- src/syscall/syscall_linux.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/syscall/syscall_linux.go') diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go index 6d428d58dd..f02fa45a89 100644 --- a/src/syscall/syscall_linux.go +++ b/src/syscall/syscall_linux.go @@ -161,6 +161,23 @@ func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) return openat(dirfd, path, flags|O_LARGEFILE, mode) } +func Pipe(p []int) error { + return Pipe2(p, 0) +} + +//sysnb pipe2(p *[2]_C_int, flags int) (err error) + +func Pipe2(p []int, flags int) error { + if len(p) != 2 { + return EINVAL + } + var pp [2]_C_int + err := pipe2(&pp, flags) + p[0] = int(pp[0]) + p[1] = int(pp[1]) + return err +} + //sys readlinkat(dirfd int, path string, buf []byte) (n int, err error) func Readlink(path string, buf []byte) (n int, err error) { -- cgit v1.3