diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/core/prng.c | 10 | ||||
-rw-r--r-- | src/kernel/core/thread.c | 4 | ||||
-rw-r--r-- | src/kernel/core/worker.c | 3 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/kernel/core/prng.c b/src/kernel/core/prng.c index d4307b6..dbffba5 100644 --- a/src/kernel/core/prng.c +++ b/src/kernel/core/prng.c @@ -1,4 +1,5 @@ #include <prng.h> +#include <thread.h> #define EPOOLSIZE 2048 @@ -10,11 +11,10 @@ static const uint32_t a = 16807; static const uint32_t m = 0x7FFFFFFF; uint16_t prng_word() { - if (++n == 100) { + if (++n >= 100) { n = 0; if (entropy_count) { - entropy_count--; - x += entropy[entropy_count]; + x += entropy[--entropy_count]; } } x = (x * a) % m; @@ -30,9 +30,13 @@ void prng_bytes(uint8_t* out, size_t nbytes) { } void prng_add_entropy(const uint8_t* ptr, size_t nbytes) { + int st = enter_critical(CL_NOINT); + while (nbytes-- && entropy_count < EPOOLSIZE - 1) { entropy[entropy_count++] = *(ptr++); } + + exit_critical(st); } /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index 43b56a5..d59b71d 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -11,6 +11,7 @@ #include <worker.h> #include <process.h> #include <freemem.h> +#include <prng.h> void save_context_and_enter_scheduler(saved_context_t *ctx); void resume_context(saved_context_t *ctx); @@ -124,6 +125,9 @@ void run_scheduler() { current_thread = dequeue_thread(); if (current_thread != 0) { + thread_t *ptr = current_thread; + prng_add_entropy((uint8_t*)&ptr, sizeof(ptr)); + set_kernel_stack(current_thread->stack_region->addr + current_thread->stack_region->size); resume_context(¤t_thread->ctx); } else { diff --git a/src/kernel/core/worker.c b/src/kernel/core/worker.c index e367115..cb7bf34 100644 --- a/src/kernel/core/worker.c +++ b/src/kernel/core/worker.c @@ -2,6 +2,7 @@ #include <btree.h> #include <mutex.h> #include <malloc.h> +#include <prng.h> static uint64_t time = 0; static uint64_t next_task_time = UINT64_MAX; @@ -58,6 +59,8 @@ void worker_thread(void* x) { mutex_unlock(&tasks_mutex); if (t != 0) { + prng_add_entropy((uint8_t*)&t, sizeof(t)); + // do task :-) t->fun(t->data); free(t); |