From 7937d7f88b42b3640cd6a982ca394285e2135575 Mon Sep 17 00:00:00 2001 From: CFC4N Date: Fri, 24 Mar 2023 23:38:10 +0800 Subject: [PATCH] fixes: concurrent map kallsymsCache. (#27) Signed-off-by: CFC4N --- utils.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utils.go b/utils.go index b0f31d1..55b955f 100644 --- a/utils.go +++ b/utils.go @@ -12,6 +12,7 @@ import ( "sort" "strconv" "strings" + "sync" ) type state uint @@ -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. @@ -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 }