diff --git a/src/system/kernel/arch/x86/32/thread.cpp b/src/system/kernel/arch/x86/32/thread.cpp index 10ea4b234e..66465c2951 100644 --- a/src/system/kernel/arch/x86/32/thread.cpp +++ b/src/system/kernel/arch/x86/32/thread.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -204,8 +205,9 @@ arch_thread_dump_info(void *info) static addr_t arch_randomize_stack_pointer(addr_t value) { - value -= rand() & (B_PAGE_SIZE - 1); - return value & ~0xful; + STATIC_ASSERT(MAX_RANDOM_VALUE >= B_PAGE_SIZE - 1); + value -= random_value() & (B_PAGE_SIZE - 1); + return value & ~addr_t(0xf); } diff --git a/src/system/kernel/arch/x86/64/thread.cpp b/src/system/kernel/arch/x86/64/thread.cpp index ebc8ec55e7..e1a337fe3c 100644 --- a/src/system/kernel/arch/x86/64/thread.cpp +++ b/src/system/kernel/arch/x86/64/thread.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -200,8 +201,9 @@ arch_thread_dump_info(void* info) static addr_t arch_randomize_stack_pointer(addr_t value) { - value -= rand() & (B_PAGE_SIZE - 1); - return value & ~0xful; + STATIC_ASSERT(MAX_RANDOM_VALUE >= B_PAGE_SIZE - 1); + value -= random_value() & (B_PAGE_SIZE - 1); + return value & ~addr_t(0xf); }