MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / EnumDevices

Function EnumDevices

pkg/sys/device.go:47–81  ·  view source on GitHub ↗

EnumDevices returns metadata about device drivers encountered in the system. If device driver enumeration fails, an empty slice with device information is returned.

()

Source from the content-addressed store, hash-verified

45// system. If device driver enumeration fails, an empty slice with device
46// information is returned.
47func EnumDevices() []Driver {
48 needed := uint32(0)
49 addrs := make([]uintptr, DevSize)
50 err := EnumDeviceDrivers(uintptr(unsafe.Pointer(&addrs[0])), DevSize, &needed)
51 if err != nil {
52 return nil
53 }
54 // base image size greater than initial allocation
55 if needed > uint32(len(addrs)) {
56 addrs = make([]uintptr, needed)
57 err := EnumDeviceDrivers(uintptr(unsafe.Pointer(&addrs[0])), needed, &needed)
58 if err != nil {
59 return nil
60 }
61 }
62 // resize to get the number of drivers
63 if needed/8 < uint32(len(addrs)) {
64 addrs = addrs[:needed/8]
65 }
66 drivers := make([]Driver, len(addrs))
67 for i, addr := range addrs {
68 drv := Driver{
69 Addr: addr,
70 }
71 filename := make([]uint16, syscall.MAX_PATH)
72 n := GetDeviceDriverFileName(addr, &filename[0], syscall.MAX_PATH)
73 if n == 0 {
74 continue
75 }
76 dev := syscall.UTF16ToString(filename)
77 drv.Filename = strings.Replace(dev, "\\SystemRoot", os.Getenv("SYSTEMROOT"), 1)
78 drivers[i] = drv
79 }
80 return drivers
81}

Callers 5

NewSymbolizerFunction · 0.92
CloseMethod · 0.92
GetPathMethod · 0.92
TestEnumDevicesFunction · 0.85

Calls 2

EnumDeviceDriversFunction · 0.85
GetDeviceDriverFileNameFunction · 0.85

Tested by 2

TestEnumDevicesFunction · 0.68