[issue-1357] manually allocating increasing buffer

pull/1358/head
elfrucool 3 years ago
parent dd2b43ba52
commit 91974eca63

@ -11,7 +11,7 @@ import (
"time"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v3/internal/procstats"
"github.com/shirou/gopsutil/v3/procstats"
)
var (

@ -187,30 +187,34 @@ func GetSystemProcessInformation() (*SystemProcessInformationWalk, error) {
var (
oneKb uint32 = 1024
allocKb uint32 = 1
allocBytes uint32 = allocKb * oneKb
buffer []byte
usedBytes uint32
)
// iterating instead of calling common.CallWithExpandingBuffer hangs forever
for {
var allocBytes uint32 = allocKb * oneKb
buffer = make([]byte, allocBytes)
st := common.CallWithExpandingBuffer(
func() common.NtStatus {
return common.NtQuerySystemInformation(
st := common.NtQuerySystemInformation(
windows.SystemProcessInformation,
&buffer[0],
allocBytes,
&usedBytes,
)
},
&buffer,
&usedBytes,
)
if st == common.NtStatus(windows.STATUS_INFO_LENGTH_MISMATCH) {
allocKb *= 2
continue
}
if st.IsError() {
return nil, st.Error()
}
break
}
return &SystemProcessInformationWalk{
SizeInBytes: usedBytes,
Offset: 0,
Loading…
Cancel
Save