]>
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 - 2017, 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 // 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.
29 #ifdef CONFIG_HEADER_BN_H
30 #error CONFIG_HEADER_BN_H already defined
33 #define CONFIG_HEADER_BN_H
35 #if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_IA64)
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.
41 #define SIXTY_FOUR_BIT
42 #elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)
43 #define THIRTY_TWO_BIT
45 #error Unknown target architecture
49 // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
51 #if !defined(__CC_ARM) // if va_list is not already defined
52 #define va_list VA_LIST
54 #define va_start VA_START
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)
63 // Definitions for global constants used by CRT library routines
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 */
73 // Basic types mapping
78 typedef UINT8 __uint8_t
;
79 typedef UINT8 sa_family_t
;
84 // File operations are not required for EFI building,
85 // so FILE is mapped to VOID * to pass build
90 // Structures Definitions
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 */
107 long tv_sec
; /* time value, in seconds */
108 long tv_usec
; /* time value, in microseconds */
112 __uint8_t sa_len
; /* total length */
113 sa_family_t sa_family
; /* address family */
114 char sa_data
[14]; /* actually longer; address value */
124 // Function prototypes of CRT Library routines
126 void *malloc (size_t);
127 void *realloc (void *, size_t);
129 void *memset (void *, int, size_t);
130 int memcmp (const void *, const void *, size_t);
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 *);
151 int fprintf (FILE *, const char *, ...);
152 time_t time (time_t *);
153 struct tm
*gmtime (const time_t *);
155 uid_t
geteuid (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__
));
169 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
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)