]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.19] 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:40 +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/+/497135
Auto-Submit: Heschi Kreinick <heschi@google.com>
Run-TryBot: Roland Shoemaker <roland@golang.org>

42 files changed:
src/runtime/export_aix_test.go
src/runtime/export_darwin_test.go
src/runtime/export_solaris_test.go [deleted file]
src/runtime/export_unix_test.go
src/runtime/internal/syscall/defs_linux_386.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_amd64.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_arm.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_arm64.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_loong64.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_mips64x.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_mipsx.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_ppc64x.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_riscv64.go [new file with mode: 0644]
src/runtime/internal/syscall/defs_linux_s390x.go [new file with mode: 0644]
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_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_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 a548cf7b7a5ccefad2d9292c19d961bc0414ccac..8fe95770cdb6d165fe0bafa4ea270a04dd0161ee 100644 (file)
@@ -10,6 +10,7 @@ import "unsafe"
 
 var NonblockingPipe = nonblockingPipe
 var Closeonexec = closeonexec
+var Fcntl = fcntl
 
 func sigismember(mask *sigset, i int) bool {
        clear := *mask
diff --git a/src/runtime/internal/syscall/defs_linux_386.go b/src/runtime/internal/syscall/defs_linux_386.go
new file mode 100644 (file)
index 0000000..31d704e
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2023 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 syscall
+
+const SYS_FCNTL = 55
diff --git a/src/runtime/internal/syscall/defs_linux_amd64.go b/src/runtime/internal/syscall/defs_linux_amd64.go
new file mode 100644 (file)
index 0000000..2368eb0
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2023 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 syscall
+
+const SYS_FCNTL = 72
diff --git a/src/runtime/internal/syscall/defs_linux_arm.go b/src/runtime/internal/syscall/defs_linux_arm.go
new file mode 100644 (file)
index 0000000..31d704e
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2023 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 syscall
+
+const SYS_FCNTL = 55
diff --git a/src/runtime/internal/syscall/defs_linux_arm64.go b/src/runtime/internal/syscall/defs_linux_arm64.go
new file mode 100644 (file)
index 0000000..6292c90
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2023 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 syscall
+
+const SYS_FCNTL = 25
diff --git a/src/runtime/internal/syscall/defs_linux_loong64.go b/src/runtime/internal/syscall/defs_linux_loong64.go
new file mode 100644 (file)
index 0000000..6292c90
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2023 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 syscall
+
+const SYS_FCNTL = 25
diff --git a/src/runtime/internal/syscall/defs_linux_mips64x.go b/src/runtime/internal/syscall/defs_linux_mips64x.go
new file mode 100644 (file)
index 0000000..38d2acb
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2023 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 linux && (mips64 || mips64le)
+
+package syscall
+
+const SYS_FCNTL = 5070
diff --git a/src/runtime/internal/syscall/defs_linux_mipsx.go b/src/runtime/internal/syscall/defs_linux_mipsx.go
new file mode 100644 (file)
index 0000000..e4eb0d7
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2023 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 linux && (mips || mipsle)
+
+package syscall
+
+const SYS_FCNTL = 4055
diff --git a/src/runtime/internal/syscall/defs_linux_ppc64x.go b/src/runtime/internal/syscall/defs_linux_ppc64x.go
new file mode 100644 (file)
index 0000000..cc45a3d
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2023 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 linux && (ppc64 || ppc64le)
+
+package syscall
+
+const SYS_FCNTL = 55
diff --git a/src/runtime/internal/syscall/defs_linux_riscv64.go b/src/runtime/internal/syscall/defs_linux_riscv64.go
new file mode 100644 (file)
index 0000000..6292c90
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2023 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 syscall
+
+const SYS_FCNTL = 25
diff --git a/src/runtime/internal/syscall/defs_linux_s390x.go b/src/runtime/internal/syscall/defs_linux_s390x.go
new file mode 100644 (file)
index 0000000..31d704e
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2023 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 syscall
+
+const SYS_FCNTL = 55
diff --git a/src/runtime/nbpipe_fcntl_libc_test.go b/src/runtime/nbpipe_fcntl_libc_test.go
deleted file mode 100644 (file)
index a9c8987..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 || 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 97607fa..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
-
-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 6e545b3d31b283ed03efb222b9e56d4aa5dd40b2..034363ea1cdbcef645822b19f1324084aed37dd2 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 79f6b18c9ae497fe5a62f2b25e80241452343d50..783a2949760cbca83b0f6206d419dc8ca773fc59 100644 (file)
@@ -568,6 +568,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 104c397e8c050bd07dc1cf784cdacab8d83a4b64..66b4d94cf20acb609623554046b2986206cc02a5 100644 (file)
@@ -362,7 +362,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 83478143b933b14e57ea1ed3a88d546038c44325..728d2bcdab14989609a9bc06179169a5727b41ea 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 23efd1a46e83493ff658db41bad949547920c760..94a6de2cdfd3cb5026b0db2da4b4d0bd2b024b9f 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 25aea6522dc5fc2f64a892bf85463843a361253d..af4a0922c9262ad4de15300f2358bc9b32879360 100644 (file)
@@ -456,6 +456,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 3cbace38f997018e01e16120334848a97e357e69..34f43ddecb9075bd0b4e28f2798e93cf5919f3ff 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 ab6b1818285c067cc48330603a733b031e9d7d87..c2a43bac8baa6efc4042654270e37099c0ed321b 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 ba81fcc35c4424b8ec3d6c07b30a6be8e0200817..3ba673c5eceaa623a5ba719d7c4455baef381d33 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 bf0dc9d8ccb6ce7ba5f3c4d73bcf04935e188245..5f8e824395856265f7c8399ce0db4f3c57d3dc8b 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 d10eb3fa4b25e9749b78cb75cb66478f7ed7e334..3375fc1faedb25714baaab56d590dae914ea08bc 100644 (file)
@@ -415,6 +415,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    $92, 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    $92, AX         // fcntl
index 9f48d585145fc9964660ee472d9a33cbd70c5293..55e7e250ae9c258b3396188c1c701825240208dc 100644 (file)
@@ -483,6 +483,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
+       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 a6099b465cc3147d9d38f69b0b91b0d49a7aec1f..725303a8acf1e00e69c4b4aa6827290ef846c7cb 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 4143a8f1eb40ee1c30e97e76f3bfe886ba35c619..4521ac61e41fc842680dc2f43c5030e925cd1d8d 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 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 cc37e52e16150ec558770bf59ae6f6dfddf05280..0ddcac55954d3a16853d002d2a1c02b51d43f0a7 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