]> git.proxmox.com Git - efi-boot-shim.git/blobdiff - Cryptlib/Include/OpenSslSupport.h
New upstream version 15+1531942534.dd3230d
[efi-boot-shim.git] / Cryptlib / Include / OpenSslSupport.h
index b77838db3a6c9bcaaa3bea461e4fc20393e2c47d..b38043cb9e827df9c99ebe596c658e37efa1d473 100644 (file)
@@ -17,14 +17,44 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <efi.h>\r
 #include <efilib.h>\r
-#include <Base.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/DebugLib.h>\r
+#include "Base.h"\r
+#include "Library/BaseLib.h"\r
+#include "Library/BaseMemoryLib.h"\r
+#include "Library/MemoryAllocationLib.h"\r
+#include "Library/DebugLib.h"\r
+\r
+/*\r
+ * Include stddef.h to avoid redefining "offsetof"\r
+ */\r
+#include <stddef.h>\r
 \r
 #define CONST const\r
 \r
+//\r
+// OpenSSL relies on explicit configuration for word size in crypto/bn,\r
+// but we want it to be automatically inferred from the target. So we\r
+// bypass what's in <openssl/opensslconf.h> for OPENSSL_SYS_UEFI, and\r
+// define our own here.\r
+//\r
+#ifdef CONFIG_HEADER_BN_H\r
+#error CONFIG_HEADER_BN_H already defined\r
+#endif\r
+\r
+#define CONFIG_HEADER_BN_H\r
+\r
+#if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_IA64)\r
+//\r
+// With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs\r
+// SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is\r
+// 64-bit. Since using 'long long' works fine on GCC too, just do that.\r
+//\r
+#define SIXTY_FOUR_BIT\r
+#elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)\r
+#define THIRTY_TWO_BIT\r
+#else\r
+#error Unknown target architecture\r
+#endif\r
+\r
 //\r
 // File operations are not required for building Open SSL, \r
 // so FILE is mapped to VOID * to pass build\r
@@ -47,6 +77,9 @@ typedef VOID  *FILE;
 #define va_arg    VA_ARG\r
 #define va_start  VA_START\r
 #define va_end    VA_END\r
+\r
+# if !defined(NO_BUILTIN_VA_FUNCS)\r
+\r
 typedef __builtin_va_list VA_LIST;\r
 \r
 #define VA_START(Marker, Parameter)  __builtin_va_start (Marker, Parameter)\r
@@ -57,6 +90,78 @@ typedef __builtin_va_list VA_LIST;
 \r
 #define VA_COPY(Dest, Start)         __builtin_va_copy (Dest, Start)\r
 \r
+# else\r
+\r
+#define _INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1))\r
+///\r
+/// Variable used to traverse the list of arguments. This type can vary by\r
+/// implementation and could be an array or structure.\r
+///\r
+typedef CHAR8 *VA_LIST;\r
+\r
+/**\r
+  Retrieves a pointer to the beginning of a variable argument list, based on\r
+  the name of the parameter that immediately precedes the variable argument list.\r
+\r
+  This function initializes Marker to point to the beginning of the variable\r
+  argument list that immediately follows Parameter.  The method for computing the\r
+  pointer to the next argument in the argument list is CPU-specific following the\r
+  EFIAPI ABI.\r
+\r
+  @param   Marker       The VA_LIST used to traverse the list of arguments.\r
+  @param   Parameter    The name of the parameter that immediately precedes\r
+                        the variable argument list.\r
+\r
+  @return  A pointer to the beginning of a variable argument list.\r
+\r
+**/\r
+#define VA_START(Marker, Parameter) (Marker = (VA_LIST) ((UINTN) & (Parameter) + _INT_SIZE_OF (Parameter)))\r
+\r
+/**\r
+  Returns an argument of a specified type from a variable argument list and updates\r
+  the pointer to the variable argument list to point to the next argument.\r
+\r
+  This function returns an argument of the type specified by TYPE from the beginning\r
+  of the variable argument list specified by Marker.  Marker is then updated to point\r
+  to the next argument in the variable argument list.  The method for computing the\r
+  pointer to the next argument in the argument list is CPU-specific following the EFIAPI ABI.\r
+\r
+  @param   Marker   VA_LIST used to traverse the list of arguments.\r
+  @param   TYPE     The type of argument to retrieve from the beginning\r
+                    of the variable argument list.\r
+\r
+  @return  An argument of the type specified by TYPE.\r
+\r
+**/\r
+#define VA_ARG(Marker, TYPE)   (*(TYPE *) ((Marker += _INT_SIZE_OF (TYPE)) - _INT_SIZE_OF (TYPE)))\r
+\r
+/**\r
+  Terminates the use of a variable argument list.\r
+\r
+  This function initializes Marker so it can no longer be used with VA_ARG().\r
+  After this macro is used, the only way to access the variable argument list is\r
+  by using VA_START() again.\r
+\r
+  @param   Marker   VA_LIST used to traverse the list of arguments.\r
+\r
+**/\r
+#define VA_END(Marker)      (Marker = (VA_LIST) 0)\r
+\r
+/**\r
+  Initializes a VA_LIST as a copy of an existing VA_LIST.\r
+\r
+  This macro initializes Dest as a copy of Start, as if the VA_START macro had been applied to Dest\r
+  followed by the same sequence of uses of the VA_ARG macro as had previously been used to reach\r
+  the present state of Start.\r
+\r
+  @param   Dest   VA_LIST used to traverse the list of arguments.\r
+  @param   Start  VA_LIST used to traverse the list of arguments.\r
+\r
+**/\r
+#define VA_COPY(Dest, Start)  ((void)((Dest) = (Start)))\r
+\r
+# endif\r
+\r
 #else // __CC_ARM\r
 #define va_start(Marker, Parameter)   __va_start(Marker, Parameter)\r
 #define va_arg(Marker, TYPE)          __va_arg(Marker, TYPE)\r
@@ -95,7 +200,7 @@ typedef __builtin_va_list VA_LIST;
    For pre-Standard C compilers, here is a version that usually works\r
    (but watch out!): */\r
 #ifndef offsetof\r
-#define offsetof(type, member) ( (int) & ((type*)0) -> member )\r
+#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)\r
 #endif\r
 \r
 //\r
@@ -133,6 +238,11 @@ struct tm {
   char  *tm_zone;   /* timezone abbreviation */\r
 };\r
 \r
+struct timeval {\r
+  long tv_sec;      /* time value, in seconds */\r
+  long tv_usec;     /* time value, in microseconds */\r
+};\r
+\r
 struct dirent {\r
   UINT32  d_fileno;         /* file number of entry */\r
   UINT16  d_reclen;         /* length of this record */\r
@@ -200,6 +310,9 @@ int            strncmp     (const char *, const char *, size_t);
 char           *strrchr    (const char *, int);\r
 unsigned long  strtoul     (const char *, char **, int);\r
 long           strtol      (const char *, char **, int);\r
+char           *strerror   (int);\r
+size_t         strspn      (const char *, const char *);\r
+size_t         strcspn     (const char *, const char *);\r
 int            printf      (const char *, ...);\r
 int            sscanf      (const char *, const char *, ...);\r
 int            open        (const char *, int, ...);\r
@@ -246,26 +359,27 @@ extern FILE  *stdin;
 extern FILE  *stdout;\r
 \r
 #define AsciiStrLen(x) strlena(x)\r
-#define AsciiStrnCmp(s1, s2, len) strncmpa(s1, s2, len)\r
+#define AsciiStrnCmp(s1, s2, len) strncmpa((CHAR8 *)s1, (CHAR8 *)s2, len)\r
 \r
 //\r
 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions\r
 //\r
 #define memcpy(dest,source,count)         ( {CopyMem(dest,source,(UINTN)(count)); dest; })\r
 #define memset(dest,ch,count)             SetMem(dest,(UINTN)(count),(UINT8)(ch))\r
-#define memchr(buf,ch,count)              ScanMem8(buf,(UINTN)(count),(UINT8)ch)\r
+#define memchr(buf,ch,count)              ScanMem8((CHAR8 *)buf,(UINTN)(count),ch)\r
 #define memcmp(buf1,buf2,count)           (int)(CompareMem(buf1,buf2,(UINTN)(count)))\r
 #define memmove(dest,source,count)        CopyMem(dest,source,(UINTN)(count))\r
-#define strcmp                            strcmpa\r
-#define strncmp(string1,string2,count)    (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))\r
+#define strlen(str)                       (size_t)(AsciiStrLen((CHAR8 *)str))\r
 #define strcpy(strDest,strSource)         AsciiStrCpy(strDest,strSource)\r
 #define strncpy(strDest,strSource,count)  AsciiStrnCpy(strDest,strSource,(UINTN)count)\r
-#define strlen(str)                       (size_t)(AsciiStrLen(str))\r
 #define strcat(strDest,strSource)         AsciiStrCat(strDest,strSource)\r
-#define strchr(str,ch)                    ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)\r
-#define abort()                           ASSERT (FALSE)\r
-#define assert(expression)\r
+#define strchr(str,ch)                    (char *)(ScanMem8((CHAR8 *)str,AsciiStrSize((CHAR8 *)str),ch))\r
+#define strncmp(string1,string2,count)    (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))\r
 #define localtime(timer)                  NULL\r
+#define assert(expression)\r
+#define atoi(nptr)                        AsciiStrDecimalToUintn(nptr)\r
+#define gettimeofday(tvp,tz)              do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0)\r
 #define gmtime_r(timer,result)            (result = NULL)\r
+#define abort()\r
 \r
 #endif\r