sd-boot: add overflow check to TSC reads
On some archs the counter is 32bit, and in case of virtualization it might actually overflow, who knows.
This commit is contained in:
@@ -45,6 +45,10 @@ UINT64 ticks_freq(void) {
|
||||
BS->Stall(1000);
|
||||
ticks_end = ticks_read();
|
||||
|
||||
if (ticks_end < ticks_start) /* Check for an overflow (which is not that unlikely, given on some
|
||||
* archs the value is 32bit) */
|
||||
return 0;
|
||||
|
||||
return (ticks_end - ticks_start) * 1000UL;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user