summaryrefslogtreecommitdiff
path: root/Kernel/Arch/i386
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-03 12:36:30 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-03 12:43:07 +0100
commit9026598999d996d403d0b5951006ef4bb0f1c1c0 (patch)
tree027cb67bad6291ce48d109673abb60cc909689f5 /Kernel/Arch/i386
parent24cc67d199256faa88b43cf580e9b76b4b9b327f (diff)
downloadserenity-9026598999d996d403d0b5951006ef4bb0f1c1c0.zip
Kernel: Add a more expressive API for getting random bytes
We now have these API's in <Kernel/Random.h>: - get_fast_random_bytes(u8* buffer, size_t buffer_size) - get_good_random_bytes(u8* buffer, size_t buffer_size) - get_fast_random<T>() - get_good_random<T>() Internally they both use x86 RDRAND if available, otherwise they fall back to the same LCG we had in RandomDevice all along. The main purpose of this patch is to give kernel code a way to better express its needs for random data. Randomness is something that will require a lot more work, but this is hopefully a step in the right direction.
Diffstat (limited to 'Kernel/Arch/i386')
-rw-r--r--Kernel/Arch/i386/CPU.cpp2
-rw-r--r--Kernel/Arch/i386/CPU.h1
2 files changed, 3 insertions, 0 deletions
diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp
index acb08e19ed..efe2a67ddf 100644
--- a/Kernel/Arch/i386/CPU.cpp
+++ b/Kernel/Arch/i386/CPU.cpp
@@ -524,6 +524,7 @@ void sse_init()
bool g_cpu_supports_nx;
bool g_cpu_supports_pae;
bool g_cpu_supports_pge;
+bool g_cpu_supports_rdrand;
bool g_cpu_supports_smep;
bool g_cpu_supports_sse;
bool g_cpu_supports_tsc;
@@ -536,6 +537,7 @@ void detect_cpu_features()
g_cpu_supports_pge = (processor_info.edx() & (1 << 13));
g_cpu_supports_sse = (processor_info.edx() & (1 << 25));
g_cpu_supports_tsc = (processor_info.edx() & (1 << 4));
+ g_cpu_supports_rdrand = (processor_info.ecx() & (1 << 30));
CPUID extended_processor_info(0x80000001);
g_cpu_supports_nx = (extended_processor_info.edx() & (1 << 20));
diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h
index 482247a2d2..96d579cfeb 100644
--- a/Kernel/Arch/i386/CPU.h
+++ b/Kernel/Arch/i386/CPU.h
@@ -519,6 +519,7 @@ void detect_cpu_features();
extern bool g_cpu_supports_nx;
extern bool g_cpu_supports_pae;
extern bool g_cpu_supports_pge;
+extern bool g_cpu_supports_rdrand;
extern bool g_cpu_supports_smep;
extern bool g_cpu_supports_sse;
extern bool g_cpu_supports_tsc;