Skip to content

Commit

Permalink
fixes: concurrent map kallsymsCache. (#27)
Browse files Browse the repository at this point in the history
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
  • Loading branch information
cfc4n committed Mar 25, 2023
1 parent 4daf40e commit 7937d7f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
)

type state uint
Expand Down Expand Up @@ -97,6 +98,7 @@ func GetSyscallFnName(name string) (string, error) {

// cache of the symfile
var kallsymsCache = make(map[string]bool)
var kallSymsLocker = sync.Mutex{}

// GetSyscallFnNameWithSymFile - Returns the kernel function of the provided syscall, after reading symFile to retrieve
// the list of symbols of the current kernel.
Expand All @@ -122,12 +124,18 @@ func GetSyscallFnNameWithSymFile(name string, symFile string) (string, error) {
// only save symbol in text (code) section and weak symbol
// Reference: https://github.com/iovisor/bcc/pull/1540/files
if strings.ToLower(line[1]) == "t" || strings.ToLower(line[1]) == "w" {
kallSymsLocker.Lock()
kallsymsCache[line[2]] = true
kallSymsLocker.Unlock()
}
}
}

if _, exist := kallsymsCache[name]; exist {
kallSymsLocker.Lock()
_, exist := kallsymsCache[name];
kallSymsLocker.Unlock()

if exist {
return name, nil
}

Expand Down

0 comments on commit 7937d7f

Please sign in to comment.