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