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