win: fix CPU query buffer handling

Try in a short loop until we get the size right.
This commit is contained in:
Daniel Hiltgen
2025-09-25 08:13:24 -07:00
parent 5f9f312bdb
commit 936c6d6be1

View File

@@ -99,28 +99,23 @@ func (pkg *winPackage) IsMember(target *GROUP_AFFINITY) bool {
} }
func getLogicalProcessorInformationEx() ([]byte, error) { func getLogicalProcessorInformationEx() ([]byte, error) {
buf := make([]byte, 1) buf := make([]byte, 1024)
bufSize := len(buf) bufSize := len(buf)
ret, _, err := GetLogicalProcessorInformationEx.Call( var err error
uintptr(RelationAll), for range 3 {
uintptr(unsafe.Pointer(&buf[0])), var ret uintptr
uintptr(unsafe.Pointer(&bufSize)),
)
if ret != 0 {
return nil, fmt.Errorf("failed to determine size info ret:%d %w", ret, err)
}
buf = make([]byte, bufSize)
ret, _, err = GetLogicalProcessorInformationEx.Call( ret, _, err = GetLogicalProcessorInformationEx.Call(
uintptr(RelationAll), uintptr(RelationAll),
uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&buf[0])),
uintptr(unsafe.Pointer(&bufSize)), uintptr(unsafe.Pointer(&bufSize)),
) )
if ret == 0 { if ret == 1 && bufSize <= len(buf) {
return nil, fmt.Errorf("failed to gather processor information ret:%d buflen:%d %w", ret, bufSize, err)
}
return buf, nil return buf, nil
} }
buf = make([]byte, bufSize)
}
return nil, fmt.Errorf("unable to determine CPU details: %w", err)
}
func processSystemLogicalProcessorInforationList(buf []byte) []*winPackage { func processSystemLogicalProcessorInforationList(buf []byte) []*winPackage {
var slpi *SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX var slpi *SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX