]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/Include/CrtLibSupport.h
5806f50f7485101dad8bb9da18306aa8747b3928
[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 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef __CRT_LIB_SUPPORT_H__
11 #define __CRT_LIB_SUPPORT_H__
12
13 #include <Library/BaseLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/PrintLib.h>
17
18 #define OPENSSLDIR ""
19 #define ENGINESDIR ""
20
21 #define MAX_STRING_SIZE 0x1000
22
23 //
24 // We already have "no-ui" in out Configure invocation.
25 // but the code still fails to compile.
26 // Ref: https://github.com/openssl/openssl/issues/8904
27 //
28 // This is defined in CRT library(stdio.h).
29 //
30 #ifndef BUFSIZ
31 #define BUFSIZ 8192
32 #endif
33
34 //
35 // OpenSSL relies on explicit configuration for word size in crypto/bn,
36 // but we want it to be automatically inferred from the target. So we
37 // bypass what's in <openssl/opensslconf.h> for OPENSSL_SYS_UEFI, and
38 // define our own here.
39 //
40 #ifdef CONFIG_HEADER_BN_H
41 #error CONFIG_HEADER_BN_H already defined
42 #endif
43
44 #define CONFIG_HEADER_BN_H
45
46 #if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_IA64)
47 //
48 // With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs
49 // SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is
50 // 64-bit. Since using 'long long' works fine on GCC too, just do that.
51 //
52 #define SIXTY_FOUR_BIT
53 #elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)
54 #define THIRTY_TWO_BIT
55 #else
56 #error Unknown target architecture
57 #endif
58
59 //
60 // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
61 //
62 #if !defined(__CC_ARM) // if va_list is not already defined
63 #define va_list VA_LIST
64 #define va_arg VA_ARG
65 #define va_start VA_START
66 #define va_end VA_END
67 #else // __CC_ARM
68 #define va_start(Marker, Parameter) __va_start(Marker, Parameter)
69 #define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)
70 #define va_end(Marker) ((void)0)
71 #endif
72
73 //
74 // Definitions for global constants used by CRT library routines
75 //
76 #define EINVAL 22 /* Invalid argument */
77 #define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */
78 #define LONG_MAX 0X7FFFFFFFL /* max value for a long */
79 #define LONG_MIN (-LONG_MAX-1) /* min value for a long */
80 #define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */
81 #define CHAR_BIT 8 /* Number of bits in a char */
82
83 //
84 // Basic types mapping
85 //
86 typedef UINTN size_t;
87 typedef INTN ssize_t;
88 typedef INT32 time_t;
89 typedef UINT8 __uint8_t;
90 typedef UINT8 sa_family_t;
91 typedef UINT32 uid_t;
92 typedef UINT32 gid_t;
93
94 //
95 // File operations are not required for EFI building,
96 // so FILE is mapped to VOID * to pass build
97 //
98 typedef VOID *FILE;
99
100 //
101 // Structures Definitions
102 //
103 struct tm {
104 int tm_sec; /* seconds after the minute [0-60] */
105 int tm_min; /* minutes after the hour [0-59] */
106 int tm_hour; /* hours since midnight [0-23] */
107 int tm_mday; /* day of the month [1-31] */
108 int tm_mon; /* months since January [0-11] */
109 int tm_year; /* years since 1900 */
110 int tm_wday; /* days since Sunday [0-6] */
111 int tm_yday; /* days since January 1 [0-365] */
112 int tm_isdst; /* Daylight Savings Time flag */
113 long tm_gmtoff; /* offset from CUT in seconds */
114 char *tm_zone; /* timezone abbreviation */
115 };
116
117 struct timeval {
118 long tv_sec; /* time value, in seconds */
119 long tv_usec; /* time value, in microseconds */
120 };
121
122 struct sockaddr {
123 __uint8_t sa_len; /* total length */
124 sa_family_t sa_family; /* address family */
125 char sa_data[14]; /* actually longer; address value */
126 };
127
128 //
129 // Global variables
130 //
131 extern int errno;
132 extern FILE *stderr;
133
134 //
135 // Function prototypes of CRT Library routines
136 //
137 void *malloc (size_t);
138 void *realloc (void *, size_t);
139 void free (void *);
140 void *memset (void *, int, size_t);
141 int memcmp (const void *, const void *, size_t);
142 int isdigit (int);
143 int isspace (int);
144 int isxdigit (int);
145 int isalnum (int);
146 int isupper (int);
147 int tolower (int);
148 int strcmp (const char *, const char *);
149 int strncasecmp (const char *, const char *, size_t);
150 char *strrchr (const char *, int);
151 unsigned long strtoul (const char *, char **, int);
152 long strtol (const char *, char **, int);
153 char *strerror (int);
154 size_t strspn (const char *, const char *);
155 size_t strcspn (const char *, const char *);
156 int printf (const char *, ...);
157 int sscanf (const char *, const char *, ...);
158 FILE *fopen (const char *, const char *);
159 size_t fread (void *, size_t, size_t, FILE *);
160 size_t fwrite (const void *, size_t, size_t, FILE *);
161 int fclose (FILE *);
162 int fprintf (FILE *, const char *, ...);
163 time_t time (time_t *);
164 struct tm *gmtime (const time_t *);
165 uid_t getuid (void);
166 uid_t geteuid (void);
167 gid_t getgid (void);
168 gid_t getegid (void);
169 int issetugid (void);
170 void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
171 char *getenv (const char *);
172 char *secure_getenv (const char *);
173 #if defined(__GNUC__) && (__GNUC__ >= 2)
174 void abort (void) __attribute__((__noreturn__));
175 #else
176 void abort (void);
177 #endif
178
179 //
180 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
181 //
182 #define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))
183 #define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
184 #define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
185 #define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
186 #define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))
187 #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
188 #define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
189 #define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
190 #define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
191 #define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
192 #define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
193 #define strcasecmp(str1,str2) (int)AsciiStriCmp(str1,str2)
194 #define sprintf(buf,...) AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__)
195 #define localtime(timer) NULL
196 #define assert(expression)
197 #define offsetof(type,member) OFFSET_OF(type,member)
198 #define atoi(nptr) AsciiStrDecimalToUintn(nptr)
199 #define gettimeofday(tvp,tz) do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0)
200
201 #endif