]>
Commit | Line | Data |
---|---|---|
fc9fa685 QL |
1 | /** @file\r |
2 | Root include file of C runtime library to support building the third-party\r | |
3 | cryptographic library.\r | |
4 | \r | |
c1e66210 | 5 | Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.<BR>\r |
9025a014 | 6 | Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>\r |
2009f6b4 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
fc9fa685 QL |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #ifndef __CRT_LIB_SUPPORT_H__\r | |
12 | #define __CRT_LIB_SUPPORT_H__\r | |
13 | \r | |
14 | #include <Library/BaseLib.h>\r | |
15 | #include <Library/BaseMemoryLib.h>\r | |
16 | #include <Library/DebugLib.h>\r | |
17 | #include <Library/PrintLib.h>\r | |
18 | \r | |
7c342378 MK |
19 | #define OPENSSLDIR ""\r |
20 | #define ENGINESDIR ""\r | |
fc9fa685 QL |
21 | \r |
22 | #define MAX_STRING_SIZE 0x1000\r | |
23 | \r | |
456dd8b9 XL |
24 | //\r |
25 | // We already have "no-ui" in out Configure invocation.\r | |
26 | // but the code still fails to compile.\r | |
27 | // Ref: https://github.com/openssl/openssl/issues/8904\r | |
28 | //\r | |
29 | // This is defined in CRT library(stdio.h).\r | |
30 | //\r | |
31 | #ifndef BUFSIZ\r | |
32 | #define BUFSIZ 8192\r | |
33 | #endif\r | |
34 | \r | |
fc9fa685 QL |
35 | //\r |
36 | // OpenSSL relies on explicit configuration for word size in crypto/bn,\r | |
37 | // but we want it to be automatically inferred from the target. So we\r | |
38 | // bypass what's in <openssl/opensslconf.h> for OPENSSL_SYS_UEFI, and\r | |
39 | // define our own here.\r | |
40 | //\r | |
41 | #ifdef CONFIG_HEADER_BN_H\r | |
7c342378 | 42 | #error CONFIG_HEADER_BN_H already defined\r |
fc9fa685 QL |
43 | #endif\r |
44 | \r | |
45 | #define CONFIG_HEADER_BN_H\r | |
46 | \r | |
7c342378 MK |
47 | #if !defined (SIXTY_FOUR_BIT) && !defined (THIRTY_TWO_BIT)\r |
48 | #if defined (MDE_CPU_X64) || defined (MDE_CPU_AARCH64) || defined (MDE_CPU_IA64) || defined (MDE_CPU_RISCV64)\r | |
fc9fa685 QL |
49 | //\r |
50 | // With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs\r | |
51 | // SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is\r | |
52 | // 64-bit. Since using 'long long' works fine on GCC too, just do that.\r | |
53 | //\r | |
54 | #define SIXTY_FOUR_BIT\r | |
7c342378 | 55 | #elif defined (MDE_CPU_IA32) || defined (MDE_CPU_ARM) || defined (MDE_CPU_EBC)\r |
fc9fa685 | 56 | #define THIRTY_TWO_BIT\r |
7c342378 MK |
57 | #else\r |
58 | #error Unknown target architecture\r | |
59 | #endif\r | |
d0bf83e1 | 60 | #endif\r |
fc9fa685 QL |
61 | \r |
62 | //\r | |
63 | // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h\r | |
64 | //\r | |
7c342378 | 65 | #if !defined (__CC_ARM) // if va_list is not already defined\r |
fc9fa685 QL |
66 | #define va_list VA_LIST\r |
67 | #define va_arg VA_ARG\r | |
68 | #define va_start VA_START\r | |
69 | #define va_end VA_END\r | |
70 | #else // __CC_ARM\r | |
7c342378 MK |
71 | #define va_start(Marker, Parameter) __va_start(Marker, Parameter)\r |
72 | #define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)\r | |
73 | #define va_end(Marker) ((void)0)\r | |
fc9fa685 QL |
74 | #endif\r |
75 | \r | |
76 | //\r | |
77 | // Definitions for global constants used by CRT library routines\r | |
78 | //\r | |
7c342378 MK |
79 | #define EINVAL 22 /* Invalid argument */\r |
80 | #define EAFNOSUPPORT 47 /* Address family not supported by protocol family */\r | |
81 | #define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */\r | |
82 | #define LONG_MAX 0X7FFFFFFFL /* max value for a long */\r | |
83 | #define LONG_MIN (-LONG_MAX-1) /* min value for a long */\r | |
84 | #define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */\r | |
85 | #define CHAR_BIT 8 /* Number of bits in a char */\r | |
fc9fa685 | 86 | \r |
2ac41c12 LE |
87 | //\r |
88 | // Address families.\r | |
89 | //\r | |
90 | #define AF_INET 2 /* internetwork: UDP, TCP, etc. */\r | |
91 | #define AF_INET6 24 /* IP version 6 */\r | |
92 | \r | |
93 | //\r | |
94 | // Define constants based on RFC0883, RFC1034, RFC 1035\r | |
95 | //\r | |
96 | #define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */\r | |
97 | #define NS_INADDRSZ 4 /*%< IPv4 T_A */\r | |
98 | #define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */\r | |
99 | \r | |
fc9fa685 QL |
100 | //\r |
101 | // Basic types mapping\r | |
102 | //\r | |
7c342378 MK |
103 | typedef UINTN size_t;\r |
104 | typedef UINTN u_int;\r | |
105 | typedef INTN ptrdiff_t;\r | |
106 | typedef INTN ssize_t;\r | |
107 | typedef INT32 time_t;\r | |
108 | typedef UINT8 __uint8_t;\r | |
109 | typedef UINT8 sa_family_t;\r | |
110 | typedef UINT8 u_char;\r | |
111 | typedef UINT32 uid_t;\r | |
112 | typedef UINT32 gid_t;\r | |
113 | typedef CHAR16 wchar_t;\r | |
fc9fa685 QL |
114 | \r |
115 | //\r | |
116 | // File operations are not required for EFI building,\r | |
117 | // so FILE is mapped to VOID * to pass build\r | |
118 | //\r | |
7c342378 | 119 | typedef VOID *FILE;\r |
fc9fa685 QL |
120 | \r |
121 | //\r | |
122 | // Structures Definitions\r | |
123 | //\r | |
124 | struct tm {\r | |
7c342378 MK |
125 | int tm_sec; /* seconds after the minute [0-60] */\r |
126 | int tm_min; /* minutes after the hour [0-59] */\r | |
127 | int tm_hour; /* hours since midnight [0-23] */\r | |
128 | int tm_mday; /* day of the month [1-31] */\r | |
129 | int tm_mon; /* months since January [0-11] */\r | |
130 | int tm_year; /* years since 1900 */\r | |
131 | int tm_wday; /* days since Sunday [0-6] */\r | |
132 | int tm_yday; /* days since January 1 [0-365] */\r | |
133 | int tm_isdst; /* Daylight Savings Time flag */\r | |
134 | long tm_gmtoff; /* offset from CUT in seconds */\r | |
135 | char *tm_zone; /* timezone abbreviation */\r | |
fc9fa685 QL |
136 | };\r |
137 | \r | |
138 | struct timeval {\r | |
7c342378 MK |
139 | long tv_sec; /* time value, in seconds */\r |
140 | long tv_usec; /* time value, in microseconds */\r | |
fc9fa685 QL |
141 | };\r |
142 | \r | |
143 | struct sockaddr {\r | |
7c342378 MK |
144 | __uint8_t sa_len; /* total length */\r |
145 | sa_family_t sa_family; /* address family */\r | |
146 | char sa_data[14]; /* actually longer; address value */\r | |
fc9fa685 QL |
147 | };\r |
148 | \r | |
149 | //\r | |
150 | // Global variables\r | |
151 | //\r | |
7c342378 MK |
152 | extern int errno;\r |
153 | extern FILE *stderr;\r | |
fc9fa685 QL |
154 | \r |
155 | //\r | |
156 | // Function prototypes of CRT Library routines\r | |
157 | //\r | |
7c342378 MK |
158 | void *\r |
159 | malloc (\r | |
160 | size_t\r | |
161 | );\r | |
162 | \r | |
163 | void *\r | |
164 | realloc (\r | |
165 | void *,\r | |
166 | size_t\r | |
167 | );\r | |
168 | \r | |
169 | void\r | |
170 | free (\r | |
171 | void *\r | |
172 | );\r | |
173 | \r | |
174 | void *\r | |
175 | memset (\r | |
176 | void *,\r | |
177 | int,\r | |
178 | size_t\r | |
179 | );\r | |
180 | \r | |
181 | int\r | |
182 | memcmp (\r | |
183 | const void *,\r | |
184 | const void *,\r | |
185 | size_t\r | |
186 | );\r | |
187 | \r | |
188 | int\r | |
189 | isdigit (\r | |
190 | int\r | |
191 | );\r | |
192 | \r | |
193 | int\r | |
194 | isspace (\r | |
195 | int\r | |
196 | );\r | |
197 | \r | |
198 | int\r | |
199 | isxdigit (\r | |
200 | int\r | |
201 | );\r | |
202 | \r | |
203 | int\r | |
204 | isalnum (\r | |
205 | int\r | |
206 | );\r | |
207 | \r | |
208 | int\r | |
209 | isupper (\r | |
210 | int\r | |
211 | );\r | |
212 | \r | |
213 | int\r | |
214 | tolower (\r | |
215 | int\r | |
216 | );\r | |
217 | \r | |
218 | int\r | |
219 | strcmp (\r | |
220 | const char *,\r | |
221 | const char *\r | |
222 | );\r | |
223 | \r | |
224 | int\r | |
225 | strncasecmp (\r | |
226 | const char *,\r | |
227 | const char *,\r | |
228 | size_t\r | |
229 | );\r | |
230 | \r | |
231 | char *\r | |
232 | strchr (\r | |
233 | const char *,\r | |
234 | int\r | |
235 | );\r | |
236 | \r | |
237 | char *\r | |
238 | strrchr (\r | |
239 | const char *,\r | |
240 | int\r | |
241 | );\r | |
242 | \r | |
243 | unsigned long\r | |
244 | strtoul (\r | |
245 | const char *,\r | |
246 | char **,\r | |
247 | int\r | |
248 | );\r | |
249 | \r | |
250 | long\r | |
251 | strtol (\r | |
252 | const char *,\r | |
253 | char **,\r | |
254 | int\r | |
255 | );\r | |
256 | \r | |
257 | char *\r | |
258 | strerror (\r | |
259 | int\r | |
260 | );\r | |
261 | \r | |
262 | size_t\r | |
263 | strspn (\r | |
264 | const char *,\r | |
265 | const char *\r | |
266 | );\r | |
267 | \r | |
268 | size_t\r | |
269 | strcspn (\r | |
270 | const char *,\r | |
271 | const char *\r | |
272 | );\r | |
273 | \r | |
274 | int\r | |
275 | printf (\r | |
276 | const char *,\r | |
277 | ...\r | |
278 | );\r | |
279 | \r | |
280 | int\r | |
281 | sscanf (\r | |
282 | const char *,\r | |
283 | const char *,\r | |
284 | ...\r | |
285 | );\r | |
286 | \r | |
287 | FILE *\r | |
288 | fopen (\r | |
289 | const char *,\r | |
290 | const char *\r | |
291 | );\r | |
292 | \r | |
293 | size_t\r | |
294 | fread (\r | |
295 | void *,\r | |
296 | size_t,\r | |
297 | size_t,\r | |
298 | FILE *\r | |
299 | );\r | |
300 | \r | |
301 | size_t\r | |
302 | fwrite (\r | |
303 | const void *,\r | |
304 | size_t,\r | |
305 | size_t,\r | |
306 | FILE *\r | |
307 | );\r | |
308 | \r | |
309 | int\r | |
310 | fclose (\r | |
311 | FILE *\r | |
312 | );\r | |
313 | \r | |
314 | int\r | |
315 | fprintf (\r | |
316 | FILE *,\r | |
317 | const char *,\r | |
318 | ...\r | |
319 | );\r | |
320 | \r | |
321 | time_t\r | |
322 | time (\r | |
323 | time_t *\r | |
324 | );\r | |
325 | \r | |
326 | struct tm *\r | |
327 | gmtime (\r | |
328 | const time_t *\r | |
329 | );\r | |
330 | \r | |
331 | uid_t\r | |
332 | getuid (\r | |
333 | void\r | |
334 | );\r | |
335 | \r | |
336 | uid_t\r | |
337 | geteuid (\r | |
338 | void\r | |
339 | );\r | |
340 | \r | |
341 | gid_t\r | |
342 | getgid (\r | |
343 | void\r | |
344 | );\r | |
345 | \r | |
346 | gid_t\r | |
347 | getegid (\r | |
348 | void\r | |
349 | );\r | |
350 | \r | |
351 | int\r | |
352 | issetugid (\r | |
353 | void\r | |
354 | );\r | |
355 | \r | |
356 | void\r | |
357 | qsort (\r | |
358 | void *,\r | |
359 | size_t,\r | |
360 | size_t,\r | |
361 | int (*)(const void *, const void *)\r | |
362 | );\r | |
363 | \r | |
364 | char *\r | |
365 | getenv (\r | |
366 | const char *\r | |
367 | );\r | |
368 | \r | |
369 | char *\r | |
370 | secure_getenv (\r | |
371 | const char *\r | |
372 | );\r | |
373 | \r | |
374 | #if defined (__GNUC__) && (__GNUC__ >= 2)\r | |
375 | void\r | |
376 | abort (\r | |
377 | void\r | |
378 | ) __attribute__ ((__noreturn__));\r | |
379 | \r | |
fc9fa685 | 380 | #else\r |
7c342378 MK |
381 | void\r |
382 | abort (\r | |
383 | void\r | |
384 | );\r | |
385 | \r | |
fc9fa685 | 386 | #endif\r |
7c342378 MK |
387 | int\r |
388 | inet_pton (\r | |
389 | int,\r | |
390 | const char *,\r | |
391 | void *\r | |
392 | );\r | |
fc9fa685 QL |
393 | \r |
394 | //\r | |
395 | // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions\r | |
396 | //\r | |
7c342378 MK |
397 | #define memcpy(dest, source, count) CopyMem(dest,source,(UINTN)(count))\r |
398 | #define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch))\r | |
399 | #define memchr(buf, ch, count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)\r | |
400 | #define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))\r | |
401 | #define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count))\r | |
402 | #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))\r | |
403 | #define strcpy(strDest, strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)\r | |
404 | #define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)\r | |
405 | #define strcat(strDest, strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)\r | |
406 | #define strncmp(string1, string2, count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))\r | |
407 | #define strcasecmp(str1, str2) (int)AsciiStriCmp(str1,str2)\r | |
408 | #define sprintf(buf, ...) AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__)\r | |
409 | #define localtime(timer) NULL\r | |
fc9fa685 | 410 | #define assert(expression)\r |
7c342378 MK |
411 | #define offsetof(type, member) OFFSET_OF(type,member)\r |
412 | #define atoi(nptr) AsciiStrDecimalToUintn(nptr)\r | |
413 | #define gettimeofday(tvp, tz) do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0)\r | |
fc9fa685 QL |
414 | \r |
415 | #endif\r |