aboutsummaryrefslogtreecommitdiff
path: root/libc/random.c
diff options
context:
space:
mode:
authorMarvin Borner2021-03-14 16:12:44 +0100
committerGitHub2021-03-14 16:12:44 +0100
commit268f3ccdb90ab4b9bd70ca176478797aae97ca05 (patch)
tree2dbc3e52d90dab4aae8021773f09b6b72a74b8cb /libc/random.c
parent4309322f9d2b3e31421a3cc5399ab1f4368e0652 (diff)
parent6dec7db5158447b66f31a3f786ce2916cab83cec (diff)
Added memory management using paging
This was quite a roller-coaster and most things are slower now, but it works and is way more secure. I still need to implement things like shared memory for the WM/GUI system but other than that everything is supported.
Diffstat (limited to 'libc/random.c')
-rw-r--r--libc/random.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libc/random.c b/libc/random.c
index 8c8076f..cfd082d 100644
--- a/libc/random.c
+++ b/libc/random.c
@@ -1,5 +1,6 @@
// MIT License, Copyright (c) 2020 Marvin Borner
+#include <cpu.h>
#include <def.h>
#include <mem.h>
#include <random.h>
@@ -11,6 +12,34 @@ void srand(u32 seed)
g_seed = seed;
}
+u32 rdrand(void)
+{
+#ifdef kernel
+ if (!cpu_has_cfeature(CPUID_FEAT_ECX_RDRND))
+ return rand();
+
+ u32 rd;
+ __asm__ volatile("rdrand %%eax" : "=a"(rd));
+ return rd;
+#else
+ return rand();
+#endif
+}
+
+u32 rdseed(void)
+{
+#ifdef kernel
+ if (!cpu_has_cfeature(CPUID_FEAT_ECX_RDRND))
+ return rand();
+
+ u32 rd;
+ __asm__ volatile("rdseed %%eax" : "=a"(rd));
+ return rd;
+#else
+ return rand();
+#endif
+}
+
u32 rand(void)
{
g_seed = g_seed * 1103515245 + 12345;