Skip to content

Commit

Permalink
unix: rename XDPUmemReg field back to Size
Browse files Browse the repository at this point in the history
When the Linux-specific XDPUmemReg struct was originally added
(CL 136695) the only field with a prefix was chunk_size,
so cgo rewrote the field to Size. Later Linux added a tx_metadata_len
field, which caused cgo to to leave the chunk_size field as Chunk_size
(CL 577975).

However, existing code, specifically gvisor, refers to the field
as Size. So go back to Size so that existing code will continue
to work.

This does unfortunately mean that people who used the struct since CL
577975 in April, 2024 will have to adapt. There doesn't seem to be a
perfect solution here. But we've had Size since September, 2018,
so let's stick with that.

Change-Id: Ib11edfbf98ce3a9e1a909194f200a39ddfe6f8e0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/607876
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Aug 22, 2024
1 parent 59665e5 commit a8c5219
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions unix/mkpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ func main() {
spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
b = spareFieldsRegex.ReplaceAll(b, []byte("_"))

// Rename chunk_size field in XDPUmemReg.
// When the struct was originally added (CL 136695) the only
// field with a prefix was chunk_size, so cgo rewrote the
// field to Size. Later Linux added a tx_metadata_len field,
// so cgo left chunk_size as Chunk_size (CL 577975).
// Go back to Size so that packages like gvisor don't have
// to adjust.
xdpUmemRegType := regexp.MustCompile(`type XDPUmemReg struct {[^}]*}`)
xdpUmemRegStructs := xdpUmemRegType.FindAll(b, -1)
for _, s := range xdpUmemRegStructs {
newName := bytes.Replace(s, []byte("Chunk_size"), []byte("Size"), 1)
b = bytes.Replace(b, s, newName, 1)
}

// Remove cgo padding fields
removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`)
b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_"))
Expand Down
2 changes: 1 addition & 1 deletion unix/ztypes_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a8c5219

Please # to comment.