]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Include/CrtLibSupport.h
ddf7784a37be9d2a3a3fd6baf115df11cbbe3496
[mirror_edk2.git] / CryptoPkg / Include / CrtLibSupport.h
1 /** @file
2 Root include file of C runtime library to support building the third-party
3 cryptographic library.
4
5 Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __CRT_LIB_SUPPORT_H__
17 #define __CRT_LIB_SUPPORT_H__
18
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/PrintLib.h>
23
24 #define OPENSSLDIR ""
25 #define ENGINESDIR ""
26
27 #define MAX_STRING_SIZE 0x1000
28
29 //
30 // OpenSSL relies on explicit configuration for word size in crypto/bn,
31 // but we want it to be automatically inferred from the target. So we
32 // bypass what's in <openssl/opensslconf.h> for OPENSSL_SYS_UEFI, and
33 // define our own here.
34 //
35 #ifdef CONFIG_HEADER_BN_H
36 #error CONFIG_HEADER_BN_H already defined
37 #endif
38
39 #define CONFIG_HEADER_BN_H
40
41 #if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_IA64)
42 //
43 // With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs
44 // SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is
45 // 64-bit. Since using 'long long' works fine on GCC too, just do that.
46 //
47 #define SIXTY_FOUR_BIT
48 #elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)
49 #define THIRTY_TWO_BIT
50 #else
51 #error Unknown target architecture
52 #endif
53
54 //
55 // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
56 //
57 #if !defined(__CC_ARM) // if va_list is not already defined
58 #define va_list VA_LIST
59 #define va_arg VA_ARG
60 #define va_start VA_START
61 #define va_end VA_END
62 #else // __CC_ARM
63 #define va_start(Marker, Parameter) __va_start(Marker, Parameter)
64 #define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)
65 #define va_end(Marker) ((void)0)
66 #endif
67
68 //
69 // Definitions for global constants used by CRT library routines
70 //
71 #define EINVAL 22 /* Invalid argument */
72 #define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */
73 #define LONG_MAX 0X7FFFFFFFL /* max value for a long */
74 #define LONG_MIN (-LONG_MAX-1) /* min value for a long */
75 #define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */
76 #define CHAR_BIT 8 /* Number of bits in a char */
77
78 //
79 // Basic types mapping
80 //
81 typedef UINTN size_t;
82 typedef INTN ssize_t;
83 typedef INT32 time_t;
84 typedef UINT8 __uint8_t;
85 typedef UINT8 sa_family_t;
86 typedef UINT32 uid_t;
87 typedef UINT32 gid_t;
88
89 //
90 // File operations are not required for EFI building,
91 // so FILE is mapped to VOID * to pass build
92 //
93 typedef VOID *FILE;
94
95 //
96 // Structures Definitions
97 //
98 struct tm {
99 int tm_sec; /* seconds after the minute [0-60] */
100 int tm_min; /* minutes after the hour [0-59] */
101 int tm_hour; /* hours since midnight [0-23] */
102 int tm_mday; /* day of the month [1-31] */
103 int tm_mon; /* months since January [0-11] */
104 int tm_year; /* years since 1900 */
105 int tm_wday; /* days since Sunday [0-6] */
106 int tm_yday; /* days since January 1 [0-365] */
107 int tm_isdst; /* Daylight Savings Time flag */
108 long tm_gmtoff; /* offset from CUT in seconds */
109 char *tm_zone; /* timezone abbreviation */
110 };
111
112 struct timeval {
113 long tv_sec; /* time value, in seconds */
114 long tv_usec; /* time value, in microseconds */
115 };
116
117 struct sockaddr {
118 __uint8_t sa_len; /* total length */
119 sa_family_t sa_family; /* address family */
120 char sa_data[14]; /* actually longer; address value */
121 };
122
123 //
124 // Global variables
125 //
126 extern int errno;
127 extern FILE *stderr;
128
129 //
130 // Function prototypes of CRT Library routines
131 //
132 void *malloc (size_t);
133 void *realloc (void *, size_t);
134 void free (void *);
135 void *memset (void *, int, size_t);
136 int isdigit (int);
137 int isspace (int);
138 int isxdigit (int);
139 int isalnum (int);
140 int isupper (int);
141 int tolower (int);
142 int strcmp (const char *, const char *);
143 int strncasecmp (const char *, const char *, size_t);
144 char *strrchr (const char *, int);
145 unsigned long strtoul (const char *, char **, int);
146 long strtol (const char *, char **, int);
147 char *strerror (int);
148 size_t strspn (const char *, const char *);
149 size_t strcspn (const char *, const char *);
150 int printf (const char *, ...);
151 int sscanf (const char *, const char *, ...);
152 FILE *fopen (const char *, const char *);
153 size_t fread (void *, size_t, size_t, FILE *);
154 size_t fwrite (const void *, size_t, size_t, FILE *);
155 int fclose (FILE *);
156 int fprintf (FILE *, const char *, ...);
157 time_t time (time_t *);
158 struct tm *gmtime (const time_t *);
159 uid_t getuid (void);
160 uid_t geteuid (void);
161 gid_t getgid (void);
162 gid_t getegid (void);
163 void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
164 char *getenv (const char *);
165 #if defined(__GNUC__) && (__GNUC__ >= 2)
166 void abort (void) __attribute__((__noreturn__));
167 #else
168 void abort (void);
169 #endif
170
171 //
172 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
173 //
174 #define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))
175 #define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
176 #define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
177 #define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
178 #define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))
179 #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
180 #define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
181 #define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
182 #define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
183 #define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
184 #define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
185 #define strcasecmp(str1,str2) (int)AsciiStriCmp(str1,str2)
186 #define sprintf(buf,...) AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__)
187 #define localtime(timer) NULL
188 #define assert(expression)
189 #define offsetof(type,member) OFFSET_OF(type,member)
190 #define atoi(nptr) AsciiStrDecimalToUintn(nptr)
191 #define gettimeofday(tvp,tz) do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0)
192
193 #endif