1
0
mirror of https://github.com/golang/go synced 2024-09-29 10:34:36 -06:00

internal/syscall/unix: use fcntl64 on 32-bit GNU/Linux systems

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>
This commit is contained in:
Ian Lance Taylor 2019-12-20 13:05:24 -08:00
parent 26f8b7074b
commit 372efbbf31
6 changed files with 46 additions and 7 deletions

View File

@ -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
}

View File

@ -8,8 +8,12 @@ package unix
import "syscall" 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) { 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 { if e1 != 0 {
return false, e1 return false, e1
} }

View File

@ -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
}

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build aix solaris // +build aix darwin solaris
package runtime_test package runtime_test

View File

@ -2,13 +2,16 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 package runtime_test
import "syscall" import (
"internal/syscall/unix"
"syscall"
)
func fcntl(fd uintptr, cmd int, arg uintptr) (uintptr, syscall.Errno) { 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 return res, err
} }

View File

@ -1,9 +1,12 @@
// +build linux,386 linux,arm linux,mips linux,mipsle
// Copyright 2014 The Go Authors. All rights reserved. // Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 package syscall
func init() { func init() {