stack_protector.c 759 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * Copyright (c) 2017, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <common/debug.h>
  8. #include <plat/common/platform.h>
  9. /*
  10. * Canary value used by the compiler runtime checks to detect stack corruption.
  11. *
  12. * Force the canary to be in .data to allow predictable memory layout relatively
  13. * to the stacks.
  14. */
  15. u_register_t __attribute__((section(".data.stack_protector_canary")))
  16. __stack_chk_guard = (u_register_t) 3288484550995823360ULL;
  17. /*
  18. * Function called when the stack's canary check fails, which means the stack
  19. * was corrupted. It must not return.
  20. */
  21. void __dead2 __stack_chk_fail(void)
  22. {
  23. #if DEBUG
  24. ERROR("Stack corruption detected\n");
  25. #endif
  26. panic();
  27. }