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