xref: /linux/arch/riscv/include/asm/stackprotector.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _ASM_RISCV_STACKPROTECTOR_H
4 #define _ASM_RISCV_STACKPROTECTOR_H
5 
6 extern unsigned long __stack_chk_guard;
7 
8 /*
9  * Initialize the stackprotector canary value.
10  *
11  * NOTE: this must only be called from functions that never return,
12  * and it must always be inlined.
13  */
14 static __always_inline void boot_init_stack_canary(void)
15 {
16 	unsigned long canary = get_random_canary();
17 
18 	current->stack_canary = canary;
19 	if (!IS_ENABLED(CONFIG_STACKPROTECTOR_PER_TASK))
20 		__stack_chk_guard = current->stack_canary;
21 }
22 #endif /* _ASM_RISCV_STACKPROTECTOR_H */
23