]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/Include/CrtLibSupport.h
2 Root include file of C runtime library to support building the third-party
5 Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef __CRT_LIB_SUPPORT_H__
11 #define __CRT_LIB_SUPPORT_H__
13 #include <Library/BaseLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/PrintLib.h>
21 #define MAX_STRING_SIZE 0x1000
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
28 // This is defined in CRT library(stdio.h).
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.
40 #ifdef CONFIG_HEADER_BN_H
41 #error CONFIG_HEADER_BN_H already defined
44 #define CONFIG_HEADER_BN_H
46 #if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_IA64)
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.
52 #define SIXTY_FOUR_BIT
53 #elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)
54 #define THIRTY_TWO_BIT
56 #error Unknown target architecture
60 // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
62 #if !defined(__CC_ARM) // if va_list is not already defined
63 #define va_list VA_LIST
65 #define va_start VA_START
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)
74 // Definitions for global constants used by CRT library routines
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 */
84 // Basic types mapping
89 typedef UINT8 __uint8_t
;
90 typedef UINT8 sa_family_t
;
95 // File operations are not required for EFI building,
96 // so FILE is mapped to VOID * to pass build
101 // Structures Definitions
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 */
118 long tv_sec
; /* time value, in seconds */
119 long tv_usec
; /* time value, in microseconds */
123 __uint8_t sa_len
; /* total length */
124 sa_family_t sa_family
; /* address family */
125 char sa_data
[14]; /* actually longer; address value */
135 // Function prototypes of CRT Library routines
137 void *malloc (size_t);
138 void *realloc (void *, size_t);
140 void *memset (void *, int, size_t);
141 int memcmp (const void *, const void *, size_t);
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 *);
162 int fprintf (FILE *, const char *, ...);
163 time_t time (time_t *);
164 struct tm
*gmtime (const time_t *);
166 uid_t
geteuid (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__
));
180 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
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)