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