From 936c6d6be189fcfd6e4e55eb0b52ae68d571f128 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Thu, 25 Sep 2025 08:13:24 -0700 Subject: [PATCH] win: fix CPU query buffer handling Try in a short loop until we get the size right. --- discover/cpu_windows.go | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/discover/cpu_windows.go b/discover/cpu_windows.go index ee308805e..5f516b5d1 100644 --- a/discover/cpu_windows.go +++ b/discover/cpu_windows.go @@ -99,27 +99,22 @@ func (pkg *winPackage) IsMember(target *GROUP_AFFINITY) bool { } func getLogicalProcessorInformationEx() ([]byte, error) { - buf := make([]byte, 1) + buf := make([]byte, 1024) bufSize := len(buf) - ret, _, err := GetLogicalProcessorInformationEx.Call( - uintptr(RelationAll), - uintptr(unsafe.Pointer(&buf[0])), - uintptr(unsafe.Pointer(&bufSize)), - ) - if ret != 0 { - return nil, fmt.Errorf("failed to determine size info ret:%d %w", ret, err) + var err error + for range 3 { + var ret uintptr + ret, _, err = GetLogicalProcessorInformationEx.Call( + uintptr(RelationAll), + uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(&bufSize)), + ) + if ret == 1 && bufSize <= len(buf) { + return buf, nil + } + buf = make([]byte, bufSize) } - - buf = make([]byte, bufSize) - ret, _, err = GetLogicalProcessorInformationEx.Call( - uintptr(RelationAll), - uintptr(unsafe.Pointer(&buf[0])), - uintptr(unsafe.Pointer(&bufSize)), - ) - if ret == 0 { - return nil, fmt.Errorf("failed to gather processor information ret:%d buflen:%d %w", ret, bufSize, err) - } - return buf, nil + return nil, fmt.Errorf("unable to determine CPU details: %w", err) } func processSystemLogicalProcessorInforationList(buf []byte) []*winPackage {