]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
CryptoPkg/CrtLibSupport: add secure_getenv() stub function
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / SysCall / CrtWrapper.c
index 79957cc89f780ce45a5fb11b4e15750e1f9b1989..9510a4a383e6450d501ab46a9fabb6eace403038 100644 (file)
@@ -2,7 +2,7 @@
   C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based\r
   Cryptographic Library.\r
 \r
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2017, 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
@@ -13,16 +13,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <OpenSslSupport.h>\r
+#include <CrtLibSupport.h>\r
 \r
 int errno = 0;\r
 \r
 FILE  *stderr = NULL;\r
-FILE  *stdin = NULL;\r
+FILE  *stdin  = NULL;\r
 FILE  *stdout = NULL;\r
 \r
 typedef\r
-INTN\r
+int\r
 (*SORT_COMPARE)(\r
   IN  VOID  *Buffer1,\r
   IN  VOID  *Buffer2\r
@@ -136,6 +136,30 @@ char *strrchr (const char *str, int c)
   }\r
 }\r
 \r
+/* Compare first n bytes of string s1 with string s2, ignoring case */\r
+int strncasecmp (const char *s1, const char *s2, size_t n)\r
+{\r
+  int Val;\r
+\r
+  ASSERT(s1 != NULL);\r
+  ASSERT(s2 != NULL);\r
+\r
+  if (n != 0) {\r
+    do {\r
+      Val = tolower(*s1) - tolower(*s2);\r
+      if (Val != 0) {\r
+        return Val;\r
+      }\r
+      ++s1;\r
+      ++s2;\r
+      if (*s1 == '\0') {\r
+        break;\r
+      }\r
+    } while (--n != 0);\r
+  }\r
+  return 0;\r
+}\r
+\r
 /* Read formatted data from a string */\r
 int sscanf (const char *buffer, const char *format, ...)\r
 {\r
@@ -146,6 +170,70 @@ int sscanf (const char *buffer, const char *format, ...)
   return 0;\r
 }\r
 \r
+/* Maps errnum to an error-message string */\r
+char * strerror (int errnum)\r
+{\r
+  return NULL;\r
+}\r
+\r
+/* Computes the length of the maximum initial segment of the string pointed to by s1\r
+   which consists entirely of characters from the string pointed to by s2. */\r
+size_t strspn (const char *s1 , const char *s2)\r
+{\r
+  UINT8   Map[32];\r
+  UINT32  Index;\r
+  size_t  Count;\r
+\r
+  for (Index = 0; Index < 32; Index++) {\r
+    Map[Index] = 0;\r
+  }\r
+\r
+  while (*s2) {\r
+    Map[*s2 >> 3] |= (1 << (*s2 & 7));\r
+    s2++;\r
+  }\r
+\r
+  if (*s1) {\r
+    Count = 0;\r
+    while (Map[*s1 >> 3] & (1 << (*s1 & 7))) {\r
+      Count++;\r
+      s1++;\r
+    }\r
+\r
+    return Count;\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+/* Computes the length of the maximum initial segment of the string pointed to by s1\r
+   which consists entirely of characters not from the string pointed to by s2. */\r
+size_t strcspn (const char *s1, const char *s2)\r
+{\r
+  UINT8  Map[32];\r
+  UINT32 Index;\r
+  size_t Count;\r
+\r
+  for (Index = 0; Index < 32; Index++) {\r
+    Map[Index] = 0;\r
+  }\r
+\r
+  while (*s2) {\r
+    Map[*s2 >> 3] |= (1 << (*s2 & 7));\r
+    s2++;\r
+  }\r
+\r
+  Map[0] |= 1;\r
+\r
+  Count   = 0;\r
+  while (!(Map[*s1 >> 3] & (1 << (*s1 & 7)))) {\r
+    Count ++;\r
+    s1++;\r
+  }\r
+\r
+  return Count;\r
+}\r
+\r
 //\r
 // -- Character Classification Routines --\r
 //\r
@@ -244,7 +332,10 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
   ASSERT (base    != NULL);\r
   ASSERT (compare != NULL);\r
 \r
-  Buffer = AllocatePool (width);\r
+  //\r
+  // Use CRT-style malloc to cover BS and RT memory allocation.\r
+  //\r
+  Buffer = malloc (width);\r
   ASSERT (Buffer != NULL);\r
 \r
   //\r
@@ -252,7 +343,7 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
   //\r
   QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);\r
 \r
-  FreePool (Buffer);\r
+  free (Buffer);\r
   return;\r
 }\r
 \r
@@ -270,16 +361,23 @@ char *getenv (const char *varname)
   return NULL;\r
 }\r
 \r
+/* Get a value from the current environment */\r
+char *secure_getenv (const char *varname)\r
+{\r
+  //\r
+  // Null secure_getenv() function implementation to satisfy the linker, since\r
+  // there is no direct functionality logic dependency in present UEFI cases.\r
+  //\r
+  // From the secure_getenv() manual: 'just like getenv() except that it\r
+  // returns NULL in cases where "secure execution" is required'.\r
+  //\r
+  return NULL;\r
+}\r
+\r
 //\r
 // -- Stream I/O Routines --\r
 //\r
 \r
-/* Write formatted output using a pointer to a list of arguments */\r
-int vfprintf (FILE *stream, const char *format, VA_LIST arg)\r
-{\r
-  return 0;\r
-}\r
-\r
 /* Write data to a stream */\r
 size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream)\r
 {\r
@@ -300,41 +398,41 @@ int BIO_snprintf(char *buf, size_t n, const char *format, ...)
   return 0;\r
 }\r
 \r
-void *UI_OpenSSL(void)\r
-{\r
-  return NULL;\r
-}\r
-\r
-int X509_load_cert_file (VOID *ctx, const char *file, int type)\r
-{\r
-  return 0;\r
-}\r
+#ifdef __GNUC__\r
 \r
-int X509_load_crl_file (VOID *ctx, const char *file, int type)\r
-{\r
-  return 0;\r
-}\r
+typedef\r
+VOID\r
+(EFIAPI *NoReturnFuncPtr)(\r
+  VOID\r
+  ) __attribute__((__noreturn__));\r
 \r
-int chmod (const char *c, mode_t m)\r
+STATIC\r
+VOID\r
+EFIAPI\r
+NopFunction (\r
+  VOID\r
+  )\r
 {\r
-  return -1;\r
 }\r
 \r
-int close (int f)\r
+void abort (void)\r
 {\r
-  return -1;\r
-}\r
+  NoReturnFuncPtr NoReturnFunc;\r
 \r
-void closelog (void)\r
-{\r
+  NoReturnFunc = (NoReturnFuncPtr) NopFunction;\r
 \r
+  NoReturnFunc ();\r
 }\r
 \r
-void exit (int e)\r
-{\r
+#else\r
 \r
+void abort (void)\r
+{\r
+  // Do nothing\r
 }\r
 \r
+#endif\r
+\r
 int fclose (FILE *f)\r
 {\r
   return 0;\r
@@ -350,11 +448,6 @@ size_t fread (void *b, size_t c, size_t i, FILE *f)
   return 0;\r
 }\r
 \r
-int fprintf (FILE *f, const char *s, ...)\r
-{\r
-  return 0;\r
-}\r
-\r
 uid_t getuid (void)\r
 {\r
   return 0;\r
@@ -375,42 +468,7 @@ gid_t getegid (void)
   return 0;\r
 }\r
 \r
-off_t lseek (int a, off_t o, int d)\r
-{\r
-  return 0;\r
-}\r
-\r
-void openlog (const char *c, int a, int b)\r
-{\r
-\r
-}\r
-\r
-ssize_t read (int f, void *b, size_t c)\r
-{\r
-  return 0;\r
-}\r
-\r
-int stat (const char *c, struct stat *s)\r
-{\r
-  return -1;\r
-}\r
-\r
-int strcasecmp (const char *c, const char *s)\r
-{\r
-  return 0;\r
-}\r
-\r
-int strncasecmp (const char *c, const char *s, size_t l)\r
-{\r
-  return 0;\r
-}\r
-\r
-void syslog (int a, const char *c, ...)\r
-{\r
-\r
-}\r
-\r
-ssize_t write (int f, const void *b, size_t l)\r
+int printf (char const *fmt, ...)\r
 {\r
   return 0;\r
 }\r