1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * GCC stack protector support.
4  *
5  */
6 
7 #ifndef _ASM_STACKPROTECTOR_H
8 #define _ASM_STACKPROTECTOR_H
9 
10 #include <linux/random.h>
11 #include <linux/version.h>
12 #include <asm/reg.h>
13 #include <asm/current.h>
14 
15 /*
16  * Initialize the stackprotector canary value.
17  *
18  * NOTE: this must only be called from functions that never return,
19  * and it must always be inlined.
20  */
21 static __always_inline void boot_init_stack_canary(void)
22 {
23 	unsigned long canary;
24 
25 	/* Try to get a semi random initial value. */
26 	canary = get_random_canary();
27 	canary ^= mftb();
28 	canary ^= LINUX_VERSION_CODE;
29 	canary &= CANARY_MASK;
30 
31 	current->stack_canary = canary;
32 }
33 
34 #endif	/* _ASM_STACKPROTECTOR_H */
35