Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes: concurrent map kallsymsCache. (#27) #28

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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