1 /*
2  * Copyright 2019 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #include <stdint.h>
10 #include <stdnoreturn.h>
11 
12 #include "hf/panic.h"
13 
14 /**
15  * This is the value that is used as the stack canary. It is written to the top
16  * of the stack when entering a function and compared against the stack when
17  * exiting a function. If there is a mismatch, a failure is triggered.
18  *
19  * As the value must be the same at the beginning and end of the function, this
20  * is a global variable and there are multiple CPUs executing concurrently, this
21  * value cannot change after being initialized.
22  *
23  * TODO: initialize to a random value at boot.
24  */
25 uint64_t __attribute__((used)) __stack_chk_guard = 0x72afaf72bad0feed;
26 
27 /**
28  * Called when the stack canary is invalid. The stack can no longer be trusted
29  * so this function must not return.
30  */
__stack_chk_fail(void)31 noreturn void __stack_chk_fail(void)
32 {
33 	panic("stack corruption");
34 }
35