1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00
shirou_gopsutil/process/process_windows_64bit.go
Lomanic 01cf95a92d [process][windows] Fix #1216 fix compilation on arm/arm64
go build ./... with GOARCH=arm64 is otherwise failing with the following:

process\process_windows.go:412:11: undefined: readProcessMemory
process\process_windows.go:425:11: undefined: readProcessMemory
process\process_windows.go:896:32: undefined: PROCESS_MEMORY_COUNTERS
process\process_windows.go:897:10: undefined: PROCESS_MEMORY_COUNTERS
process\process_windows.go:910:50: undefined: PROCESS_MEMORY_COUNTERS
process\process_windows.go:950:21: undefined: queryPebAddress
process\process_windows.go:955:9: undefined: readProcessMemory
process\process_windows.go:961:8: undefined: readProcessMemory
process\process_windows.go:969:21: undefined: queryPebAddress
process\process_windows.go:974:9: undefined: readProcessMemory
process\process_windows.go:974:9: too many errors
2022-01-05 01:09:23 +01:00

80 lines
2.0 KiB
Go

//go:build (windows && amd64) || (windows && arm64)
// +build windows,amd64 windows,arm64
package process
import (
"syscall"
"unsafe"
"github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/windows"
)
type PROCESS_MEMORY_COUNTERS struct {
CB uint32
PageFaultCount uint32
PeakWorkingSetSize uint64
WorkingSetSize uint64
QuotaPeakPagedPoolUsage uint64
QuotaPagedPoolUsage uint64
QuotaPeakNonPagedPoolUsage uint64
QuotaNonPagedPoolUsage uint64
PagefileUsage uint64
PeakPagefileUsage uint64
}
func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) (uint64, error) {
if is32BitProcess {
// we are on a 64-bit process reading an external 32-bit process
var wow64 uint
ret, _, _ := common.ProcNtQueryInformationProcess.Call(
uintptr(procHandle),
uintptr(common.ProcessWow64Information),
uintptr(unsafe.Pointer(&wow64)),
uintptr(unsafe.Sizeof(wow64)),
uintptr(0),
)
if status := windows.NTStatus(ret); status == windows.STATUS_SUCCESS {
return uint64(wow64), nil
} else {
return 0, windows.NTStatus(ret)
}
} else {
// we are on a 64-bit process reading an external 64-bit process
var info processBasicInformation64
ret, _, _ := common.ProcNtQueryInformationProcess.Call(
uintptr(procHandle),
uintptr(common.ProcessBasicInformation),
uintptr(unsafe.Pointer(&info)),
uintptr(unsafe.Sizeof(info)),
uintptr(0),
)
if status := windows.NTStatus(ret); status == windows.STATUS_SUCCESS {
return info.PebBaseAddress, nil
} else {
return 0, windows.NTStatus(ret)
}
}
}
func readProcessMemory(procHandle syscall.Handle, _ bool, address uint64, size uint) []byte {
var read uint
buffer := make([]byte, size)
ret, _, _ := common.ProcNtReadVirtualMemory.Call(
uintptr(procHandle),
uintptr(address),
uintptr(unsafe.Pointer(&buffer[0])),
uintptr(size),
uintptr(unsafe.Pointer(&read)),
)
if int(ret) >= 0 && read > 0 {
return buffer[:read]
}
return nil
}