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