]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Include/OpenSslSupport.h
CryptoPkg/OpensslLib: Undefine NO_BUILTIN_VA_FUNCS to fix varargs breakage
[mirror_edk2.git] / CryptoPkg / Include / OpenSslSupport.h
CommitLineData
97f98500
HT
1/** @file\r
2 Root include file to support building OpenSSL Crypto Library.\r
3\r
1463ce18 4Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
97f98500
HT
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef __OPEN_SSL_SUPPORT_H__\r
16#define __OPEN_SSL_SUPPORT_H__\r
17\r
18#include <Base.h>\r
19#include <Library/BaseLib.h>\r
20#include <Library/BaseMemoryLib.h>\r
21#include <Library/MemoryAllocationLib.h>\r
22#include <Library/DebugLib.h>\r
23\r
5c4a3795
QL
24#define MAX_STRING_SIZE 0x1000\r
25\r
97f98500
HT
26//\r
27// File operations are not required for building Open SSL, \r
28// so FILE is mapped to VOID * to pass build\r
29//\r
30typedef VOID *FILE;\r
31\r
32//\r
33// Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h\r
34//\r
8e01b449 35#if !defined(__CC_ARM) // if va_list is not already defined\r
97f98500
HT
36#define va_list VA_LIST\r
37#define va_arg VA_ARG\r
38#define va_start VA_START\r
39#define va_end VA_END\r
8e01b449 40#else // __CC_ARM\r
41#define va_start(Marker, Parameter) __va_start(Marker, Parameter)\r
42#define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)\r
43#define va_end(Marker) ((void)0)\r
44#endif\r
45\r
97f98500
HT
46//\r
47// #defines from EFI Application Toolkit required to buiild Open SSL\r
48//\r
49#define ENOMEM 12 /* Cannot allocate memory */\r
50#define EINVAL 22 /* Invalid argument */\r
51#define BUFSIZ 1024 /* size of buffer used by setbuf */\r
52#define INT_MAX 2147483647 /* max value for an int */\r
53#define INT_MIN (-2147483647-1) /* min value for an int */\r
54#define LONG_MAX 2147483647L /* max value for a long */\r
55#define LONG_MIN (-2147483647-1) /* min value for a long */\r
56#define ULONG_MAX 0xffffffff /* max value for an unsigned long */\r
57#define LOG_DAEMON (3<<3) /* system daemons */\r
58#define LOG_EMERG 0 /* system is unusable */\r
59#define LOG_ALERT 1 /* action must be taken immediately */\r
60#define LOG_CRIT 2 /* critical conditions */\r
61#define LOG_ERR 3 /* error conditions */\r
62#define LOG_WARNING 4 /* warning conditions */\r
63#define LOG_NOTICE 5 /* normal but significant condition */\r
64#define LOG_INFO 6 /* informational */\r
65#define LOG_DEBUG 7 /* debug-level messages */\r
66#define LOG_PID 0x01 /* log the pid with each message */\r
67#define LOG_CONS 0x02 /* log on the console if errors in sending */\r
68\r
69//\r
70// Macros from EFI Application Toolkit required to buiild Open SSL\r
71//\r
72/* The offsetof() macro calculates the offset of a structure member\r
73 in its structure. Unfortunately this cannot be written down\r
74 portably, hence it is provided by a Standard C header file.\r
75 For pre-Standard C compilers, here is a version that usually works\r
76 (but watch out!): */\r
afc18ead 77#define offsetof(type, member) OFFSET_OF (type, member)\r
97f98500
HT
78\r
79//\r
80// Basic types from EFI Application Toolkit required to buiild Open SSL\r
81//\r
82typedef UINTN size_t;\r
83typedef INTN ssize_t;\r
84typedef INT64 off_t;\r
85typedef UINT16 mode_t;\r
86typedef long time_t;\r
87typedef unsigned long clock_t;\r
88typedef UINT32 uid_t;\r
89typedef UINT32 gid_t;\r
90typedef UINT32 ino_t;\r
91typedef UINT32 dev_t;\r
92typedef UINT16 nlink_t;\r
93typedef int pid_t;\r
94typedef void *DIR;\r
95typedef void __sighandler_t (int);\r
96\r
97//\r
98// Structures from EFI Application Toolkit required to buiild Open SSL\r
99//\r
100struct tm {\r
101 int tm_sec; /* seconds after the minute [0-60] */\r
102 int tm_min; /* minutes after the hour [0-59] */\r
103 int tm_hour; /* hours since midnight [0-23] */\r
104 int tm_mday; /* day of the month [1-31] */\r
105 int tm_mon; /* months since January [0-11] */\r
106 int tm_year; /* years since 1900 */\r
107 int tm_wday; /* days since Sunday [0-6] */\r
108 int tm_yday; /* days since January 1 [0-365] */\r
109 int tm_isdst; /* Daylight Savings Time flag */\r
110 long tm_gmtoff; /* offset from CUT in seconds */\r
111 char *tm_zone; /* timezone abbreviation */\r
112};\r
113\r
1463ce18
QL
114struct timeval {\r
115 long tv_sec; /* time value, in seconds */\r
116 long tv_usec; /* time value, in microseconds */\r
117} timeval;\r
118\r
97f98500
HT
119struct dirent {\r
120 UINT32 d_fileno; /* file number of entry */\r
121 UINT16 d_reclen; /* length of this record */\r
122 UINT8 d_type; /* file type, see below */\r
123 UINT8 d_namlen; /* length of string in d_name */\r
124 char d_name[255 + 1]; /* name must be no longer than this */\r
125};\r
126\r
127struct stat {\r
128 dev_t st_dev; /* inode's device */\r
129 ino_t st_ino; /* inode's number */\r
130 mode_t st_mode; /* inode protection mode */\r
131 nlink_t st_nlink; /* number of hard links */\r
132 uid_t st_uid; /* user ID of the file's owner */\r
133 gid_t st_gid; /* group ID of the file's group */\r
134 dev_t st_rdev; /* device type */\r
135 time_t st_atime; /* time of last access */\r
136 long st_atimensec; /* nsec of last access */\r
137 time_t st_mtime; /* time of last data modification */\r
138 long st_mtimensec; /* nsec of last data modification */\r
139 time_t st_ctime; /* time of last file status change */\r
140 long st_ctimensec; /* nsec of last file status change */\r
141 off_t st_size; /* file size, in bytes */\r
142 INT64 st_blocks; /* blocks allocated for file */\r
143 UINT32 st_blksize; /* optimal blocksize for I/O */\r
144 UINT32 st_flags; /* user defined flags for file */\r
145 UINT32 st_gen; /* file generation number */\r
146 INT32 st_lspare;\r
147 INT64 st_qspare[2];\r
148};\r
149\r
150//\r
151// Externs from EFI Application Toolkit required to buiild Open SSL\r
152//\r
153extern int errno;\r
154\r
155//\r
156// Function prototypes from EFI Application Toolkit required to buiild Open SSL\r
157//\r
158void *malloc (size_t);\r
159void *realloc (void *, size_t);\r
160void free (void *);\r
161int isdigit (int);\r
162int isspace (int);\r
163int tolower (int);\r
164int isupper (int);\r
165int isxdigit (int);\r
166int isalnum (int);\r
167void *memcpy (void *, const void *, size_t);\r
168void *memset (void *, int, size_t);\r
169void *memchr (const void *, int, size_t);\r
170int memcmp (const void *, const void *, size_t);\r
171void *memmove (void *, const void *, size_t);\r
172int strcmp (const char *, const char *);\r
173int strncmp (const char *, const char *, size_t);\r
174char *strcpy (char *, const char *);\r
175char *strncpy (char *, const char *, size_t);\r
176size_t strlen (const char *);\r
177char *strcat (char *, const char *);\r
178char *strchr (const char *, int);\r
179int strcasecmp (const char *, const char *);\r
180int strncasecmp (const char *, const char *, size_t);\r
181char *strncpy (char *, const char *, size_t);\r
182int strncmp (const char *, const char *, size_t);\r
183char *strrchr (const char *, int);\r
184unsigned long strtoul (const char *, char **, int);\r
185long strtol (const char *, char **, int);\r
186int printf (const char *, ...);\r
187int sscanf (const char *, const char *, ...);\r
188int open (const char *, int, ...);\r
189int chmod (const char *, mode_t);\r
190int stat (const char *, struct stat *);\r
191off_t lseek (int, off_t, int);\r
192ssize_t read (int, void *, size_t);\r
193ssize_t write (int, const void *, size_t);\r
194int close (int);\r
195FILE *fopen (const char *, const char *);\r
196size_t fread (void *, size_t, size_t, FILE *);\r
197size_t fwrite (const void *, size_t, size_t, FILE *);\r
198char *fgets (char *, int, FILE *);\r
199int fputs (const char *, FILE *);\r
200int fprintf (FILE *, const char *, ...);\r
201int vfprintf (FILE *, const char *, VA_LIST);\r
202int fflush (FILE *);\r
203int fclose (FILE *);\r
204DIR *opendir (const char *);\r
205struct dirent *readdir (DIR *);\r
206int closedir (DIR *);\r
207void openlog (const char *, int, int);\r
208void closelog (void);\r
209void syslog (int, const char *, ...);\r
210time_t time (time_t *);\r
211struct tm *localtime (const time_t *);\r
212struct tm *gmtime (const time_t *);\r
213struct tm *gmtime_r (const time_t *, struct tm *);\r
214uid_t getuid (void);\r
215uid_t geteuid (void);\r
216gid_t getgid (void);\r
217gid_t getegid (void);\r
218void qsort (void *, size_t, size_t, int (*)(const void *, const void *));\r
219char *getenv (const char *);\r
220void exit (int);\r
221void abort (void);\r
222__sighandler_t *signal (int, __sighandler_t *);\r
223\r
224//\r
225// Global variables from EFI Application Toolkit required to buiild Open SSL\r
226//\r
c61fb9c8 227extern FILE *stderr;\r
228extern FILE *stdin;\r
229extern FILE *stdout;\r
97f98500
HT
230\r
231//\r
232// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions\r
233//\r
234#define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))\r
235#define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))\r
236#define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)\r
237#define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))\r
4a567c96 238#define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))\r
97f98500
HT
239#define strcmp AsciiStrCmp\r
240#define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))\r
5c4a3795
QL
241#define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)\r
242#define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)\r
243#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))\r
244#define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)\r
97f98500
HT
245#define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)\r
246#define abort() ASSERT (FALSE)\r
247#define assert(expression)\r
248#define localtime(timer) NULL\r
97f98500 249#define gmtime_r(timer,result) (result = NULL)\r
1463ce18 250#define atoi(nptr) AsciiStrDecimalToUintn(nptr)\r
97f98500
HT
251\r
252#endif\r