6 #include <sys/kernel.h>
8 #include <sys/libkern.h>
10 long __stack_chk_guard[8] = {};
11 void __stack_chk_fail(void);
14 __stack_chk_fail(void)
17 panic("stack overflow detected; backtrace may be corrupted");
20 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
22 __stack_chk_init(void *dummy __unused)
25 long guard[__arraycount(__stack_chk_guard)];
27 arc4rand(guard, sizeof(guard), 0);
28 for (i = 0; i < __arraycount(guard); i++)
29 __stack_chk_guard[i] = guard[i];
31 SYSINIT(stack_chk, SI_SUB_RANDOM, SI_ORDER_ANY, __stack_chk_init, NULL);