mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-08 20:32:56 +03:00
Kernel: Ensure we don't get in an endless loop while querying the CMOS
When we try to query the time from the RTC CMOS, we try to check if the CMOS is updated. If it is updated for a long period of time (as a result of hardware malfunction), break the loop and return Unix epoch time.
This commit is contained in:
parent
74c9587798
commit
517460d3a9
Notes:
sideshowbarker
2024-07-18 07:29:22 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/517460d3a9d Pull-request: https://github.com/SerenityOS/serenity/pull/8964 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/caoimhebyrne
@ -6,6 +6,7 @@
|
||||
|
||||
#include <AK/Time.h>
|
||||
#include <Kernel/CMOS.h>
|
||||
#include <Kernel/IO.h>
|
||||
#include <Kernel/RTC.h>
|
||||
|
||||
namespace RTC {
|
||||
@ -34,8 +35,27 @@ static u8 bcd_to_binary(u8 bcd)
|
||||
|
||||
void read_registers(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& minute, unsigned& second)
|
||||
{
|
||||
while (update_in_progress())
|
||||
;
|
||||
// Note: Let's wait 0.01 seconds until we stop trying to query the RTC CMOS
|
||||
size_t time_passed_in_milliseconds = 0;
|
||||
bool update_in_progress_ended_successfully = false;
|
||||
while (time_passed_in_milliseconds < 100) {
|
||||
if (!update_in_progress()) {
|
||||
update_in_progress_ended_successfully = true;
|
||||
break;
|
||||
}
|
||||
IO::delay(1000);
|
||||
time_passed_in_milliseconds++;
|
||||
}
|
||||
|
||||
if (!update_in_progress_ended_successfully) {
|
||||
year = 1970;
|
||||
month = 1;
|
||||
day = 1;
|
||||
hour = 0;
|
||||
minute = 0;
|
||||
second = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
u8 status_b = CMOS::read(0x0b);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user