net: fix MIB_IF_ROW2 layout on Windows 386 - #2120
Open
zhangli091011 wants to merge 1 commit into
Open
Conversation
Author
|
Would you have a chance to review this PR when convenient? CI is green. Thank you! |
shirou
reviewed
Jul 30, 2026
shirou
left a comment
Owner
There was a problem hiding this comment.
Thanks for tracking this down — the analysis is correct, and I verified that TransmitLinkSpeed lands at offset 1192 with a total size of 1352 on 386 with this padding, matching amd64.
One suggestion: since unsafe.Alignof is a constant expression and net_windows.go already imports unsafe, the padding can be derived directly, without the two build-tagged files:
const (
maxStringSize = 256
maxPhysAddressLength = 32
// Windows aligns ULONG64 to 8 bytes, but Go only gives uint64 4-byte
// alignment on 32-bit architectures, so pad ConnectionType up to the
// next 8-byte boundary there.
// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_if_row2
pad0for64_4for32 = (8 - unsafe.Alignof(uint64(0))) % 8
)This yields 4 on windows/386 and 0 on windows/amd64 and windows/arm64 (same as today), and it also stays correct for any other 32-bit Windows port, which !386 would miss.
Would you mind giving it a try?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1865.
Windows aligns the
ULONG64fields inMIB_IF_ROW2to an 8-byte boundary. Go only givesuint644-byte alignment on 386, which causedTransmitLinkSpeedand every following network counter to be read four bytes early.This adds four bytes of explicit padding for Windows 386 while retaining the existing layout on other Windows architectures. A deterministic 386 regression test verifies the
TransmitLinkSpeedoffset and total structure size.Verification
go test ./net -count=1with CI behavior enabledgit diff --checkAI disclosure
OpenCode using
myself/gpt-5.6-solassisted with issue investigation, implementation, and test preparation. I reviewed the ABI rationale, source changes, and verification results.