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: IoctlFileClone takes int for file descriptors and not uintptr #64992

Closed
mitar opened this issue Jan 6, 2024 · 2 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Milestone

Comments

@mitar
Copy link
Contributor

mitar commented Jan 6, 2024

Go version

go version go1.21.3 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/mitar/.cache/go-build'
GOENV='/home/mitar/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/mitar/.go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/mitar/.go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='/usr/bin/gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4184395022=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I am trying to use unix.IoctlFileClone.

What did you see happen?

I noticed that I have to cast Go file descriptors (file.Fd()) to int.

What did you expect to see?

That I would not have to cast file descriptors (which are in Go uintptr) to int.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 6, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jan 6, 2024
@bcmills
Copy link
Contributor

bcmills commented Jan 8, 2024

The signatures of the functions in the unix package are intended to match the signatures of the corresponding C system calls.

On Linux, the C signature of ioctl(2) is:

int ioctl(int fd, unsigned long request, ...);

os.File.Fd presumably returns a uintptr because it is designed to be platform-independent. On Windows it refers to a HANDLE, which is typedef'd pointer to void — which corresponds to a uintptr, not an int. On Unix platforms, you may assume that the uintptr returned by os.File.Fd can be safely converted to an int.

(I suppose that it is theoretically possible for uintptr to be smaller than int, but I don't believe that is the case for any platform currently supported by Go.)

@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2024
@mitar
Copy link
Contributor Author

mitar commented Jan 8, 2024

Thanks!

On Unix platforms, you may assume that the uintptr returned by os.File.Fd can be safely converted to an int.

Should this be documented maybe for os.File.Fd?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

3 participants