Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: Add Dup3 on FreeBSD #55935

Closed
dveeden opened this issue Sep 29, 2022 · 3 comments
Closed

x/sys/unix: Add Dup3 on FreeBSD #55935

dveeden opened this issue Sep 29, 2022 · 3 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-FreeBSD
Milestone

Comments

@dveeden
Copy link

dveeden commented Sep 29, 2022

What version of Go are you using (go version)?

% go version
go version go1.19.1 freebsd/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
% go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dveeden/.cache/go-build"
GOENV="/home/dveeden/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOINSECURE=""
GOMODCACHE="/home/dveeden/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="freebsd"
GOPATH="/home/dveeden/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go119"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go119/pkg/tool/freebsd_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v2"
AR="ar"
CC="cc"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4147625229=/tmp/go-build -gno-record-gcc-switches"

What did you do?

syscall.Dup3() is available on Linux, but not on FreeBSD. However the syscall seems to be present as indicated on the dup3(3) manpage.

A patch like this might work:

diff --git a/src/syscall/syscall_freebsd.go b/src/syscall/syscall_freebsd.go
index 0f3912644b..83d338554b 100644
--- a/src/syscall/syscall_freebsd.go
+++ b/src/syscall/syscall_freebsd.go
@@ -179,6 +179,7 @@ func Mknod(path string, mode uint32, dev uint64) (err error) {
 //sys  Close(fd int) (err error)
 //sys  Dup(fd int) (nfd int, err error)
 //sys  Dup2(from int, to int) (err error)
+//sys  Dup3(oldfd int, newfd int, flags int) (err error)
 //sys  Fchdir(fd int) (err error)
 //sys  Fchflags(fd int, flags int) (err error)
 //sys  Fchmod(fd int, mode uint32) (err error)
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 29, 2022
@dveeden
Copy link
Author

dveeden commented Sep 29, 2022

Looks like dup3() is a Linux compatibility. See https://docs.freebsd.org/en/books/developers-handbook/x86/#x86-call-numbers
I assume that this means that it should not be included in syscall?

% grep 'SYS_dup' /usr/include/sys/syscall.h
#define	SYS_dup	41
#define	SYS_dup2	90
% find /usr/src/sys -name syscalls.master -print -exec grep -B1 -A5 'dup3(' {} \;
/usr/src/sys/compat/freebsd32/syscalls.master
/usr/src/sys/kern/syscalls.master
/usr/src/sys/amd64/linux32/syscalls.master
330	AUE_NULL	STD {
		int linux_dup3(
		    l_int oldfd,
		    l_int newfd,
		    l_int flags
		);
	}
/usr/src/sys/amd64/linux/syscalls.master
292	AUE_NULL	STD {
		int linux_dup3(
		    l_uint oldfd,
		    l_uint newfd,
		    l_int flags
		);
	}
/usr/src/sys/arm/linux/syscalls.master
358	AUE_NULL	STD	{
		int linux_dup3(
		    l_int oldfd,
		    l_int newfd,
		    l_int flags
		);
	}
/usr/src/sys/arm64/linux/syscalls.master
24	AUE_NULL	STD	{
		int linux_dup3(
		    l_int oldfd,
		    l_int newfd,
		    l_int flags
		);
	}
/usr/src/sys/i386/linux/syscalls.master
330	AUE_NULL	STD {
		int linux_dup3(
		    l_int oldfd,
		    l_int newfd,
		    l_int flags
		);
	}

@tklauser
Copy link
Member

The dup3 is Linux-specific and e.g. NetBSD and OpenBSD decided to add it as a syscall too. On FreeBSD it's available as a libc function using fcntl with F_DUP2FD_CLOEXEC: https://github.com/freebsd/freebsd-src/blob/373ffc62c158e52cde86a5b934ab4a51307f9f2e/lib/libc/gen/dup3.c#L42-L60

We could add a similar Dup3 implementation for FreeBSD. Though not to the syscall package - which is frozen, see its package level godoc - but to golang.org/x/sys/unix which should be used instead.

@tklauser tklauser added this to the Unplanned milestone Sep 29, 2022
@tklauser tklauser added OS-FreeBSD NeedsFix The path to resolution is known, but the work has not been done. labels Sep 29, 2022
@tklauser tklauser changed the title syscall: Add Dup3 on FreeBSD x/sys/unix: Add Dup3 on FreeBSD Sep 29, 2022
@dmgk dmgk self-assigned this Feb 23, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/470675 mentions this issue: unix: add Dup3 on FreeBSD

@golang golang locked and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-FreeBSD
Projects
None yet
Development

No branches or pull requests

4 participants