]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[release-branch.go1.20] runtime: consistently define fcntl
authorIan Lance Taylor <iant@golang.org>
Mon, 15 May 2023 23:34:36 +0000 (16:34 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 22 May 2023 21:48:37 +0000 (21:48 +0000)
Clean up and consolidate on a single consistent definition of fcntl,
which takes three int32 arguments and returns either a positive result
or a negative errno value.

Change-Id: Id9505492712db4b0aab469c6bd15e4fce3c9ff6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/495075
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/497115
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Heschi Kreinick <heschi@google.com>

34 files changed:
src/runtime/export_aix_test.go
src/runtime/export_darwin_test.go
src/runtime/export_openbsd_test.go [deleted file]
src/runtime/export_solaris_test.go [deleted file]
src/runtime/export_unix_test.go
src/runtime/nbpipe_fcntl_libc_test.go [deleted file]
src/runtime/nbpipe_fcntl_unix_test.go [deleted file]
src/runtime/nbpipe_test.go
src/runtime/netpoll_solaris.go
src/runtime/os3_solaris.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_syscall2.go
src/runtime/os_solaris.go
src/runtime/sys_darwin_amd64.s
src/runtime/sys_darwin_arm64.s
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_freebsd_arm64.s
src/runtime/sys_freebsd_riscv64.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
src/runtime/sys_openbsd_mips64.s

index 51df951738436afe5b455976c0cba9c176592d31..48455333c146d6e430bf3cd7af287b0411b28669 100644 (file)
@@ -4,5 +4,4 @@
 
 package runtime
 
-var Fcntl = syscall_fcntl1
 var SetNonblock = setNonblock
index 66e2c02c4f6c2159e4a13d24fe3897fcf0663626..48455333c146d6e430bf3cd7af287b0411b28669 100644 (file)
@@ -4,12 +4,4 @@
 
 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
-}
-
 var SetNonblock = setNonblock
diff --git a/src/runtime/export_openbsd_test.go b/src/runtime/export_openbsd_test.go
deleted file mode 100644 (file)
index ef680dc..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2022 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.
-
-//go:build openbsd && !mips64
-
-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
-}
diff --git a/src/runtime/export_solaris_test.go b/src/runtime/export_solaris_test.go
deleted file mode 100644 (file)
index e865c77..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// 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) {
-       return sysvicall3Err(&libc_fcntl, fd, cmd, arg)
-}
index 71a55d8941d9a661ea1a375a67fa1651c613ea36..6967e7645c88348163340095ab2e807a2e07cdc6 100644 (file)
@@ -9,6 +9,7 @@ package runtime
 import "unsafe"
 
 var NonblockingPipe = nonblockingPipe
+var Fcntl = fcntl
 
 func sigismember(mask *sigset, i int) bool {
        clear := *mask
diff --git a/src/runtime/nbpipe_fcntl_libc_test.go b/src/runtime/nbpipe_fcntl_libc_test.go
deleted file mode 100644 (file)
index 170245d..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// 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.
-
-//go:build aix || darwin || (openbsd && !mips64) || solaris
-
-package runtime_test
-
-import (
-       "runtime"
-       "syscall"
-)
-
-// Call fcntl libc function rather than calling syscall.
-func fcntl(fd uintptr, cmd int, arg uintptr) (uintptr, syscall.Errno) {
-       res, errno := runtime.Fcntl(fd, uintptr(cmd), arg)
-       return res, syscall.Errno(errno)
-}
diff --git a/src/runtime/nbpipe_fcntl_unix_test.go b/src/runtime/nbpipe_fcntl_unix_test.go
deleted file mode 100644 (file)
index b7252ea..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// 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.
-
-//go:build dragonfly || freebsd || linux || netbsd || (openbsd && mips64)
-
-package runtime_test
-
-import (
-       "internal/syscall/unix"
-       "syscall"
-)
-
-func fcntl(fd uintptr, cmd int, arg uintptr) (uintptr, syscall.Errno) {
-       res, _, err := syscall.Syscall(unix.FcntlSyscall, fd, uintptr(cmd), arg)
-       return res, err
-}
index 0b0f64d07643752f2a0212672ec8682f6bb16442..bb21003c358239f141254bcab3aa4c8791156dfa 100644 (file)
@@ -14,23 +14,29 @@ import (
 )
 
 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)
-       }()
+       defer runtime.Close(w)
 
        checkIsPipe(t, r, w)
        checkNonblocking(t, r, "reader")
        checkCloseonexec(t, r, "reader")
        checkNonblocking(t, w, "writer")
        checkCloseonexec(t, w, "writer")
+
+       // Test that fcntl returns an error as expected.
+       if runtime.Close(r) != 0 {
+               t.Fatalf("Close(%d) failed", r)
+       }
+       val := runtime.Fcntl(r, syscall.F_GETFD, 0)
+       if val >= 0 {
+               t.Errorf("Fcntl succeeded unexpectedly")
+       } else if syscall.Errno(-val) != syscall.EBADF {
+               t.Errorf("Fcntl failed with error %v, expected %v", -val, syscall.EBADF)
+       }
 }
 
 func checkIsPipe(t *testing.T, r, w int32) {
@@ -49,9 +55,9 @@ func checkIsPipe(t *testing.T, r, w int32) {
 
 func checkNonblocking(t *testing.T, fd int32, name string) {
        t.Helper()
-       flags, errno := fcntl(uintptr(fd), syscall.F_GETFL, 0)
-       if errno != 0 {
-               t.Errorf("fcntl(%s, F_GETFL) failed: %v", name, syscall.Errno(errno))
+       flags := runtime.Fcntl(fd, syscall.F_GETFL, 0)
+       if flags < 0 {
+               t.Errorf("fcntl(%s, F_GETFL) failed: %v", name, syscall.Errno(-flags))
        } else if flags&syscall.O_NONBLOCK == 0 {
                t.Errorf("O_NONBLOCK not set in %s flags %#x", name, flags)
        }
@@ -59,9 +65,9 @@ func checkNonblocking(t *testing.T, fd int32, name string) {
 
 func checkCloseonexec(t *testing.T, fd int32, name string) {
        t.Helper()
-       flags, errno := fcntl(uintptr(fd), syscall.F_GETFD, 0)
-       if errno != 0 {
-               t.Errorf("fcntl(%s, F_GETFD) failed: %v", name, syscall.Errno(errno))
+       flags := runtime.Fcntl(fd, syscall.F_GETFD, 0)
+       if flags < 0 {
+               t.Errorf("fcntl(%s, F_GETFD) failed: %v", name, syscall.Errno(flags))
        } else if flags&syscall.FD_CLOEXEC == 0 {
                t.Errorf("FD_CLOEXEC not set in %s flags %#x", name, flags)
        }
index d835cd9bf09c3715d075713db9efde3caa888a4b..fad7f78050a1a318709b987035dad319e3ec16da 100644 (file)
@@ -95,10 +95,6 @@ func errno() int32 {
        return *getg().m.perrno
 }
 
-func fcntl(fd, cmd, arg int32) int32 {
-       return int32(sysvicall3(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg)))
-}
-
 func port_create() int32 {
        return int32(sysvicall0(&libc_port_create))
 }
index ffac4b6492b87cc51ded27da824f05373e1adba0..219e02d8351b581fad4c0ce336f0b779ba18e15f 100644 (file)
@@ -569,6 +569,15 @@ func pipe2(flags int32) (r, w int32, errno int32) {
        return p[0], p[1], int32(e)
 }
 
+//go:nosplit
+func fcntl(fd, cmd, arg int32) int32 {
+       r1, err := sysvicall3Err(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg))
+       if r := int32(r1); r >= 0 {
+               return r
+       }
+       return -int32(err)
+}
+
 //go:nosplit
 func closeonexec(fd int32) {
        fcntl(fd, _F_SETFD, _FD_CLOEXEC)
index e07c7f1da665b5717b8df1b4966c9f83f60300d3..56b77e955a08fe2e868f58601fcac38fb620cecd 100644 (file)
@@ -353,7 +353,10 @@ func walltime() (sec int64, nsec int32) {
 
 //go:nosplit
 func fcntl(fd, cmd, arg int32) int32 {
-       r, _ := syscall3(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg))
+       r, errno := syscall3(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg))
+       if int32(r) < 0 {
+               return -int32(errno)
+       }
        return int32(r)
 }
 
index e467578c32a8c0e4c5958663c33dbca1ef807777..ff73e0683a78a1834be72442b3251eb5efcd1e2b 100644 (file)
@@ -63,6 +63,7 @@ func kqueue() int32
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
 
 func pipe2(flags int32) (r, w int32, errno int32)
+func fcntl(fd, cmd, arg int32) int32
 func closeonexec(fd int32)
 
 // From DragonFly's <sys/sysctl.h>
index f53cb115a157df9d83ec737344313c84c5c485a6..efc44c16e9938743a902c7579c178dba1c1b05f1 100644 (file)
@@ -48,6 +48,7 @@ func kqueue() int32
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
 
 func pipe2(flags int32) (r, w int32, errno int32)
+func fcntl(fd, cmd, arg int32) int32
 func closeonexec(fd int32)
 
 // From FreeBSD's <sys/sysctl.h>
index 3ad1e3b8fcd1d15e35c28129b46b16eb51bbb4b4..a7d2cc5becccc2033db55db2eabd20bd5af4bae4 100644 (file)
@@ -461,6 +461,16 @@ func osyield_no_g() {
 
 func pipe2(flags int32) (r, w int32, errno int32)
 
+//go:nosplit
+func fcntl(fd, cmd, arg int32) int32 {
+       r, _, errno := syscall.Syscall6(syscall.SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg), 0, 0, 0)
+       ri := int32(r)
+       if ri < 0 {
+               return -int32(errno)
+       }
+       return ri
+}
+
 const (
        _si_max_size    = 128
        _sigev_max_size = 64
index ce59618af4adb581ae21379e60fe8e9137b4100e..d56e0e36acbc0d6c2265578d2a74a562538b1afe 100644 (file)
@@ -79,6 +79,7 @@ func kqueue() int32
 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
 
 func pipe2(flags int32) (r, w int32, errno int32)
+func fcntl(fd, cmd, arg int32) int32
 func closeonexec(fd int32)
 
 const (
index ebf478badf8652bb56c1bf3200f00dccd0b0be14..0b61773c9d2edb3382ab5f431bfacd59ce3cd95c 100644 (file)
@@ -95,6 +95,7 @@ func nanotime1() int64
 //go:noescape
 func sigaltstack(new, old *stackt)
 
+func fcntl(fd, cmd, arg int32) int32
 func closeonexec(fd int32)
 
 func walltime() (sec int64, nsec int32)
index 8ac1b08f690a8ab59851fb5f0bc3c1406e9b2ae9..9e13c2903afe37c5c49a1870111603a93b28f07a 100644 (file)
@@ -149,7 +149,7 @@ func sysvicall3(fn *libcFunc, a1, a2, a3 uintptr) uintptr {
 //go:cgo_unsafe_args
 
 // sysvicall3Err returns both the system call result and the errno value.
-// This is used by sysicall3 and write1.
+// This is used by sysvicall3 and write1.
 func sysvicall3Err(fn *libcFunc, a1, a2, a3 uintptr) (r1, err uintptr) {
        // Leave caller's PC/SP around for traceback.
        gp := getg()
index 6eaeeb915f7e242037c7274c6a08e093c05f3c21..e97811c9abc4bd77c1326eed1bfff6bbad1ae608 100644 (file)
@@ -437,6 +437,12 @@ TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
        MOVL    0(DI), DI               // arg 1 fd
        XORL    AX, AX                  // vararg: say "no float args"
        CALL    libc_fcntl(SB)
+       TESTL   AX, AX
+       JGT     noerr
+       CALL    libc_error(SB)
+       MOVL    (AX), AX
+       NEGL    AX                      // caller expects negative errno value
+noerr:
        POPQ    BP
        RET
 
index 4a51fb3a86349a85a976d4bce8c439f0c510366c..4111b3427bd5564c2069e876b01e4bb5183f382c 100644 (file)
@@ -314,6 +314,13 @@ TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
        MOVW    R2, (RSP)       // arg 3 is variadic, pass on stack
        MOVW    0(R0), R0       // arg 1 fd
        BL      libc_fcntl(SB)
+       MOVD    $-1, R1
+       CMP     R0, R1
+       BNE     noerr
+       BL      libc_error(SB)
+       MOVW    (R0), R0
+       NEG     R0, R0          // caller expects negative errno value
+noerr:
        ADD     $16, RSP
        RET
 
index 0cf98219fb013dffec961b9b72ba4f1a05ba097a..e3d85ab062acc8546b7f9eef7fb1290302daf478 100644 (file)
@@ -387,6 +387,18 @@ TEXT runtime·kevent(SB),NOSPLIT,$0
        MOVL    AX, ret+48(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVL    fd+0(FP), DI    // fd
+       MOVL    cmd+4(FP), SI   // cmd
+       MOVL    arg+8(FP), DX   // arg
+       MOVL    $92, AX         // fcntl
+       SYSCALL
+       JCC     2(PC)
+       NEGL    AX              // caller expects negative errno
+       MOVL    AX, ret+16(FP)
+       RET
+
 // void runtime·closeonexec(int32 fd);
 TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVL    fd+0(FP), DI    // fd
index 4e0bc9b08c505164f46be9ccce722fe10935a7b9..55c299f36f75b431d740452f7d1bd0f942fb4a77 100644 (file)
@@ -451,6 +451,15 @@ TEXT runtime·kevent(SB),NOSPLIT,$0
        MOVL    AX, ret+24(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$-4
+       MOVL    $SYS_fcntl, AX
+       INT     $0x80
+       JAE     2(PC)
+       NEGL    AX                      // caller expects negative errno
+       MOVL    AX, ret+12(FP)
+       RET
+
 // int32 runtime·closeonexec(int32 fd);
 TEXT runtime·closeonexec(SB),NOSPLIT,$32
        MOVL    $SYS_fcntl, AX
index 374e0ab769ff30ed7e43bea767afe4812b8fa20e..cd4029a72dd19a42fbb63c46d8d8ac48bec13047 100644 (file)
@@ -550,6 +550,18 @@ TEXT runtime·kevent(SB),NOSPLIT,$0
        MOVL    AX, ret+48(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVL    fd+0(FP), DI    // fd
+       MOVL    cmd+4(FP), SI   // cmd
+       MOVL    arg+8(FP), DX   // arg
+       MOVL    $SYS_fcntl, AX
+       SYSCALL
+       JCC     2(PC)
+       NEGQ    AX              // caller expects negative errno
+       MOVL    AX, ret+16(FP)
+       RET
+
 // void runtime·closeonexec(int32 fd);
 TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVL    fd+0(FP), DI    // fd
index a3fee1426c43ab016264677b886e5e5203ae16a5..2da092ad8ea09cf8194886882aff506592bb84b2 100644 (file)
@@ -387,6 +387,17 @@ TEXT runtime·kevent(SB),NOSPLIT,$0
        MOVW    R0, ret+24(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVW fd+0(FP), R0       // fd
+       MOVW cmd+4(FP), R1      // cmd
+       MOVW arg+8(FP), R2      // arg
+       MOVW $SYS_fcntl, R7
+       SWI $0
+       RSB.CS $0, R0           // caller expects negative errno
+       MOVW R0, ret+12(FP)
+       RET
+
 // void runtime·closeonexec(int32 fd)
 TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVW fd+0(FP), R0       // fd
index 29866cb4ca4a7d68e92d92083a1c12a340564355..6fb07bbd08d94a90e7643da159efc9d0795e9ac5 100644 (file)
@@ -444,6 +444,19 @@ ok:
        MOVW    R0, ret+48(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVW    fd+0(FP), R0
+       MOVW    cmd+4(FP), R1
+       MOVW    arg+8(FP), R2
+       MOVD    $SYS_fcntl, R8
+       SVC
+       BCC     ok
+       NEG     R0, R0          // caller expects negative errno
+ok:
+       MOVW    R0, ret+16(FP)
+       RET
+
 // func closeonexec(fd int32)
 TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
        MOVW    fd+0(FP), R0
index 30deed2573a99e301339eea5cd9509a6ba6f68df..0d3a0a83fb8b3377feb2946efff3ca6d8203761b 100644 (file)
@@ -420,6 +420,19 @@ ok:
        MOVW    A0, ret+48(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVW    fd+0(FP), A0
+       MOVW    cmd+4(FP), A1
+       MOVW    arg+8(FP), A2
+       MOV     $SYS_fcntl, T0
+       ECALL
+       BEQ     T0, ZERO, ok
+       NEG     A0, A0          // caller expects negative errno
+ok:
+       MOVW    A0, ret+16(FP)
+       RET
+
 // func closeonexec(fd int32)
 TEXT runtime·closeonexec(SB),NOSPLIT|NOFRAME,$0
        MOVW    fd+0(FP), A0
index 7be18c61d8b99b0c9e0eb5e3fdb5f6214d5462e3..a05e1d44787294c4480a8a7a1aaa47bd9c2ccc29 100644 (file)
@@ -457,6 +457,15 @@ TEXT runtime·kevent(SB),NOSPLIT,$0
        MOVL    AX, ret+24(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$-4
+       MOVL    $SYS_fcntl, AX
+       INT     $0x80
+       JAE     2(PC)
+       NEGL    AX                      // caller expects negative errno
+       MOVL    AX, ret+12(FP)
+       RET
+
 // int32 runtime·closeonexec(int32 fd)
 TEXT runtime·closeonexec(SB),NOSPLIT,$32
        MOVL    $SYS_fcntl, AX
index 30f3f380b6fc98566a1c3a61130112a82b5dd238..368eef56edf5929331326a1ce295da875910e011 100644 (file)
@@ -434,6 +434,18 @@ TEXT runtime·kevent(SB),NOSPLIT,$0
        MOVL    AX, ret+48(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int2
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVL    fd+0(FP), DI    // fd
+       MOVL    cmd+4(FP), SI   // cmd
+       MOVL    arg+8(FP), DX   // arg
+       MOVL    $SYS_fcntl, AX
+       SYSCALL
+       JCC     2(PC)
+       NEGQ    AX              // caller expects negative errno
+       MOVL    AX, ret+16(FP)
+       RET
+
 // void runtime·closeonexec(int32 fd)
 TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVL    fd+0(FP), DI    // fd
index 62fa852adddf3625ccd54b9aee11cf0369122832..f9cbcb6df1bdcd3a8bb189cbd36410e479a242fa 100644 (file)
@@ -398,6 +398,16 @@ TEXT runtime·kevent(SB),NOSPLIT,$8
        MOVW    R0, ret+24(FP)
        RET
 
+// func fcntl(fd, cmd, args int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVW fd+0(FP), R0
+       MOVW cmd+4(FP), R1
+       MOVW arg+8(FP), R2
+       SWI $SYS_fcntl
+       RSB.CS $0, R0           // caller expects negative errno
+       MOVW R0, ret+12(FP)
+       RET
+
 // void runtime·closeonexec(int32 fd)
 TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVW fd+0(FP), R0       // fd
index d57959f8d76d5559f17b182393eb035db7aca341..d27133550a877d984b847ed0e06e02cc7900c2ce 100644 (file)
@@ -421,6 +421,18 @@ ok:
        MOVW    R0, ret+48(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVW    fd+0(FP), R0    // fd
+       MOVW    cmd+4(FP), R1   // cmd
+       MOVW    arg+8(FP), R2   // arg
+       SVC     $SYS_fcntl
+       BCC     ok
+       NEG     R0, R0          // caller expects negative errno
+ok:
+       MOVW    R0, ret+16(FP)
+       RET
+
 // void runtime·closeonexec(int32 fd)
 TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVW    fd+0(FP), R0            // arg 1 - fd
index 963678a2c3c8a82c812173f8a06a48a9a2d25431..3e5dbc2b0a8496aa81c4a7f75c1d79ebb58e3f34 100644 (file)
@@ -542,6 +542,12 @@ TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
        MOVL    CX, 8(SP)               // arg 3 - arg
        MOVL    $0, 12(SP)              // vararg
        CALL    libc_fcntl(SB)
+       CMPL    AX, $-1
+       JNE     noerr
+       CALL    libc_errno(SB)
+       MOVL    (AX), AX
+       NEGL    AX                      // caller expects negative errno
+noerr:
        MOVL    BP, SP
        POPL    BP
        RET
index 2c026c8d0dba63327c373bc80f06a96277427d52..35a57c026b6501a228effd77fd9ecb576d3a54c5 100644 (file)
@@ -393,6 +393,12 @@ TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
        MOVL    0(DI), DI               // arg 1 fd
        XORL    AX, AX                  // vararg: say "no float args"
        CALL    libc_fcntl(SB)
+       TESTL   AX, AX
+       JGE     noerr
+       CALL    libc_errno(SB)
+       MOVL    (AX), AX
+       NEGL    AX                      // caller expects negative errno value
+noerr:
        POPQ    BP
        RET
 
index e03cfb52f60fdf67589adbb21b213f8ddaba7684..3568d4eb941692e70c210744f4ab1a582c5f131a 100644 (file)
@@ -424,6 +424,12 @@ TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
        MOVW    R2, 0(R13)
        MOVW    0(R0), R0               // arg 1 fd
        BL      libc_fcntl(SB)
+       CMP     $-1, R0
+       BNE     noerr
+       BL      libc_errno(SB)
+       MOVW    (R0), R0
+       RSB.CS  $0, R0                  // caller expects negative errno
+noerr:
        MOVW    R9, R13
        RET
 
index db92326efbaec588359666132b7b60de19a6247a..0bd801ff7a98e6df248c6e8ac6a8759f524d1b3b 100644 (file)
@@ -311,6 +311,12 @@ TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
        MOVW    0(R0), R0               // arg 1 - fd
        MOVD    $0, R3                  // vararg
        CALL    libc_fcntl(SB)
+       CMP     $-1, R0
+       BNE     noerr
+       CALL    libc_errno(SB)
+       MOVW    (R0), R0
+       NEG     R0, R0                  // caller expects negative errno value
+noerr:
        RET
 
 TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0
index affd586742ef0408effb66a6717dc6ae84abbe2e..0ba53cd37d5e68805085c2a605264171e9d24bb3 100644 (file)
@@ -364,6 +364,18 @@ TEXT runtime·kevent(SB),NOSPLIT,$0
        MOVW    R2, ret+48(FP)
        RET
 
+// func fcntl(fd, cmd, arg int32) int32
+TEXT runtime·fcntl(SB),NOSPLIT,$0
+       MOVW    fd+0(FP), R4    // fd
+       MOVW    cmd+4(FP), R5   // cmd
+       MOVW    arg+8(FP), R6   // arg
+       MOVV    $92, R2         // sys_fcntl
+       SYSCALL
+       BEQ     R7, 2(PC)
+       SUBVU   R2, R0, R2      // caller expects negative errno
+       MOVW    R2, ret+16(FP)
+       RET
+
 // func closeonexec(fd int32)
 TEXT runtime·closeonexec(SB),NOSPLIT,$0
        MOVW    fd+0(FP), R4            // arg 1 - fd