]>
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 - 2022, Intel Corporation. All rights reserved.<BR>
6 Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
7 Copyright (c) 2022, Loongson Technology Corporation Limited. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #ifndef __CRT_LIB_SUPPORT_H__
13 #define __CRT_LIB_SUPPORT_H__
15 #include <Library/BaseLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/PrintLib.h>
24 #define MAX_STRING_SIZE 0x1000
27 // We already have "no-ui" in out Configure invocation.
28 // but the code still fails to compile.
29 // Ref: https://github.com/openssl/openssl/issues/8904
31 // This is defined in CRT library(stdio.h).
38 // OpenSSL relies on explicit configuration for word size in crypto/bn,
39 // but we want it to be automatically inferred from the target. So we
40 // bypass what's in <openssl/opensslconf.h> for OPENSSL_SYS_UEFI, and
41 // define our own here.
43 #ifdef CONFIG_HEADER_BN_H
44 #error CONFIG_HEADER_BN_H already defined
47 #define CONFIG_HEADER_BN_H
49 #if !defined (SIXTY_FOUR_BIT) && !defined (THIRTY_TWO_BIT)
50 #if defined (MDE_CPU_X64) || defined (MDE_CPU_AARCH64) || defined (MDE_CPU_IA64) || defined (MDE_CPU_RISCV64) || defined (MDE_CPU_LOONGARCH64)
52 // With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs
53 // SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is
54 // 64-bit. Since using 'long long' works fine on GCC too, just do that.
56 #define SIXTY_FOUR_BIT
57 #elif defined (MDE_CPU_IA32) || defined (MDE_CPU_ARM) || defined (MDE_CPU_EBC)
58 #define THIRTY_TWO_BIT
60 #error Unknown target architecture
65 // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
67 #if !defined (__CC_ARM) // if va_list is not already defined
68 #define va_list VA_LIST
70 #define va_start VA_START
73 #define va_start(Marker, Parameter) __va_start(Marker, Parameter)
74 #define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)
75 #define va_end(Marker) ((void)0)
79 // Definitions for global constants used by CRT library routines
81 #define EINVAL 22 /* Invalid argument */
82 #define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
83 #define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */
84 #define INT_MIN (-INT_MAX-1) /* Minimum (signed) int value */
85 #define LONG_MAX 0X7FFFFFFFL /* max value for a long */
86 #define LONG_MIN (-LONG_MAX-1) /* min value for a long */
87 #define UINT_MAX 0xFFFFFFFF /* Maximum unsigned int value */
88 #define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */
89 #define CHAR_BIT 8 /* Number of bits in a char */
94 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
95 #define AF_INET6 24 /* IP version 6 */
98 // Define constants based on RFC0883, RFC1034, RFC 1035
100 #define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */
101 #define NS_INADDRSZ 4 /*%< IPv4 T_A */
102 #define NS_IN6ADDRSZ 16 /*%< IPv6 T_AAAA */
105 // Basic types mapping
107 typedef UINTN
size_t;
110 typedef INTN
ptrdiff_t;
111 typedef INTN ssize_t
;
112 typedef INT64
time_t;
113 typedef UINT8 __uint8_t
;
114 typedef UINT8 sa_family_t
;
115 typedef UINT8 u_char
;
116 typedef UINT32 uid_t
;
117 typedef UINT32 gid_t
;
118 typedef CHAR16
wchar_t;
121 // File operations are not required for EFI building,
122 // so FILE is mapped to VOID * to pass build
127 // Structures Definitions
130 int tm_sec
; /* seconds after the minute [0-60] */
131 int tm_min
; /* minutes after the hour [0-59] */
132 int tm_hour
; /* hours since midnight [0-23] */
133 int tm_mday
; /* day of the month [1-31] */
134 int tm_mon
; /* months since January [0-11] */
135 int tm_year
; /* years since 1900 */
136 int tm_wday
; /* days since Sunday [0-6] */
137 int tm_yday
; /* days since January 1 [0-365] */
138 int tm_isdst
; /* Daylight Savings Time flag */
139 long tm_gmtoff
; /* offset from CUT in seconds */
140 char *tm_zone
; /* timezone abbreviation */
144 long tv_sec
; /* time value, in seconds */
145 long tv_usec
; /* time value, in microseconds */
149 __uint8_t sa_len
; /* total length */
150 sa_family_t sa_family
; /* address family */
151 char sa_data
[14]; /* actually longer; address value */
161 // Function prototypes of CRT Library routines
366 int (*)(const void *, const void *)
379 #if defined (__GNUC__) && (__GNUC__ >= 2)
383 ) __attribute__ ((__noreturn__
));
402 const char *strSource
406 // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
408 #define memcpy(dest, source, count) CopyMem(dest,source,(UINTN)(count))
409 #define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
410 #define memchr(buf, ch, count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
411 #define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
412 #define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count))
413 #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
414 #define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count)
415 #define strcat(strDest, strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource)
416 #define strncmp(string1, string2, count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
417 #define strcasecmp(str1, str2) (int)AsciiStriCmp(str1,str2)
418 #define strstr(s1, s2) AsciiStrStr(s1,s2)
419 #define sprintf(buf, ...) AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__)
420 #define localtime(timer) NULL
421 #define assert(expression)
422 #define offsetof(type, member) OFFSET_OF(type,member)
423 #define atoi(nptr) AsciiStrDecimalToUintn(nptr)
424 #define gettimeofday(tvp, tz) do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0)