Skip to content

Commit a8c5219

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent 59665e5 commit a8c5219

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

unix/mkpost.go

+14
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ func main() {
202202
spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
203203
b = spareFieldsRegex.ReplaceAll(b, []byte("_"))
204204

205+
// Rename chunk_size field in XDPUmemReg.
206+
// When the struct was originally added (CL 136695) the only
207+
// field with a prefix was chunk_size, so cgo rewrote the
208+
// field to Size. Later Linux added a tx_metadata_len field,
209+
// so cgo left chunk_size as Chunk_size (CL 577975).
210+
// Go back to Size so that packages like gvisor don't have
211+
// to adjust.
212+
xdpUmemRegType := regexp.MustCompile(`type XDPUmemReg struct {[^}]*}`)
213+
xdpUmemRegStructs := xdpUmemRegType.FindAll(b, -1)
214+
for _, s := range xdpUmemRegStructs {
215+
newName := bytes.Replace(s, []byte("Chunk_size"), []byte("Size"), 1)
216+
b = bytes.Replace(b, s, newName, 1)
217+
}
218+
205219
// Remove cgo padding fields
206220
removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`)
207221
b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_"))

unix/ztypes_linux.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)