]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/IntrinsicLib/MemoryIntrinsics.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / CryptoPkg / Library / IntrinsicLib / MemoryIntrinsics.c
index afaa0b74ee26b904e556564f59b45bd706b552cd..611e9fd773b0803f3b87282516176d2926ac5265 100644 (file)
@@ -2,27 +2,42 @@
   Intrinsic Memory Routines Wrapper Implementation for OpenSSL-based\r
   Cryptographic Library.\r
 \r
-Copyright (c) 2010, Intel Corporation. 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
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include <Base.h>\r
 #include <Library/BaseMemoryLib.h>\r
+#include <Library/BaseLib.h>\r
+\r
+typedef UINTN size_t;\r
+\r
+#if defined (__GNUC__) || defined (__clang__)\r
+#define GLOBAL_USED  __attribute__((used))\r
+#else\r
+#define GLOBAL_USED\r
+#endif\r
 \r
 /* OpenSSL will use floating point support, and C compiler produces the _fltused\r
    symbol by default. Simply define this symbol here to satisfy the linker. */\r
-int _fltused = 1;\r
+int  GLOBAL_USED  _fltused = 1;\r
 \r
 /* Sets buffers to a specified character */\r
-void * memset (void *dest, char ch, unsigned int count)\r
+void *\r
+memset (\r
+  void    *dest,\r
+  int     ch,\r
+  size_t  count\r
+  )\r
 {\r
+  //\r
+  // NOTE: Here we use one base implementation for memset, instead of the direct\r
+  //       optimized SetMem() wrapper. Because the IntrinsicLib has to be built\r
+  //       without whole program optimization option, and there will be some\r
+  //       potential register usage errors when calling other optimized codes.\r
+  //\r
+\r
   //\r
   // Declare the local variables that actually move the data elements as\r
   // volatile to prevent the optimizer from replacing this function with\r
@@ -32,8 +47,28 @@ void * memset (void *dest, char ch, unsigned int count)
 \r
   Pointer = (UINT8 *)dest;\r
   while (count-- != 0) {\r
-    *(Pointer++) = ch;\r
+    *(Pointer++) = (UINT8)ch;\r
   }\r
-  \r
+\r
   return dest;\r
 }\r
+\r
+/* Compare bytes in two buffers. */\r
+int\r
+memcmp (\r
+  const void  *buf1,\r
+  const void  *buf2,\r
+  size_t      count\r
+  )\r
+{\r
+  return (int)CompareMem (buf1, buf2, count);\r
+}\r
+\r
+int\r
+strcmp (\r
+  const char  *s1,\r
+  const char  *s2\r
+  )\r
+{\r
+  return (int)AsciiStrCmp (s1, s2);\r
+}\r