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