162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci#ifndef _ASM_RISCV_STACKPROTECTOR_H
462306a36Sopenharmony_ci#define _ASM_RISCV_STACKPROTECTOR_H
562306a36Sopenharmony_ci
662306a36Sopenharmony_ciextern unsigned long __stack_chk_guard;
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci/*
962306a36Sopenharmony_ci * Initialize the stackprotector canary value.
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * NOTE: this must only be called from functions that never return,
1262306a36Sopenharmony_ci * and it must always be inlined.
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_cistatic __always_inline void boot_init_stack_canary(void)
1562306a36Sopenharmony_ci{
1662306a36Sopenharmony_ci	unsigned long canary = get_random_canary();
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci	current->stack_canary = canary;
1962306a36Sopenharmony_ci	if (!IS_ENABLED(CONFIG_STACKPROTECTOR_PER_TASK))
2062306a36Sopenharmony_ci		__stack_chk_guard = current->stack_canary;
2162306a36Sopenharmony_ci}
2262306a36Sopenharmony_ci#endif /* _ASM_RISCV_STACKPROTECTOR_H */
23