mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:27:34 +00:00
Kernel: Add RTC as fallback entropy source if HPET is not found
This commit is contained in:
parent
0a61924727
commit
645657865d
2 changed files with 14 additions and 2 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include <Kernel/Devices/RandomDevice.h>
|
#include <Kernel/Devices/RandomDevice.h>
|
||||||
#include <Kernel/Random.h>
|
#include <Kernel/Random.h>
|
||||||
#include <Kernel/Time/HPET.h>
|
#include <Kernel/Time/HPET.h>
|
||||||
|
#include <Kernel/Time/RTC.h>
|
||||||
#include <Kernel/Time/TimeManagement.h>
|
#include <Kernel/Time/TimeManagement.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
@ -65,14 +66,23 @@ KernelRng::KernelRng()
|
||||||
|
|
||||||
this->resource().add_random_event(value, i % 32);
|
this->resource().add_random_event(value, i % 32);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (TimeManagement::the().can_query_precise_time()) {
|
||||||
// Add HPET as entropy source if we don't have anything better.
|
// Add HPET as entropy source if we don't have anything better.
|
||||||
klog() << "KernelRng: Using HPET as entropy source (bad!)";
|
klog() << "KernelRng: Using HPET as entropy source";
|
||||||
|
|
||||||
for (size_t i = 0; i < resource().pool_count * resource().reseed_threshold; ++i) {
|
for (size_t i = 0; i < resource().pool_count * resource().reseed_threshold; ++i) {
|
||||||
u64 hpet_time = HPET::the().read_main_counter();
|
u64 hpet_time = HPET::the().read_main_counter();
|
||||||
this->resource().add_random_event(hpet_time, i % 32);
|
this->resource().add_random_event(hpet_time, i % 32);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback to RTC
|
||||||
|
klog() << "KernelRng: Using RTC as entropy source (bad!)";
|
||||||
|
time_t current_time = RTC::now();
|
||||||
|
for (size_t i = 0; i < resource().pool_count * resource().reseed_threshold; ++i) {
|
||||||
|
this->resource().add_random_event(current_time, i % 32);
|
||||||
|
current_time *= 0x574a;
|
||||||
|
current_time += 0x40b2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,8 @@ public:
|
||||||
timespec remaining_epoch_time_adjustment() const { return m_remaining_epoch_time_adjustment; }
|
timespec remaining_epoch_time_adjustment() const { return m_remaining_epoch_time_adjustment; }
|
||||||
void set_remaining_epoch_time_adjustment(const timespec& adjustment) { m_remaining_epoch_time_adjustment = adjustment; }
|
void set_remaining_epoch_time_adjustment(const timespec& adjustment) { m_remaining_epoch_time_adjustment = adjustment; }
|
||||||
|
|
||||||
|
bool can_query_precise_time() const { return m_can_query_precise_time; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool probe_and_set_legacy_hardware_timers();
|
bool probe_and_set_legacy_hardware_timers();
|
||||||
bool probe_and_set_non_legacy_hardware_timers();
|
bool probe_and_set_non_legacy_hardware_timers();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue