xref: /arm-trusted-firmware/plat/arm/board/fvp_r/fvp_r_stack_protector.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #include <stdint.h>
8*91f16700Schasinglulu 
9*91f16700Schasinglulu #include <fvp_r_arch_helpers.h>
10*91f16700Schasinglulu #include <plat/common/platform.h>
11*91f16700Schasinglulu 
12*91f16700Schasinglulu #define RANDOM_CANARY_VALUE ((u_register_t) 8092347823957523895ULL)
13*91f16700Schasinglulu 
14*91f16700Schasinglulu u_register_t plat_get_stack_protector_canary(void)
15*91f16700Schasinglulu {
16*91f16700Schasinglulu 	/*
17*91f16700Schasinglulu 	 * Ideally, a random number should be returned instead of the
18*91f16700Schasinglulu 	 * combination of a timer's value and a compile-time constant. As the
19*91f16700Schasinglulu 	 * FVP_R does not have any random number generator, this is better than
20*91f16700Schasinglulu 	 * nothing but not necessarily really secure.
21*91f16700Schasinglulu 	 */
22*91f16700Schasinglulu 	return RANDOM_CANARY_VALUE ^ read_cntpct_el0();
23*91f16700Schasinglulu }
24*91f16700Schasinglulu 
25