]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/Include/CrtLibSupport.h
CryptoPkg/CrtLibSupport: add off_t
[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 off_t;
108 typedef UINTN u_int;
109 typedef INTN ptrdiff_t;
110 typedef INTN ssize_t;
111 typedef INT32 time_t;
112 typedef UINT8 __uint8_t;
113 typedef UINT8 sa_family_t;
114 typedef UINT8 u_char;
115 typedef UINT32 uid_t;
116 typedef UINT32 gid_t;
117 typedef CHAR16 wchar_t;
118
119 //
120 // File operations are not required for EFI building,
121 // so FILE is mapped to VOID * to pass build
122 //
123 typedef VOID *FILE;
124
125 //
126 // Structures Definitions
127 //
128 struct tm {
129 int tm_sec; /* seconds after the minute [0-60] */
130 int tm_min; /* minutes after the hour [0-59] */
131 int tm_hour; /* hours since midnight [0-23] */
132 int tm_mday; /* day of the month [1-31] */
133 int tm_mon; /* months since January [0-11] */
134 int tm_year; /* years since 1900 */
135 int tm_wday; /* days since Sunday [0-6] */
136 int tm_yday; /* days since January 1 [0-365] */
137 int tm_isdst; /* Daylight Savings Time flag */
138 long tm_gmtoff; /* offset from CUT in seconds */
139 char *tm_zone; /* timezone abbreviation */
140 };
141
142 struct timeval {
143 long tv_sec; /* time value, in seconds */
144 long tv_usec; /* time value, in microseconds */
145 };
146
147 struct sockaddr {
148 __uint8_t sa_len; /* total length */
149 sa_family_t sa_family; /* address family */
150 char sa_data[14]; /* actually longer; address value */
151 };
152
153 //
154 // Global variables
155 //
156 extern int errno;
157 extern FILE *stderr;
158
159 //
160 // Function prototypes of CRT Library routines
161 //
162 void *
163 malloc (
164 size_t
165 );
166
167 void *
168 realloc (
169 void *,
170 size_t
171 );
172
173 void
174 free (
175 void *
176 );
177
178 void *
179 memset (
180 void *,
181 int,
182 size_t
183 );
184
185 int
186 memcmp (
187 const void *,
188 const void *,
189 size_t
190 );
191
192 int
193 isdigit (
194 int
195 );
196
197 int
198 isspace (
199 int
200 );
201
202 int
203 isxdigit (
204 int
205 );
206
207 int
208 isalnum (
209 int
210 );
211
212 int
213 isupper (
214 int
215 );
216
217 int
218 tolower (
219 int
220 );
221
222 int
223 strcmp (
224 const char *,
225 const char *
226 );
227
228 int
229 strncasecmp (
230 const char *,
231 const char *,
232 size_t
233 );
234
235 char *
236 strchr (
237 const char *,
238 int
239 );
240
241 char *
242 strrchr (
243 const char *,
244 int
245 );
246
247 unsigned long
248 strtoul (
249 const char *,
250 char **,
251 int
252 );
253
254 long
255 strtol (
256 const char *,
257 char **,
258 int
259 );
260
261 char *
262 strerror (
263 int
264 );
265
266 size_t
267 strspn (
268 const char *,
269 const char *
270 );
271
272 size_t
273 strcspn (
274 const char *,
275 const char *
276 );
277
278 int
279 printf (
280 const char *,
281 ...
282 );
283
284 int
285 sscanf (
286 const char *,
287 const char *,
288 ...
289 );
290
291 FILE *
292 fopen (
293 const char *,
294 const char *
295 );
296
297 size_t
298 fread (
299 void *,
300 size_t,
301 size_t,
302 FILE *
303 );
304
305 size_t
306 fwrite (
307 const void *,
308 size_t,
309 size_t,
310 FILE *
311 );
312
313 int
314 fclose (
315 FILE *
316 );
317
318 int
319 fprintf (
320 FILE *,
321 const char *,
322 ...
323 );
324
325 time_t
326 time (
327 time_t *
328 );
329
330 struct tm *
331 gmtime (
332 const time_t *
333 );
334
335 uid_t
336 getuid (
337 void
338 );
339
340 uid_t
341 geteuid (
342 void
343 );
344
345 gid_t
346 getgid (
347 void
348 );
349
350 gid_t
351 getegid (
352 void
353 );
354
355 int
356 issetugid (
357 void
358 );
359
360 void
361 qsort (
362 void *,
363 size_t,
364 size_t,
365 int (*)(const void *, const void *)
366 );
367
368 char *
369 getenv (
370 const char *
371 );
372
373 char *
374 secure_getenv (
375 const char *
376 );
377
378 #if defined (__GNUC__) && (__GNUC__ >= 2)
379 void
380 abort (
381 void
382 ) __attribute__ ((__noreturn__));
383
384 #else
385 void
386 abort (
387 void
388 );
389
390 #endif
391 int
392 inet_pton (
393 int,
394 const char *,
395 void *
396 );
397
398 //
399 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
400 //
401 #define memcpy(dest, source, count) CopyMem(dest,source,(UINTN)(count))
402 #define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
403 #define memchr(buf, ch, count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
404 #define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
405 #define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count))
406 #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
407 #define strcpy(strDest, strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
408 #define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
409 #define strcat(strDest, strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
410 #define strncmp(string1, string2, count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
411 #define strcasecmp(str1, str2) (int)AsciiStriCmp(str1,str2)
412 #define strstr(s1, s2) AsciiStrStr(s1,s2)
413 #define sprintf(buf, ...) AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__)
414 #define localtime(timer) NULL
415 #define assert(expression)
416 #define offsetof(type, member) OFFSET_OF(type,member)
417 #define atoi(nptr) AsciiStrDecimalToUintn(nptr)
418 #define gettimeofday(tvp, tz) do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0)
419
420 #endif