]>
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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef __CRT_LIB_SUPPORT_H__
17 #define __CRT_LIB_SUPPORT_H__
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/PrintLib.h>
27 #define MAX_STRING_SIZE 0x1000
30 // OpenSSL relies on explicit configuration for word size in crypto/bn,
31 // but we want it to be automatically inferred from the target. So we
32 // bypass what's in <openssl/opensslconf.h> for OPENSSL_SYS_UEFI, and
33 // define our own here.
35 #ifdef CONFIG_HEADER_BN_H
36 #error CONFIG_HEADER_BN_H already defined
39 #define CONFIG_HEADER_BN_H
41 #if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_IA64)
43 // With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs
44 // SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is
45 // 64-bit. Since using 'long long' works fine on GCC too, just do that.
47 #define SIXTY_FOUR_BIT
48 #elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)
49 #define THIRTY_TWO_BIT
51 #error Unknown target architecture
55 // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
57 #if !defined(__CC_ARM) // if va_list is not already defined
58 #define va_list VA_LIST
60 #define va_start VA_START
63 #define va_start(Marker, Parameter) __va_start(Marker, Parameter)
64 #define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)
65 #define va_end(Marker) ((void)0)
69 // Definitions for global constants used by CRT library routines
71 #define EINVAL 22 /* Invalid argument */
72 #define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */
73 #define LONG_MAX 0X7FFFFFFFL /* max value for a long */
74 #define LONG_MIN (-LONG_MAX-1) /* min value for a long */
75 #define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */
76 #define CHAR_BIT 8 /* Number of bits in a char */
79 // Basic types mapping
84 typedef UINT8 __uint8_t
;
85 typedef UINT8 sa_family_t
;
90 // File operations are not required for EFI building,
91 // so FILE is mapped to VOID * to pass build
96 // Structures Definitions
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 */
113 long tv_sec
; /* time value, in seconds */
114 long tv_usec
; /* time value, in microseconds */
118 __uint8_t sa_len
; /* total length */
119 sa_family_t sa_family
; /* address family */
120 char sa_data
[14]; /* actually longer; address value */
130 // Function prototypes of CRT Library routines
132 void *malloc (size_t);
133 void *realloc (void *, size_t);
135 void *memset (void *, int, size_t);
136 int memcmp (const void *, const void *, size_t);
143 int strcmp (const char *, const char *);
144 int strncasecmp (const char *, const char *, size_t);
145 char *strrchr (const char *, int);
146 unsigned long strtoul (const char *, char **, int);
147 long strtol (const char *, char **, int);
148 char *strerror (int);
149 size_t strspn (const char *, const char *);
150 size_t strcspn (const char *, const char *);
151 int printf (const char *, ...);
152 int sscanf (const char *, const char *, ...);
153 FILE *fopen (const char *, const char *);
154 size_t fread (void *, size_t, size_t, FILE *);
155 size_t fwrite (const void *, size_t, size_t, FILE *);
157 int fprintf (FILE *, const char *, ...);
158 time_t time (time_t *);
159 struct tm
*gmtime (const time_t *);
161 uid_t
geteuid (void);
163 gid_t
getegid (void);
164 void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
165 char *getenv (const char *);
166 #if defined(__GNUC__) && (__GNUC__ >= 2)
167 void abort (void) __attribute__((__noreturn__
));
173 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
175 #define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))
176 #define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
177 #define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
178 #define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
179 #define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))
180 #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
181 #define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource)
182 #define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
183 #define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
184 #define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
185 #define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
186 #define strcasecmp(str1,str2) (int)AsciiStriCmp(str1,str2)
187 #define sprintf(buf,...) AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__)
188 #define localtime(timer) NULL
189 #define assert(expression)
190 #define offsetof(type,member) OFFSET_OF(type,member)
191 #define atoi(nptr) AsciiStrDecimalToUintn(nptr)
192 #define gettimeofday(tvp,tz) do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0)