]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Include/OpenSslSupport.h
Patch from open source community for CryptoPkg to allow it to build for ARM using...
[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
4Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
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
24//\r
25// File operations are not required for building Open SSL, \r
26// so FILE is mapped to VOID * to pass build\r
27//\r
28typedef VOID *FILE;\r
29\r
30//\r
31// Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h\r
32//\r
8e01b449 33#if !defined(__CC_ARM) // if va_list is not already defined\r
97f98500
HT
34#define va_list VA_LIST\r
35#define va_arg VA_ARG\r
36#define va_start VA_START\r
37#define va_end VA_END\r
8e01b449 38#else // __CC_ARM\r
39#define va_start(Marker, Parameter) __va_start(Marker, Parameter)\r
40#define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)\r
41#define va_end(Marker) ((void)0)\r
42#endif\r
43\r
44\r
97f98500
HT
45\r
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
77#define offsetof(type, member) ( (int) & ((type*)0) -> member )\r
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
114struct dirent {\r
115 UINT32 d_fileno; /* file number of entry */\r
116 UINT16 d_reclen; /* length of this record */\r
117 UINT8 d_type; /* file type, see below */\r
118 UINT8 d_namlen; /* length of string in d_name */\r
119 char d_name[255 + 1]; /* name must be no longer than this */\r
120};\r
121\r
122struct stat {\r
123 dev_t st_dev; /* inode's device */\r
124 ino_t st_ino; /* inode's number */\r
125 mode_t st_mode; /* inode protection mode */\r
126 nlink_t st_nlink; /* number of hard links */\r
127 uid_t st_uid; /* user ID of the file's owner */\r
128 gid_t st_gid; /* group ID of the file's group */\r
129 dev_t st_rdev; /* device type */\r
130 time_t st_atime; /* time of last access */\r
131 long st_atimensec; /* nsec of last access */\r
132 time_t st_mtime; /* time of last data modification */\r
133 long st_mtimensec; /* nsec of last data modification */\r
134 time_t st_ctime; /* time of last file status change */\r
135 long st_ctimensec; /* nsec of last file status change */\r
136 off_t st_size; /* file size, in bytes */\r
137 INT64 st_blocks; /* blocks allocated for file */\r
138 UINT32 st_blksize; /* optimal blocksize for I/O */\r
139 UINT32 st_flags; /* user defined flags for file */\r
140 UINT32 st_gen; /* file generation number */\r
141 INT32 st_lspare;\r
142 INT64 st_qspare[2];\r
143};\r
144\r
145//\r
146// Externs from EFI Application Toolkit required to buiild Open SSL\r
147//\r
148extern int errno;\r
149\r
150//\r
151// Function prototypes from EFI Application Toolkit required to buiild Open SSL\r
152//\r
153void *malloc (size_t);\r
154void *realloc (void *, size_t);\r
155void free (void *);\r
156int isdigit (int);\r
157int isspace (int);\r
158int tolower (int);\r
159int isupper (int);\r
160int isxdigit (int);\r
161int isalnum (int);\r
162void *memcpy (void *, const void *, size_t);\r
163void *memset (void *, int, size_t);\r
164void *memchr (const void *, int, size_t);\r
165int memcmp (const void *, const void *, size_t);\r
166void *memmove (void *, const void *, size_t);\r
167int strcmp (const char *, const char *);\r
168int strncmp (const char *, const char *, size_t);\r
169char *strcpy (char *, const char *);\r
170char *strncpy (char *, const char *, size_t);\r
171size_t strlen (const char *);\r
172char *strcat (char *, const char *);\r
173char *strchr (const char *, int);\r
174int strcasecmp (const char *, const char *);\r
175int strncasecmp (const char *, const char *, size_t);\r
176char *strncpy (char *, const char *, size_t);\r
177int strncmp (const char *, const char *, size_t);\r
178char *strrchr (const char *, int);\r
179unsigned long strtoul (const char *, char **, int);\r
180long strtol (const char *, char **, int);\r
181int printf (const char *, ...);\r
182int sscanf (const char *, const char *, ...);\r
183int open (const char *, int, ...);\r
184int chmod (const char *, mode_t);\r
185int stat (const char *, struct stat *);\r
186off_t lseek (int, off_t, int);\r
187ssize_t read (int, void *, size_t);\r
188ssize_t write (int, const void *, size_t);\r
189int close (int);\r
190FILE *fopen (const char *, const char *);\r
191size_t fread (void *, size_t, size_t, FILE *);\r
192size_t fwrite (const void *, size_t, size_t, FILE *);\r
193char *fgets (char *, int, FILE *);\r
194int fputs (const char *, FILE *);\r
195int fprintf (FILE *, const char *, ...);\r
196int vfprintf (FILE *, const char *, VA_LIST);\r
197int fflush (FILE *);\r
198int fclose (FILE *);\r
199DIR *opendir (const char *);\r
200struct dirent *readdir (DIR *);\r
201int closedir (DIR *);\r
202void openlog (const char *, int, int);\r
203void closelog (void);\r
204void syslog (int, const char *, ...);\r
205time_t time (time_t *);\r
206struct tm *localtime (const time_t *);\r
207struct tm *gmtime (const time_t *);\r
208struct tm *gmtime_r (const time_t *, struct tm *);\r
209uid_t getuid (void);\r
210uid_t geteuid (void);\r
211gid_t getgid (void);\r
212gid_t getegid (void);\r
213void qsort (void *, size_t, size_t, int (*)(const void *, const void *));\r
214char *getenv (const char *);\r
215void exit (int);\r
216void abort (void);\r
217__sighandler_t *signal (int, __sighandler_t *);\r
218\r
219//\r
220// Global variables from EFI Application Toolkit required to buiild Open SSL\r
221//\r
8e01b449 222static FILE *stderr;\r
223static FILE *stdin;\r
224static FILE *stdout;\r
97f98500
HT
225\r
226//\r
227// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions\r
228//\r
229#define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))\r
230#define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))\r
231#define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)\r
232#define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))\r
4a567c96 233#define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))\r
97f98500
HT
234#define strcmp AsciiStrCmp\r
235#define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))\r
236#define strcpy(strDest,strSource) AsciiStrCpy(strDest,strSource)\r
237#define strncpy(strDest,strSource,count) AsciiStrnCpy(strDest,strSource,(UINTN)count)\r
238#define strlen(str) (size_t)(AsciiStrLen(str))\r
239#define strcat(strDest,strSource) AsciiStrCat(strDest,strSource)\r
240#define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)\r
241#define abort() ASSERT (FALSE)\r
242#define assert(expression)\r
243#define localtime(timer) NULL\r
244#define gmtime(timer) NULL\r
245#define gmtime_r(timer,result) (result = NULL)\r
246\r
247#endif\r