mirror of
https://github.com/speed47/spectre-meltdown-checker.git
synced 2024-12-26 20:10:31 +01:00
cache is_cpu_vulnerable result for performance
This commit is contained in:
parent
56d4f82484
commit
de6590cd09
@ -170,6 +170,16 @@ _debug()
|
|||||||
_echo 3 "\033[34m(debug) $@\033[0m"
|
_echo 3 "\033[34m(debug) $@\033[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_cpu_vulnerable_cached=0
|
||||||
|
_is_cpu_vulnerable_cached()
|
||||||
|
{
|
||||||
|
[ "$1" = 1 ] && return $variant1
|
||||||
|
[ "$1" = 2 ] && return $variant2
|
||||||
|
[ "$1" = 3 ] && return $variant3
|
||||||
|
echo "$0: error: invalid variant '$1' passed to is_cpu_vulnerable()" >&2
|
||||||
|
exit 255
|
||||||
|
}
|
||||||
|
|
||||||
is_cpu_vulnerable()
|
is_cpu_vulnerable()
|
||||||
{
|
{
|
||||||
# param: 1, 2 or 3 (variant)
|
# param: 1, 2 or 3 (variant)
|
||||||
@ -177,6 +187,11 @@ is_cpu_vulnerable()
|
|||||||
# (note that in shell, a return of 0 is success)
|
# (note that in shell, a return of 0 is success)
|
||||||
# by default, everything is vulnerable, we work in a "whitelist" logic here.
|
# by default, everything is vulnerable, we work in a "whitelist" logic here.
|
||||||
# usage: is_cpu_vulnerable 2 && do something if vulnerable
|
# usage: is_cpu_vulnerable 2 && do something if vulnerable
|
||||||
|
if [ "$is_cpu_vulnerable_cached" = 1 ]; then
|
||||||
|
_is_cpu_vulnerable_cached "$1"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
variant1=''
|
variant1=''
|
||||||
variant2=''
|
variant2=''
|
||||||
variant3=''
|
variant3=''
|
||||||
@ -260,12 +275,9 @@ is_cpu_vulnerable()
|
|||||||
[ "$variant2" = "immune" ] && variant2=1 || variant2=0
|
[ "$variant2" = "immune" ] && variant2=1 || variant2=0
|
||||||
[ "$variant3" = "immune" ] && variant3=1 || variant3=0
|
[ "$variant3" = "immune" ] && variant3=1 || variant3=0
|
||||||
_debug "is_cpu_vulnerable: final results are <$variant1> <$variant2> <$variant3>"
|
_debug "is_cpu_vulnerable: final results are <$variant1> <$variant2> <$variant3>"
|
||||||
|
is_cpu_vulnerable_cached=1
|
||||||
[ "$1" = 1 ] && return $variant1
|
_is_cpu_vulnerable_cached "$1"
|
||||||
[ "$1" = 2 ] && return $variant2
|
return $?
|
||||||
[ "$1" = 3 ] && return $variant3
|
|
||||||
echo "$0: error: invalid variant '$1' passed to is_cpu_vulnerable()" >&2
|
|
||||||
exit 255
|
|
||||||
}
|
}
|
||||||
|
|
||||||
show_header()
|
show_header()
|
||||||
|
Loading…
Reference in New Issue
Block a user