Hi, I'm a bit confused as to how the golang.org/x/sys package works. >From the documentation of unsafe.Pointer: >(4) Conversion of a Pointer to a uintptr when calling syscall.Syscall.
> The Syscall functions in package syscall pass their uintptr arguments > directly to the operating system, which then may, depending on the details > of the call, reinterpret some of them as pointers. > That is, the system call implementation is implicitly converting certain > arguments back from uintptr to pointer. > If a pointer argument must be converted to uintptr for use as an argument, > that conversion must appear in the call expression itself Now, as far as I can tell this forces non stdlib packages to adhere to exactly that. As far as I can tell x/sys is just a common namespace for the go authors, but as far as the compiler itself is concerned, that's a normal module not the stdlib. Or is this a wrong assumption? Reason I ask is because the code in x/sys clearly violates that rule. in unix/ioctl.go there's ``` // IoctlSetPointerInt performs an ioctl operation which sets an // integer value on fd, using the specified request number. The ioctl // argument is called with a pointer to the integer value, rather than // passing the integer value directly. func IoctlSetPointerInt(fd int, req uint, value int) error { v := int32(value) return ioctl(fd, req, uintptr(unsafe.Pointer(&v))) } ``` and the declaration of ioctl in zsyskall_linux.go: ``` func ioctl(fd int, req uint, arg uintptr) (err error) { _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { err = errnoErr(e1) } return } ``` Now, for starters ioctl includes a pointless conversion of a uintptr to a uintptr, for the arg parameter can anyone tell me why? Second (and this is my actual question), isn't that in violation of the unsafe constraints cited above? IoctlSetPointerInt clearly converts a unsafe.Pointer to a uintptr and *doesn't* directly call syscall.Syscall. Why is this valid? Thanks in advance. Regards, Reto -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20210227221836.kgkn4xskg4xe7gsk%40feather.localdomain.