[issue-1357] manually allocating increasing buffer

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

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

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