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