mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 19:57:45 +03:00
Kernel: Use existing assembly snippets for x86-64 RDSEED & RDRAND calls
This commit is contained in:
parent
cb4cbe3ae8
commit
d7d233ab04
Notes:
sideshowbarker
2024-07-19 16:57:59 +09:00
Author: https://github.com/konradekk Commit: https://github.com/SerenityOS/serenity/commit/d7d233ab04e Pull-request: https://github.com/SerenityOS/serenity/pull/17087 Reviewed-by: https://github.com/FireFox317
@ -29,27 +29,17 @@ KernelRng& KernelRng::the()
|
||||
UNMAP_AFTER_INIT KernelRng::KernelRng()
|
||||
{
|
||||
#if ARCH(X86_64)
|
||||
bool supports_rdseed = Processor::current().has_feature(CPUFeature::RDSEED);
|
||||
bool supports_rdrand = Processor::current().has_feature(CPUFeature::RDRAND);
|
||||
if (supports_rdseed || supports_rdrand) {
|
||||
dmesgln("KernelRng: Using RDSEED or RDRAND as entropy source");
|
||||
for (size_t i = 0; i < pool_count * reseed_threshold; ++i) {
|
||||
u32 value = 0;
|
||||
if (supports_rdseed) {
|
||||
asm volatile(
|
||||
"1:\n"
|
||||
"rdseed %0\n"
|
||||
"jnc 1b\n"
|
||||
: "=r"(value));
|
||||
} else {
|
||||
asm volatile(
|
||||
"1:\n"
|
||||
"rdrand %0\n"
|
||||
"jnc 1b\n"
|
||||
: "=r"(value));
|
||||
}
|
||||
if (Processor::current().has_feature(CPUFeature::RDSEED)) {
|
||||
dmesgln("KernelRng: Using RDSEED as entropy source");
|
||||
|
||||
add_random_event(value, i % 32);
|
||||
for (size_t i = 0; i < pool_count * reseed_threshold; ++i) {
|
||||
add_random_event(Kernel::rdseed(), i % 32);
|
||||
}
|
||||
} else if (Processor::current().has_feature(CPUFeature::RDRAND)) {
|
||||
dmesgln("KernelRng: Using RDRAND as entropy source");
|
||||
|
||||
for (size_t i = 0; i < pool_count * reseed_threshold; ++i) {
|
||||
add_random_event(Kernel::rdrand(), i % 32);
|
||||
}
|
||||
} else if (TimeManagement::the().can_query_precise_time()) {
|
||||
// Add HPET as entropy source if we don't have anything better.
|
||||
|
Loading…
Reference in New Issue
Block a user