Skip to content

Commit b849f9b

Browse files
committed
unix: use fcntl(2) libc stub on OpenBSD
Future OpenBSD releases will remove the syscall(2) interface. This converts the Fcntl functions to use fcntl(2) from libc, rather than indirectly through syscall(2). Updates #63569.
1 parent 249e16f commit b849f9b

17 files changed

+254
-1
lines changed

unix/fcntl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build dragonfly || freebsd || linux || netbsd || openbsd
5+
//go:build dragonfly || freebsd || linux || netbsd
66

77
package unix
88

unix/fcntl_openbsd.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2019 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 unix
6+
7+
import "unsafe"
8+
9+
// FcntlInt performs a fcntl syscall on fd with the provided command and argument.
10+
func FcntlInt(fd uintptr, cmd, arg int) (int, error) {
11+
return fcntl(int(fd), cmd, arg)
12+
}
13+
14+
// FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
15+
func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error {
16+
_, err := fcntlPtr(int(fd), cmd, unsafe.Pointer(lk))
17+
return err
18+
}

unix/syscall_openbsd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ func Getresgid() (rgid, egid, sgid int) {
171171

172172
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
173173

174+
//sys fcntl(fd int, cmd int, arg int) (n int, err error)
175+
//sys fcntlPtr(fd int, cmd int, arg unsafe.Pointer) (n int, err error) = SYS_FCNTL
176+
174177
//sys ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error)
175178

176179
func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error) {

unix/zsyscall_openbsd_386.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_openbsd_386.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0
178178
GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $4
179179
DATA ·libc_sysctl_trampoline_addr(SB)/4, $libc_sysctl_trampoline<>(SB)
180180

181+
TEXT libc_fcntl_trampoline<>(SB),NOSPLIT,$0-0
182+
JMP libc_fcntl(SB)
183+
GLOBL ·libc_fcntl_trampoline_addr(SB), RODATA, $4
184+
DATA ·libc_fcntl_trampoline_addr(SB)/4, $libc_fcntl_trampoline<>(SB)
185+
181186
TEXT libc_ppoll_trampoline<>(SB),NOSPLIT,$0-0
182187
JMP libc_ppoll(SB)
183188
GLOBL ·libc_ppoll_trampoline_addr(SB), RODATA, $4

unix/zsyscall_openbsd_amd64.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_openbsd_amd64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0
178178
GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8
179179
DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB)
180180

181+
TEXT libc_fcntl_trampoline<>(SB),NOSPLIT,$0-0
182+
JMP libc_fcntl(SB)
183+
GLOBL ·libc_fcntl_trampoline_addr(SB), RODATA, $8
184+
DATA ·libc_fcntl_trampoline_addr(SB)/8, $libc_fcntl_trampoline<>(SB)
185+
181186
TEXT libc_ppoll_trampoline<>(SB),NOSPLIT,$0-0
182187
JMP libc_ppoll(SB)
183188
GLOBL ·libc_ppoll_trampoline_addr(SB), RODATA, $8

unix/zsyscall_openbsd_arm.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_openbsd_arm.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0
178178
GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $4
179179
DATA ·libc_sysctl_trampoline_addr(SB)/4, $libc_sysctl_trampoline<>(SB)
180180

181+
TEXT libc_fcntl_trampoline<>(SB),NOSPLIT,$0-0
182+
JMP libc_fcntl(SB)
183+
GLOBL ·libc_fcntl_trampoline_addr(SB), RODATA, $4
184+
DATA ·libc_fcntl_trampoline_addr(SB)/4, $libc_fcntl_trampoline<>(SB)
185+
181186
TEXT libc_ppoll_trampoline<>(SB),NOSPLIT,$0-0
182187
JMP libc_ppoll(SB)
183188
GLOBL ·libc_ppoll_trampoline_addr(SB), RODATA, $4

unix/zsyscall_openbsd_arm64.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_openbsd_arm64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0
178178
GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8
179179
DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB)
180180

181+
TEXT libc_fcntl_trampoline<>(SB),NOSPLIT,$0-0
182+
JMP libc_fcntl(SB)
183+
GLOBL ·libc_fcntl_trampoline_addr(SB), RODATA, $8
184+
DATA ·libc_fcntl_trampoline_addr(SB)/8, $libc_fcntl_trampoline<>(SB)
185+
181186
TEXT libc_ppoll_trampoline<>(SB),NOSPLIT,$0-0
182187
JMP libc_ppoll(SB)
183188
GLOBL ·libc_ppoll_trampoline_addr(SB), RODATA, $8

unix/zsyscall_openbsd_mips64.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_openbsd_mips64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0
178178
GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8
179179
DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB)
180180

181+
TEXT libc_fcntl_trampoline<>(SB),NOSPLIT,$0-0
182+
JMP libc_fcntl(SB)
183+
GLOBL ·libc_fcntl_trampoline_addr(SB), RODATA, $8
184+
DATA ·libc_fcntl_trampoline_addr(SB)/8, $libc_fcntl_trampoline<>(SB)
185+
181186
TEXT libc_ppoll_trampoline<>(SB),NOSPLIT,$0-0
182187
JMP libc_ppoll(SB)
183188
GLOBL ·libc_ppoll_trampoline_addr(SB), RODATA, $8

unix/zsyscall_openbsd_ppc64.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_openbsd_ppc64.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0
213213
GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8
214214
DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB)
215215

216+
TEXT libc_fcntl_trampoline<>(SB),NOSPLIT,$0-0
217+
CALL libc_fcntl(SB)
218+
RET
219+
GLOBL ·libc_fcntl_trampoline_addr(SB), RODATA, $8
220+
DATA ·libc_fcntl_trampoline_addr(SB)/8, $libc_fcntl_trampoline<>(SB)
221+
216222
TEXT libc_ppoll_trampoline<>(SB),NOSPLIT,$0-0
217223
CALL libc_ppoll(SB)
218224
RET

unix/zsyscall_openbsd_riscv64.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_openbsd_riscv64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0
178178
GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8
179179
DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB)
180180

181+
TEXT libc_fcntl_trampoline<>(SB),NOSPLIT,$0-0
182+
JMP libc_fcntl(SB)
183+
GLOBL ·libc_fcntl_trampoline_addr(SB), RODATA, $8
184+
DATA ·libc_fcntl_trampoline_addr(SB)/8, $libc_fcntl_trampoline<>(SB)
185+
181186
TEXT libc_ppoll_trampoline<>(SB),NOSPLIT,$0-0
182187
JMP libc_ppoll(SB)
183188
GLOBL ·libc_ppoll_trampoline_addr(SB), RODATA, $8

0 commit comments

Comments
 (0)