]> Cypherpunks repositories - gostls13.git/commitdiff
internal/syscall/unix: use fcntl64 on 32-bit GNU/Linux systems
authorIan Lance Taylor <iant@golang.org>
Fri, 20 Dec 2019 21:05:24 +0000 (13:05 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 23 Dec 2019 23:29:48 +0000 (23:29 +0000)
Patch up runtime testing to use the libc fcntl function on Darwin,
which is what we should be doing anyhow. This is similar to how
we handle fcntl on AIX and Solaris.

Fixes #36211

Change-Id: I47ad87e11df043ce21496a0d59523dad28960f76
Reviewed-on: https://go-review.googlesource.com/c/go/+/212299
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
src/internal/syscall/unix/fcntl_linux_32bit.go [new file with mode: 0644]
src/internal/syscall/unix/nonblocking.go
src/runtime/export_darwin_test.go [new file with mode: 0644]
src/runtime/nbpipe_fcntl_libc_test.go
src/runtime/nbpipe_fcntl_unix_test.go
src/syscall/flock_linux_32bit.go

diff --git a/src/internal/syscall/unix/fcntl_linux_32bit.go b/src/internal/syscall/unix/fcntl_linux_32bit.go
new file mode 100644 (file)
index 0000000..6c75afc
--- /dev/null
@@ -0,0 +1,16 @@
+// 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.
+
+// On 32-bit Linux systems, use SYS_FCNTL64.
+// If you change the build tags here, see syscall/flock_linux_32bit.go.
+
+// +build linux,386 linux,arm linux,mips linux,mipsle
+
+package unix
+
+import "syscall"
+
+func init() {
+       FcntlSyscall = syscall.SYS_FCNTL64
+}
index bcc350b56e1e19d989a4302534b49664b1157487..545445204f5909a3fbf1fdfa93b6814b21086994 100644 (file)
@@ -8,8 +8,12 @@ package unix
 
 import "syscall"
 
+// FcntlSyscall is the number for the fcntl system call. This is
+// usually SYS_FCNTL, but can be overridden to SYS_FCNTL64.
+var FcntlSyscall uintptr = syscall.SYS_FCNTL
+
 func IsNonblock(fd int) (nonblocking bool, err error) {
-       flag, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), uintptr(syscall.F_GETFL), 0)
+       flag, _, e1 := syscall.Syscall(FcntlSyscall, uintptr(fd), uintptr(syscall.F_GETFL), 0)
        if e1 != 0 {
                return false, e1
        }
diff --git a/src/runtime/export_darwin_test.go b/src/runtime/export_darwin_test.go
new file mode 100644 (file)
index 0000000..e9b6eb3
--- /dev/null
@@ -0,0 +1,13 @@
+// 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.
+
+package runtime
+
+func Fcntl(fd, cmd, arg uintptr) (uintptr, uintptr) {
+       r := fcntl(int32(fd), int32(cmd), int32(arg))
+       if r < 0 {
+               return ^uintptr(0), uintptr(-r)
+       }
+       return uintptr(r), 0
+}
index 70f4b8348baa5880d5144c3d2a09a547b0b82977..b38c58399bc8158d627309c6501ff3e5c4ad62be 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 solaris
+// +build aix darwin solaris
 
 package runtime_test
 
index 06b3275f062c1fd92f6b7e5265d5869c348ff35b..75acdb62dddd2d204eb07c89f6ae2289a1429e12 100644 (file)
@@ -2,13 +2,16 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin dragonfly freebsd linux netbsd openbsd
+// +build dragonfly freebsd linux netbsd openbsd
 
 package runtime_test
 
-import "syscall"
+import (
+       "internal/syscall/unix"
+       "syscall"
+)
 
 func fcntl(fd uintptr, cmd int, arg uintptr) (uintptr, syscall.Errno) {
-       res, _, err := syscall.Syscall(syscall.SYS_FCNTL, fd, uintptr(cmd), arg)
+       res, _, err := syscall.Syscall(unix.FcntlSyscall, fd, uintptr(cmd), arg)
        return res, err
 }
index e1548995b2153588732bd4a5dac7a219a200d181..e11aed6ed1a6e0380366131472301ea63d190b7e 100644 (file)
@@ -1,9 +1,12 @@
-// +build linux,386 linux,arm linux,mips linux,mipsle
-
 // Copyright 2014 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.
 
+// If you change the build tags here, see
+// internal/syscall/unix/fcntl_linux_32bit.go.
+
+// +build linux,386 linux,arm linux,mips linux,mipsle
+
 package syscall
 
 func init() {