unix: align Ifreq so its union accessors cannot fault Uint16, SetUint16, Uint32, SetUint32, Inet4Addr and SetInet4Addr cast the ifreq union to uint16, uint32 or RawSockaddrInet4 and access it in place. The generated ifreq declares that union as a byte array, so the type guarantees only byte alignment and the compiler may put an Ifreq at any address - as it does for the elements of a []Ifreq, which pack at the struct's size with an alignment of one. A misaligned access is merely slow on amd64 and arm64; on sparc64 it faults, and TestIoctlIfreq died with SIGBUS. Align the wrapper rather than changing the accessors. The union lies at offset 16 within ifreq on every architecture, so aligning the wrapper aligns the union, and all six accessors are covered instead of only the four integer ones. TestIfreqAlignment pins the invariant. Without the fix it fails on every architecture, reporting an alignment of 1, so catching a regression does not need sparc64 hardware. Updates golang/go#55000 Change-Id: I70aca33419086de9eb68032e354e5f666cc20562 GitHub-Last-Rev: 637b50d0e63b84eb536019d7c893c5cb07289bf3 GitHub-Pull-Request: golang/sys#287 Reviewed-on: https://go-review.googlesource.com/c/sys/+/820000 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This repository holds supplemental Go packages for low-level interactions with the operating system.
This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.
The git repository is https://go.googlesource.com/sys.
The main issue tracker for the sys repository is located at https://go.dev/issues. Prefix your issue with “x/sys:” in the subject line, so it is easy to find.