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:
Lennart Poettering
2022-02-08 13:46:14 +01:00
parent 1e66a23373
commit 476c0e969a
+4
View File
@@ -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