-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ksyms.go
40 lines (33 loc) · 960 Bytes
/
ksyms.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ebpf
import (
"bufio"
"os"
"sort"
"github.com/DataDog/datadog-agent/pkg/process/util"
"github.com/pkg/errors"
)
// VerifyKernelFuncs ensures all kernel functions exist in ksyms located at provided path.
func VerifyKernelFuncs(path string, requiredKernelFuncs []string) ([]string, error) {
missing := make(util.SSBytes, len(requiredKernelFuncs))
for i, f := range requiredKernelFuncs {
missing[i] = []byte(f)
}
sort.Sort(missing)
f, err := os.Open(path)
if err != nil {
return nil, errors.Wrapf(err, "error reading kallsyms file from: %s", path)
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanWords)
for scanner.Scan() && len(missing) > 0 {
if i := missing.Search(scanner.Bytes()); i < len(missing) {
missing = append(missing[:i], missing[i+1:]...)
}
}
missingStrs := make([]string, len(missing))
for i := range missing {
missingStrs[i] = string(missing[i])
}
return missingStrs, nil
}