From e8c54fb511f6a2d695a4403ae0dab1c05aef011a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 4 Nov 2019 10:14:41 +0100 Subject: [PATCH] windows: add EnumProcesses function See https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumprocesses Change-Id: Ibccb0c3d8e4f32857547ee6d072d0b1cb2430366 Reviewed-on: https://go-review.googlesource.com/c/sys/+/205197 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- windows/syscall_windows.go | 3 +++ windows/zsyscall_windows.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 034b5f40..fe8e42cf 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -314,6 +314,9 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys rtlGetVersion(info *OsVersionInfoEx) (ret error) = ntdll.RtlGetVersion //sys rtlGetNtVersionNumbers(majorVersion *uint32, minorVersion *uint32, buildNumber *uint32) = ntdll.RtlGetNtVersionNumbers +// Process Status API (PSAPI) +//sys EnumProcesses(processIds []uint32, bytesReturned *uint32) (err error) = psapi.EnumProcesses + // syscall interface implementation for other packages // GetCurrentProcess returns the handle for the current process. diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 74d721e0..6658ccd1 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -44,6 +44,7 @@ var ( moduser32 = NewLazySystemDLL("user32.dll") modole32 = NewLazySystemDLL("ole32.dll") modntdll = NewLazySystemDLL("ntdll.dll") + modpsapi = NewLazySystemDLL("psapi.dll") modws2_32 = NewLazySystemDLL("ws2_32.dll") moddnsapi = NewLazySystemDLL("dnsapi.dll") modiphlpapi = NewLazySystemDLL("iphlpapi.dll") @@ -247,6 +248,7 @@ var ( procCoTaskMemFree = modole32.NewProc("CoTaskMemFree") procRtlGetVersion = modntdll.NewProc("RtlGetVersion") procRtlGetNtVersionNumbers = modntdll.NewProc("RtlGetNtVersionNumbers") + procEnumProcesses = modpsapi.NewProc("EnumProcesses") procWSAStartup = modws2_32.NewProc("WSAStartup") procWSACleanup = modws2_32.NewProc("WSACleanup") procWSAIoctl = modws2_32.NewProc("WSAIoctl") @@ -2758,6 +2760,22 @@ func rtlGetNtVersionNumbers(majorVersion *uint32, minorVersion *uint32, buildNum return } +func EnumProcesses(processIds []uint32, bytesReturned *uint32) (err error) { + var _p0 *uint32 + if len(processIds) > 0 { + _p0 = &processIds[0] + } + r1, _, e1 := syscall.Syscall(procEnumProcesses.Addr(), 3, uintptr(unsafe.Pointer(_p0)), uintptr(len(processIds)), uintptr(unsafe.Pointer(bytesReturned))) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + func WSAStartup(verreq uint32, data *WSAData) (sockerr error) { r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0) if r0 != 0 {