Game detection: foreign GPU holders take an external lock hold (GAME_PROCS, GPU_FOREIGN_VRAM_MB)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
//go:build windows
|
||||
|
||||
package game
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// processes lists the running processes via the Toolhelp32 snapshot API.
|
||||
func processes() ([]Process, error) {
|
||||
h, err := windows.CreateToolhelp32Snapshot(windows.TH32CS_SNAPPROCESS, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer windows.CloseHandle(h) //nolint:errcheck // best effort
|
||||
|
||||
var entry windows.ProcessEntry32
|
||||
entry.Size = uint32(unsafe.Sizeof(entry))
|
||||
if err := windows.Process32First(h, &entry); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var ps []Process
|
||||
for {
|
||||
ps = append(ps, Process{
|
||||
PID: int(entry.ProcessID),
|
||||
Name: windows.UTF16ToString(entry.ExeFile[:]),
|
||||
})
|
||||
if err := windows.Process32Next(h, &entry); err != nil {
|
||||
break // ERROR_NO_MORE_FILES ends the walk
|
||||
}
|
||||
}
|
||||
return ps, nil
|
||||
}
|
||||
Reference in New Issue
Block a user