From a8c5219b5e9b860186192d821723785bd48e9100 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 22 Aug 2024 09:39:55 -0700 Subject: [PATCH] unix: rename XDPUmemReg field back to Size 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 Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- unix/mkpost.go | 14 ++++++++++++++ unix/ztypes_linux.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/unix/mkpost.go b/unix/mkpost.go index 5dc2a2b92..c98a77d7f 100644 --- a/unix/mkpost.go +++ b/unix/mkpost.go @@ -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("_")) diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 7f1961b90..9f2550dc3 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -2486,7 +2486,7 @@ type XDPMmapOffsets struct { type XDPUmemReg struct { Addr uint64 Len uint64 - Chunk_size uint32 + Size uint32 Headroom uint32 Flags uint32 Tx_metadata_len uint32