juno_stack_protector.c 560 Bytes
Newer Older
1
2
3
/*
 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
7
 */

#include <arch_helpers.h>
8
9
#include <common/debug.h>
#include <lib/utils.h>
10
#include <platform_def.h>
11

12
13
14
15
#include "juno_decl.h"

u_register_t plat_get_stack_protector_canary(void)
{
16
	uint64_t entropy;
17

18
	if (!juno_getentropy(&entropy)) {
19
20
21
22
		ERROR("Not enough entropy to initialize canary value\n");
		panic();
	}

23
24
25
26
27
	if (sizeof(entropy) == sizeof(u_register_t)) {
		return entropy;
	}

	return (entropy & 0xffffffffULL) ^ (entropy >> 32);
28
}