--- /dev/null
+/** @file\r
+ Base Stack Check library for GCC/clang.\r
+\r
+ Use -fstack-protector-all compiler flag to make the compiler insert the\r
+ __stack_chk_guard "canary" value into the stack and check the value prior\r
+ to exiting the function. If the "canary" is overwritten __stack_chk_fail()\r
+ is called. This is GCC specific code.\r
+\r
+ Copyright (c) 2012, Apple Inc. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+/// "canary" value that is inserted by the compiler into the stack frame.\r
+VOID *__stack_chk_guard = (VOID*)FixedPcdGet64 (PcdBaseStackCanary);\r
+\r
+// If ASLR was enabled we could use\r
+//void (*__stack_chk_guard)(void) = __stack_chk_fail;\r
+\r
+/**\r
+ Error path for compiler generated stack "canary" value check code. If the\r
+ stack canary has been overwritten this function gets called on exit of the\r
+ function.\r
+**/\r
+VOID\r
+__stack_chk_fail (\r
+ VOID\r
+ )\r
+{\r
+ UINT8 DebugPropertyMask;\r
+\r
+ DEBUG ((DEBUG_ERROR, "STACK FAULT: Buffer Overflow in function %a.\n", __builtin_return_address(0)));\r
+\r
+ //\r
+ // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings even if\r
+ // BaseDebugLibNull is in use.\r
+ //\r
+ DebugPropertyMask = PcdGet8 (PcdDebugPropertyMask);\r
+ if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
+ CpuBreakpoint ();\r
+ } else if ((DebugPropertyMask & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
+ CpuDeadLoop ();\r
+ }\r
+}\r
--- /dev/null
+## @file\r
+# Stack Check Library\r
+#\r
+# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = BaseStackCheckLib\r
+ FILE_GUID = 5f6579f7-b648-4fdb-9f19-4c17e27e8eff\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = NULL\r
+\r
+\r
+#\r
+# VALID_ARCHITECTURES = ARM AARCH64\r
+#\r
+\r
+[Sources]\r
+ BaseStackCheckGcc.c | GCC\r
+ BaseStackCheckGcc.c | RVCT\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ DebugLib\r
+\r
+[FixedPcd]\r
+ gEfiMdePkgTokenSpaceGuid.PcdBaseStackCanary\r
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask\r