Skip to content

Commit 768170e

Browse files
committed
Merge remote-tracking branch 'upstream/release-branch.go1.19' into fancybits-1.19
2 parents 1cb5930 + 65cc8e6 commit 768170e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+361
-94
lines changed

src/runtime/export_aix_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
package runtime
66

7-
var Fcntl = syscall_fcntl1
87
var SetNonblock = setNonblock

src/runtime/export_darwin_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,4 @@
44

55
package runtime
66

7-
func Fcntl(fd, cmd, arg uintptr) (uintptr, uintptr) {
8-
r := fcntl(int32(fd), int32(cmd), int32(arg))
9-
if r < 0 {
10-
return ^uintptr(0), uintptr(-r)
11-
}
12-
return uintptr(r), 0
13-
}
14-
157
var SetNonblock = setNonblock

src/runtime/export_solaris_test.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/runtime/export_unix_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import "unsafe"
1010

1111
var NonblockingPipe = nonblockingPipe
1212
var Closeonexec = closeonexec
13+
var Fcntl = fcntl
1314

1415
func sigismember(mask *sigset, i int) bool {
1516
clear := *mask
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package syscall
6+
7+
const SYS_FCNTL = 55
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package syscall
6+
7+
const SYS_FCNTL = 72
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package syscall
6+
7+
const SYS_FCNTL = 55
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package syscall
6+
7+
const SYS_FCNTL = 25
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package syscall
6+
7+
const SYS_FCNTL = 25
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build linux && (mips64 || mips64le)
6+
7+
package syscall
8+
9+
const SYS_FCNTL = 5070
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build linux && (mips || mipsle)
6+
7+
package syscall
8+
9+
const SYS_FCNTL = 4055
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build linux && (ppc64 || ppc64le)
6+
7+
package syscall
8+
9+
const SYS_FCNTL = 55
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package syscall
6+
7+
const SYS_FCNTL = 25
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package syscall
6+
7+
const SYS_FCNTL = 55

src/runtime/nbpipe_fcntl_libc_test.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/runtime/nbpipe_fcntl_unix_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/runtime/nbpipe_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,29 @@ import (
1414
)
1515

1616
func TestNonblockingPipe(t *testing.T) {
17-
t.Parallel()
18-
1917
// NonblockingPipe is the test name for nonblockingPipe.
2018
r, w, errno := runtime.NonblockingPipe()
2119
if errno != 0 {
2220
t.Fatal(syscall.Errno(errno))
2321
}
24-
defer func() {
25-
runtime.Close(r)
26-
runtime.Close(w)
27-
}()
22+
defer runtime.Close(w)
2823

2924
checkIsPipe(t, r, w)
3025
checkNonblocking(t, r, "reader")
3126
checkCloseonexec(t, r, "reader")
3227
checkNonblocking(t, w, "writer")
3328
checkCloseonexec(t, w, "writer")
29+
30+
// Test that fcntl returns an error as expected.
31+
if runtime.Close(r) != 0 {
32+
t.Fatalf("Close(%d) failed", r)
33+
}
34+
val, errno := runtime.Fcntl(r, syscall.F_GETFD, 0)
35+
if val != -1 {
36+
t.Errorf("Fcntl succeeded unexpectedly")
37+
} else if syscall.Errno(errno) != syscall.EBADF {
38+
t.Errorf("Fcntl failed with error %v, expected %v", syscall.Errno(errno), syscall.EBADF)
39+
}
3440
}
3541

3642
func checkIsPipe(t *testing.T, r, w int32) {
@@ -49,8 +55,8 @@ func checkIsPipe(t *testing.T, r, w int32) {
4955

5056
func checkNonblocking(t *testing.T, fd int32, name string) {
5157
t.Helper()
52-
flags, errno := fcntl(uintptr(fd), syscall.F_GETFL, 0)
53-
if errno != 0 {
58+
flags, errno := runtime.Fcntl(fd, syscall.F_GETFL, 0)
59+
if flags == -1 {
5460
t.Errorf("fcntl(%s, F_GETFL) failed: %v", name, syscall.Errno(errno))
5561
} else if flags&syscall.O_NONBLOCK == 0 {
5662
t.Errorf("O_NONBLOCK not set in %s flags %#x", name, flags)
@@ -59,8 +65,8 @@ func checkNonblocking(t *testing.T, fd int32, name string) {
5965

6066
func checkCloseonexec(t *testing.T, fd int32, name string) {
6167
t.Helper()
62-
flags, errno := fcntl(uintptr(fd), syscall.F_GETFD, 0)
63-
if errno != 0 {
68+
flags, errno := runtime.Fcntl(fd, syscall.F_GETFD, 0)
69+
if flags == -1 {
6470
t.Errorf("fcntl(%s, F_GETFD) failed: %v", name, syscall.Errno(errno))
6571
} else if flags&syscall.FD_CLOEXEC == 0 {
6672
t.Errorf("FD_CLOEXEC not set in %s flags %#x", name, flags)

src/runtime/netpoll_solaris.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ func errno() int32 {
9595
return *getg().m.perrno
9696
}
9797

98-
func fcntl(fd, cmd, arg int32) int32 {
99-
return int32(sysvicall3(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg)))
100-
}
101-
10298
func port_create() int32 {
10399
return int32(sysvicall0(&libc_port_create))
104100
}

src/runtime/os3_solaris.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,12 @@ func pipe2(flags int32) (r, w int32, errno int32) {
568568
return p[0], p[1], int32(e)
569569
}
570570

571+
//go:nosplit
572+
func fcntl(fd, cmd, arg int32) (ret int32, errno int32) {
573+
r1, err := sysvicall3Err(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg))
574+
return int32(r1), int32(err)
575+
}
576+
571577
//go:nosplit
572578
func closeonexec(fd int32) {
573579
fcntl(fd, _F_SETFD, _FD_CLOEXEC)

src/runtime/os_aix.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ func walltime() (sec int64, nsec int32) {
361361
}
362362

363363
//go:nosplit
364-
func fcntl(fd, cmd, arg int32) int32 {
365-
r, _ := syscall3(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg))
366-
return int32(r)
364+
func fcntl(fd, cmd, arg int32) (int32, int32) {
365+
r, errno := syscall3(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg))
366+
return int32(r), int32(errno)
367367
}
368368

369369
//go:nosplit
@@ -373,8 +373,10 @@ func closeonexec(fd int32) {
373373

374374
//go:nosplit
375375
func setNonblock(fd int32) {
376-
flags := fcntl(fd, _F_GETFL, 0)
377-
fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
376+
flags, _ := fcntl(fd, _F_GETFL, 0)
377+
if flags != -1 {
378+
fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
379+
}
378380
}
379381

380382
// sigPerThreadSyscall is only used on linux, so we assign a bogus signal

src/runtime/os_dragonfly.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func kqueue() int32
6363
func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
6464

6565
func pipe2(flags int32) (r, w int32, errno int32)
66+
func fcntl(fd, cmd, arg int32) (ret int32, errno int32)
6667
func closeonexec(fd int32)
6768

6869
// From DragonFly's <sys/sysctl.h>

src/runtime/os_freebsd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func kqueue() int32
4848
func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
4949

5050
func pipe2(flags int32) (r, w int32, errno int32)
51+
func fcntl(fd, cmd, arg int32) (ret int32, errno int32)
5152
func closeonexec(fd int32)
5253

5354
// From FreeBSD's <sys/sysctl.h>

src/runtime/os_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ func osyield_no_g() {
456456

457457
func pipe2(flags int32) (r, w int32, errno int32)
458458

459+
//go:nosplit
460+
func fcntl(fd, cmd, arg int32) (ret int32, errno int32) {
461+
r, _, err := syscall.Syscall6(syscall.SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg), 0, 0, 0)
462+
return int32(r), int32(err)
463+
}
464+
459465
const (
460466
_si_max_size = 128
461467
_sigev_max_size = 64

src/runtime/os_netbsd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func kqueue() int32
7979
func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
8080

8181
func pipe2(flags int32) (r, w int32, errno int32)
82+
func fcntl(fd, cmd, arg int32) (ret int32, errno int32)
8283
func closeonexec(fd int32)
8384

8485
const (

src/runtime/os_openbsd_syscall2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func nanotime1() int64
9595
//go:noescape
9696
func sigaltstack(new, old *stackt)
9797

98+
func fcntl(fd, cmd, arg int32) (ret int32, errno int32)
9899
func closeonexec(fd int32)
99100

100101
func walltime() (sec int64, nsec int32)

src/runtime/os_solaris.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func sysvicall3(fn *libcFunc, a1, a2, a3 uintptr) uintptr {
149149
//go:cgo_unsafe_args
150150

151151
// sysvicall3Err returns both the system call result and the errno value.
152-
// This is used by sysicall3 and write1.
152+
// This is used by sysvicall3 and write1.
153153
func sysvicall3Err(fn *libcFunc, a1, a2, a3 uintptr) (r1, err uintptr) {
154154
// Leave caller's PC/SP around for traceback.
155155
gp := getg()

src/runtime/sys_darwin.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,13 @@ func sysctlbyname_trampoline()
382382

383383
//go:nosplit
384384
//go:cgo_unsafe_args
385-
func fcntl(fd, cmd, arg int32) int32 {
386-
return libcCall(unsafe.Pointer(abi.FuncPCABI0(fcntl_trampoline)), unsafe.Pointer(&fd))
385+
func fcntl(fd, cmd, arg int32) (ret int32, errno int32) {
386+
args := struct {
387+
fd, cmd, arg int32
388+
ret, errno int32
389+
}{fd, cmd, arg, 0, 0}
390+
libcCall(unsafe.Pointer(abi.FuncPCABI0(fcntl_trampoline)), unsafe.Pointer(&args))
391+
return args.ret, args.errno
387392
}
388393
func fcntl_trampoline()
389394

@@ -485,8 +490,10 @@ func closeonexec(fd int32) {
485490

486491
//go:nosplit
487492
func setNonblock(fd int32) {
488-
flags := fcntl(fd, _F_GETFL, 0)
489-
fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
493+
flags, _ := fcntl(fd, _F_GETFL, 0)
494+
if flags != -1 {
495+
fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
496+
}
490497
}
491498

492499
// Tell the linker that the libc_* functions are to be found

src/runtime/sys_darwin_amd64.s

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,21 @@ ok:
430430
TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
431431
PUSHQ BP
432432
MOVQ SP, BP
433-
MOVL 4(DI), SI // arg 2 cmd
434-
MOVL 8(DI), DX // arg 3 arg
435-
MOVL 0(DI), DI // arg 1 fd
433+
MOVQ DI, BX
434+
MOVL 0(BX), DI // arg 1 fd
435+
MOVL 4(BX), SI // arg 2 cmd
436+
MOVL 8(BX), DX // arg 3 arg
436437
XORL AX, AX // vararg: say "no float args"
437438
CALL libc_fcntl(SB)
439+
XORL DX, DX
440+
CMPQ AX, $-1
441+
JNE noerr
442+
CALL libc_error(SB)
443+
MOVL (AX), DX
444+
MOVL $-1, AX
445+
noerr:
446+
MOVL AX, 12(BX)
447+
MOVL DX, 16(BX)
438448
POPQ BP
439449
RET
440450

0 commit comments

Comments
 (0)