Skip to content

Commit

Permalink
feat(parse): envelope different OS GUP flags parsing
Browse files Browse the repository at this point in the history
GUP flags are changed between different OS versions.
Create parsing functions to envelope the different type implemented to
parse the flags for each version.
  • Loading branch information
AlonZivony committed Nov 14, 2023
1 parent b235fb5 commit 7411cb9
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions helpers/argumentParsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"strconv"
"strings"
"sync/atomic"

"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -3158,6 +3159,51 @@ func ParseLegacyGUPFlags(rawValue uint64) LegacyGUPFlag {
return LegacyGUPFlag{stringValue: strings.Join(f, "|"), rawValue: uint32(rawValue)}
}

var useLegacyGUPFlagsParse atomic.Bool

Check failure on line 3162 in helpers/argumentParsers.go

View workflow job for this annotation

GitHub Actions / Helpers Unit Tests (1.18)

undefined: atomic.Bool
var skipDetermineGUPFlagsFunc atomic.Bool

Check failure on line 3163 in helpers/argumentParsers.go

View workflow job for this annotation

GitHub Actions / Helpers Unit Tests (1.18)

undefined: atomic.Bool

// ParseGUPFlagsCurrentOS parse the GUP flags received according to current machine OS version.
// It uses optimizations to perform better than ParseGUPFlagsForOS
func ParseGUPFlagsCurrentOS(rawValue uint64) (SystemFunctionArgument, error) {
if !skipDetermineGUPFlagsFunc.Load() {
osInfo, err := GetOSInfo()
if err != nil {
return nil, fmt.Errorf("error getting current OS info - %v", err)
}
compare, err := osInfo.CompareOSBaseKernelRelease("6.3.0")
if err != nil {
return nil, fmt.Errorf("error comparing OS versions to determine how to parse GUP flags - %v", err)
}
if !skipDetermineGUPFlagsFunc.Swap(true) {
if compare == KernelVersionOlder {
useLegacyGUPFlagsParse.Store(true)
} else {
useLegacyGUPFlagsParse.Store(false)
}
}
}

if useLegacyGUPFlagsParse.Load() {
return ParseLegacyGUPFlags(rawValue), nil
} else {

Check failure on line 3188 in helpers/argumentParsers.go

View workflow job for this annotation

GitHub Actions / Analyze Code

if block ends with a return statement, so drop this else and outdent its block
return ParseGUPFlags(rawValue), nil
}
}

// ParseGUPFlagsForOS parse the GUP flags received according to given OS version.
func ParseGUPFlagsForOS(osInfo *OSInfo, rawValue uint64) (SystemFunctionArgument, error) {
compare, err := osInfo.CompareOSBaseKernelRelease("6.3.0")
if err != nil {
return nil, fmt.Errorf("error comparing OS versions to determine how to parse GUP flags - %v", err)
}

if compare == KernelVersionOlder {
return ParseLegacyGUPFlags(rawValue), nil
} else {

Check failure on line 3202 in helpers/argumentParsers.go

View workflow job for this annotation

GitHub Actions / Analyze Code

if block ends with a return statement, so drop this else and outdent its block
return ParseGUPFlags(rawValue), nil
}
}

// =====================================================

// VmFlag represents the flags in the `vm_area_struct` in x86 64bit architecture
Expand Down

0 comments on commit 7411cb9

Please sign in to comment.