]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Introduced BaseStackCheckLib (cont.)
authorAndrew Fish <afish@apple.com>
Wed, 20 Aug 2014 18:00:38 +0000 (18:00 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 20 Aug 2014 18:00:38 +0000 (18:00 +0000)
This library only support GCC, RVCT and XCode for now.
The new files were missing from SVN rev15851.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Andrew Fish <afish@apple.com>
Signed-off-by: Olivier Martin <olivier.martin@arm.com
Reviewed-by: Gao, Liming <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15852 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c [new file with mode: 0644]
MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf [new file with mode: 0644]

diff --git a/MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c b/MdePkg/Library/BaseStackCheckLib/BaseStackCheckGcc.c
new file mode 100644 (file)
index 0000000..ecf77f0
--- /dev/null
@@ -0,0 +1,55 @@
+/** @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
diff --git a/MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf b/MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
new file mode 100644 (file)
index 0000000..3304284
--- /dev/null
@@ -0,0 +1,42 @@
+## @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