From bac4bac33a33db14b6219f125512801a27aadd0b Mon Sep 17 00:00:00 2001 From: jief666 Date: Wed, 10 Jan 2024 14:08:21 +0100 Subject: [PATCH] OpenSsl and secureboot compilation. Don't know if it works. --- BaseTools/Conf/tools_def.template | 10 +- BaseTools/Source/Python/Common/GlobalData.py | 2 +- Clover.dsc | 8 +- CloverPkg.dec | 4 +- Include/Library/MemLogLib.h | 2 +- Include/Library/printf_lite-conf.h | 2 +- .../OpensslLib/CryptoPkg/BaseMemAllocation.c | 6 +- Library/OpensslLib/CryptoPkg/CrtWrapper.c | 699 +++++++++--------- .../CryptoPkg/Include/CrtLibSupport.h | 164 ++-- Library/OpensslLib/CryptoPkg/Include/stdint.h | 19 - .../OpensslLib/CryptoPkg/Include/stdint.h.dis | 19 + Library/OpensslLib/CryptoPkg/TimerWrapper.c | 2 +- Library/OpensslLib/OpensslLib.dec | 32 + Library/OpensslLib/OpensslLib.inf | 8 +- .../OpensslLib/openssl/crypto/conf/conf_lib.c | 8 +- Library/OpensslLib/openssl/crypto/mem.c | 6 +- .../openssl/include/internal/tsan_assist.h | 1 + .../openssl/include/openssl/e_os2.h | 17 +- Library/OpensslLib/openssl/ssl/ssl_lib.c | 4 +- OpenCorePkg | 2 +- Protocols/SMCHelper/SMCHelper.c | 5 +- rEFIt_UEFI/PlatformEFI/posix/abort.cpp | 10 - rEFIt_UEFI/PlatformEFI/posix/abort.h | 13 +- rEFIt_UEFI/PlatformEFI/posix/assert.cpp | 15 + rEFIt_UEFI/PlatformEFI/posix/assert.h | 24 + rEFIt_UEFI/PlatformEFI/posix/limits.h | 60 ++ rEFIt_UEFI/PlatformEFI/posix/posix.h | 3 +- rEFIt_UEFI/PlatformEFI/posix/stdint.h | 8 + rEFIt_UEFI/PlatformEFI/posix/stdlib.h | 18 +- rEFIt_UEFI/PlatformEFI/posix/string.cpp | 77 ++ rEFIt_UEFI/PlatformEFI/posix/string.h | 34 +- rEFIt_UEFI/PlatformEFI/posix/strings.h | 3 +- rEFIt_UEFI/entry_scan/securehash.cpp | 2 +- rEFIt_UEFI/entry_scan/securevars.cpp | 13 +- rEFIt_UEFI/include/SmcHelper.h | 20 - rEFIt_UEFI/refit.inf | 10 +- 36 files changed, 776 insertions(+), 554 deletions(-) delete mode 100644 Library/OpensslLib/CryptoPkg/Include/stdint.h create mode 100644 Library/OpensslLib/CryptoPkg/Include/stdint.h.dis create mode 100644 Library/OpensslLib/OpensslLib.dec create mode 100644 rEFIt_UEFI/PlatformEFI/posix/assert.cpp create mode 100644 rEFIt_UEFI/PlatformEFI/posix/assert.h delete mode 100644 rEFIt_UEFI/include/SmcHelper.h diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index 95e3b17b4..8123b8fe2 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -2015,7 +2015,7 @@ DEFINE GCC_X64_RC_FLAGS = -I binary -O elf64-x86-64 -B i386 --re DEFINE GCC_ARM_RC_FLAGS = -I binary -O elf32-littlearm -B arm --rename-section .data=.hii DEFINE GCC_AARCH64_RC_FLAGS = -I binary -O elf64-littleaarch64 -B aarch64 --rename-section .data=.hii -DEFINE GCC48_ALL_CC_FLAGS = -fshort-wchar -fno-builtin -Wall -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -nostdinc -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -DNO_MSABI_VA_FUNCS -fno-strict-aliasing +DEFINE GCC48_ALL_CC_FLAGS = -fshort-wchar -fno-builtin -Wall -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -DNO_MSABI_VA_FUNCS -fno-strict-aliasing DEFINE GCC48_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x20 DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector -mabi=ms "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -mcmodel=small -fpie -fno-asynchronous-unwind-tables @@ -2673,7 +2673,7 @@ RELEASE_XCODE5_X64_ASM_FLAGS = -arch x86_64 # $(PLATFORM_FLAGS) RELEASE_XCODE5_X64_CC_FLAGS = -target x86_64-pc-win32-macho -c -Os -Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS -RELEASE_XCODE5_X64_CXX_FLAGS = -target x86_64-pc-win32-macho -nostdinc -c -Os -Wall -Werror -Wextra -include AutoGen.h -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings +RELEASE_XCODE5_X64_CXX_FLAGS = -target x86_64-pc-win32-macho -c -Os -Wall -Werror -Wextra -include AutoGen.h -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -Wno-unused-parameter -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare -DNO_MSABI_VA_FUNCS -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings # -mno-implicit-float # -Wno-varargs # -Wno-unused-const-variable @@ -2746,7 +2746,7 @@ RELEASEMACOS_XCODE8_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMAG # -Wno-varargs # -Wno-unused-const-variable - DEFINE XCODE8_COMMON_FLAGS = -nostdinc -c -Wall -Wextra -include AutoGen.h -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -mno-red-zone -fno-common -fdata-sections -ffreestanding -ffunction-sections -fno-asynchronous-unwind-tables -m64 -mcmodel=small -DNO_MSABI_VA_FUNCS -fno-strict-aliasing -Wno-unused-parameter + DEFINE XCODE8_COMMON_FLAGS = -c -Wall -Wextra -include AutoGen.h -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -mno-red-zone -fno-common -fdata-sections -ffreestanding -ffunction-sections -fno-asynchronous-unwind-tables -m64 -mcmodel=small -DNO_MSABI_VA_FUNCS -fno-strict-aliasing -Wno-unused-parameter @@ -2823,7 +2823,7 @@ RELEASEMACOS_XCODE14_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMA # -Wno-varargs # -Wno-unused-const-variable - DEFINE XCODE14_COMMON_FLAGS = -nostdinc -c -Wall -Wextra -include AutoGen.h -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -mno-red-zone -fno-common -fdata-sections -ffreestanding -ffunction-sections -fno-asynchronous-unwind-tables -m64 -mcmodel=small -DNO_MSABI_VA_FUNCS -fno-strict-aliasing -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-deprecated-non-prototype + DEFINE XCODE14_COMMON_FLAGS = -c -Wall -Wextra -include AutoGen.h -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -mno-red-zone -fno-common -fdata-sections -ffreestanding -ffunction-sections -fno-asynchronous-unwind-tables -m64 -mcmodel=small -DNO_MSABI_VA_FUNCS -fno-strict-aliasing -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-deprecated-non-prototype @@ -2900,7 +2900,7 @@ RELEASEMACOS_XCODE15_X64_DLINK_FLAGS = -arch x86_64 -nostdlib -Wl,-u,_$(IMA # -Wno-varargs # -Wno-unused-const-variable - DEFINE XCODE15_COMMON_FLAGS = -nostdinc -c -Wall -Wextra -include AutoGen.h -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -mno-red-zone -fno-common -fdata-sections -ffreestanding -ffunction-sections -fno-asynchronous-unwind-tables -m64 -mcmodel=small -DNO_MSABI_VA_FUNCS -fno-strict-aliasing -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-deprecated-non-prototype -Wno-unused-command-line-argument + DEFINE XCODE15_COMMON_FLAGS = -c -Wall -Wextra -include AutoGen.h -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar -mms-bitfields -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings -mno-red-zone -fno-common -fdata-sections -ffreestanding -ffunction-sections -fno-asynchronous-unwind-tables -m64 -mcmodel=small -DNO_MSABI_VA_FUNCS -fno-strict-aliasing -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-deprecated-non-prototype -Wno-unused-command-line-argument diff --git a/BaseTools/Source/Python/Common/GlobalData.py b/BaseTools/Source/Python/Common/GlobalData.py index 61ab3f7e2..a8fe755d9 100755 --- a/BaseTools/Source/Python/Common/GlobalData.py +++ b/BaseTools/Source/Python/Common/GlobalData.py @@ -23,7 +23,7 @@ gPlatformOtherPcds = {} gActivePlatform = None gCommandLineDefines = {} gEdkGlobal = {} -gCommandMaxLength = 4096 +gCommandMaxLength = 13684 # for debug trace purpose when problem occurs gProcessingFile = '' gBuildingModule = '' diff --git a/Clover.dsc b/Clover.dsc index c766c6062..1648b983e 100644 --- a/Clover.dsc +++ b/Clover.dsc @@ -28,10 +28,6 @@ FLASH_DEFINITION = Clover.fdf !endif -!ifndef OPENSSL_VERSION - DEFINE OPENSSL_VERSION = 1.0.1e -!endif - !include MdePkg/MdeLibs.dsc.inc ################################################################################ @@ -92,7 +88,9 @@ SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf UefiCpuLib|CloverEFI/UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf !ifdef ENABLE_SECURE_BOOT - OpensslLib|Library/OpensslLib/openssl-$(OPENSSL_VERSION)/OpensslLib.inf + #RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + RngLib|OpenCorePkg/Library/OcRngLib/OcRngLib.inf + OpensslLib|Library/OpensslLib/OpensslLib.inf IntrinsicLib|Library/IntrinsicLib/IntrinsicLib.inf !else OpensslLib|Library/OpensslLib/OpensslLibNull.inf diff --git a/CloverPkg.dec b/CloverPkg.dec index b28c3edd8..0c0540548 100644 --- a/CloverPkg.dec +++ b/CloverPkg.dec @@ -20,12 +20,12 @@ PACKAGE_NAME = CloverPkg PACKAGE_GUID = C10BE46B-35C3-4B0B-9B9C-3F02051D782F PACKAGE_VERSION = 0.4 - DEFINE OPENSSL_VERSION = 1.0.1e [Includes] Include + rEFIt_UEFI/PlatformEFI/posix #Library/OpensslLib/Include - #Library/OpensslLib/openssl-$(OPENSSL_VERSION)/include + #Library/OpensslLib/openssl/include [LibraryClasses] ## @libraryclass Provides MsgLog service diff --git a/Include/Library/MemLogLib.h b/Include/Library/MemLogLib.h index e1f28a906..a31ee07ad 100644 --- a/Include/Library/MemLogLib.h +++ b/Include/Library/MemLogLib.h @@ -5,7 +5,7 @@ #ifndef __MEMLOG_LIB_H__ #define __MEMLOG_LIB_H__ - +#include // for EFI_STATUS // // Mem log sizes // diff --git a/Include/Library/printf_lite-conf.h b/Include/Library/printf_lite-conf.h index a25d5e1b3..c6dbb1bf4 100755 --- a/Include/Library/printf_lite-conf.h +++ b/Include/Library/printf_lite-conf.h @@ -27,7 +27,7 @@ extern "C" { typedef UINT32 char32_t; typedef UINT16 char16_t; typedef UINT32 uint32_t; - #define PRIu32 d + #define PRIu32 "u" #endif #ifdef _MSC_VER diff --git a/Library/OpensslLib/CryptoPkg/BaseMemAllocation.c b/Library/OpensslLib/CryptoPkg/BaseMemAllocation.c index b7bed15c1..776c41a11 100644 --- a/Library/OpensslLib/CryptoPkg/BaseMemAllocation.c +++ b/Library/OpensslLib/CryptoPkg/BaseMemAllocation.c @@ -28,7 +28,7 @@ typedef struct { /* Allocates memory blocks */ void * -malloc ( +CryptoPkg_BaseMemAllocation_malloc ( size_t size ) { @@ -61,7 +61,7 @@ malloc ( /* Reallocate memory blocks */ void * -realloc ( +CryptoPkg_BaseMemAllocation_realloc ( void *ptr, size_t size ) @@ -104,7 +104,7 @@ realloc ( /* De-allocates or frees a memory block */ void -free ( +CryptoPkg_BaseMemAllocation_free ( void *ptr ) { diff --git a/Library/OpensslLib/CryptoPkg/CrtWrapper.c b/Library/OpensslLib/CryptoPkg/CrtWrapper.c index 37cdecc9b..e40ee3d5f 100644 --- a/Library/OpensslLib/CryptoPkg/CrtWrapper.c +++ b/Library/OpensslLib/CryptoPkg/CrtWrapper.c @@ -111,69 +111,70 @@ QuickSortWorker ( // Standard C Run-time Library Interface Wrapper // --------------------------------------------------------- +// Jief : functions we already have are commented out // // -- String Manipulation Routines -- // -char * -strchr ( - const char *str, - int ch - ) -{ - return ScanMem8 (str, AsciiStrSize (str), (UINT8)ch); -} - -/* Scan a string for the last occurrence of a character */ -char * -strrchr ( - const char *str, - int c - ) -{ - char *save; - - for (save = NULL; ; ++str) { - if (*str == c) { - save = (char *)str; - } - - if (*str == 0) { - return (save); - } - } -} - -/* Compare first n bytes of string s1 with string s2, ignoring case */ -int -strncasecmp ( - const char *s1, - const char *s2, - size_t n - ) -{ - int Val; - - ASSERT (s1 != NULL); - ASSERT (s2 != NULL); - - if (n != 0) { - do { - Val = tolower (*s1) - tolower (*s2); - if (Val != 0) { - return Val; - } - - ++s1; - ++s2; - if (*s1 == '\0') { - break; - } - } while (--n != 0); - } - - return 0; -} +//char * +//strchr ( +// const char *str, +// int ch +// ) +//{ +// return ScanMem8 (str, AsciiStrSize (str), (UINT8)ch); +//} +// +///* Scan a string for the last occurrence of a character */ +//char * +//strrchr ( +// const char *str, +// int c +// ) +//{ +// char *save; +// +// for (save = NULL; ; ++str) { +// if (*str == c) { +// save = (char *)str; +// } +// +// if (*str == 0) { +// return (save); +// } +// } +//} +// +///* Compare first n bytes of string s1 with string s2, ignoring case */ +//int +//strncasecmp ( +// const char *s1, +// const char *s2, +// size_t n +// ) +//{ +// int Val; +// +// ASSERT (s1 != NULL); +// ASSERT (s2 != NULL); +// +// if (n != 0) { +// do { +// Val = tolower (*s1) - tolower (*s2); +// if (Val != 0) { +// return Val; +// } +// +// ++s1; +// ++s2; +// if (*s1 == '\0') { +// break; +// } +// } while (--n != 0); +// } +// +// return 0; +//} /* Read formatted data from a string */ int @@ -199,120 +200,120 @@ strerror ( return NULL; } -/* Computes the length of the maximum initial segment of the string pointed to by s1 - which consists entirely of characters from the string pointed to by s2. */ -size_t -strspn ( - const char *s1, - const char *s2 - ) -{ - UINT8 Map[32]; - UINT32 Index; - size_t Count; - - for (Index = 0; Index < 32; Index++) { - Map[Index] = 0; - } - - while (*s2) { - Map[*s2 >> 3] |= (1 << (*s2 & 7)); - s2++; - } - - if (*s1) { - Count = 0; - while (Map[*s1 >> 3] & (1 << (*s1 & 7))) { - Count++; - s1++; - } - - return Count; - } - - return 0; -} - -/* Computes the length of the maximum initial segment of the string pointed to by s1 - which consists entirely of characters not from the string pointed to by s2. */ -size_t -strcspn ( - const char *s1, - const char *s2 - ) -{ - UINT8 Map[32]; - UINT32 Index; - size_t Count; - - for (Index = 0; Index < 32; Index++) { - Map[Index] = 0; - } - - while (*s2) { - Map[*s2 >> 3] |= (1 << (*s2 & 7)); - s2++; - } - - Map[0] |= 1; - - Count = 0; - while (!(Map[*s1 >> 3] & (1 << (*s1 & 7)))) { - Count++; - s1++; - } - - return Count; -} - -char * -strcpy ( - char *strDest, - const char *strSource - ) -{ - AsciiStrCpyS (strDest, MAX_STRING_SIZE, strSource); - return strDest; -} - -int -strcmp ( - const char *s1, - const char *s2 - ) -{ - return (int)AsciiStrCmp (s1, s2); -} - +///* Computes the length of the maximum initial segment of the string pointed to by s1 +// which consists entirely of characters from the string pointed to by s2. */ +//size_t +//strspn ( +// const char *s1, +// const char *s2 +// ) +//{ +// UINT8 Map[32]; +// UINT32 Index; +// size_t Count; // -// -- Character Classification Routines -- +// for (Index = 0; Index < 32; Index++) { +// Map[Index] = 0; +// } // - -/* Determines if a particular character is a decimal-digit character */ -int -isdigit ( - int c - ) -{ - // - // ::= [0-9] - // - return (('0' <= (c)) && ((c) <= '9')); -} - -/* Determine if an integer represents character that is a hex digit */ -int -isxdigit ( - int c - ) -{ - // - // ::= [0-9] | [a-f] | [A-F] - // - return ((('0' <= (c)) && ((c) <= '9')) || - (('a' <= (c)) && ((c) <= 'f')) || - (('A' <= (c)) && ((c) <= 'F'))); -} +// while (*s2) { +// Map[*s2 >> 3] |= (1 << (*s2 & 7)); +// s2++; +// } +// +// if (*s1) { +// Count = 0; +// while (Map[*s1 >> 3] & (1 << (*s1 & 7))) { +// Count++; +// s1++; +// } +// +// return Count; +// } +// +// return 0; +//} +// +///* Computes the length of the maximum initial segment of the string pointed to by s1 +// which consists entirely of characters not from the string pointed to by s2. */ +//size_t +//strcspn ( +// const char *s1, +// const char *s2 +// ) +//{ +// UINT8 Map[32]; +// UINT32 Index; +// size_t Count; +// +// for (Index = 0; Index < 32; Index++) { +// Map[Index] = 0; +// } +// +// while (*s2) { +// Map[*s2 >> 3] |= (1 << (*s2 & 7)); +// s2++; +// } +// +// Map[0] |= 1; +// +// Count = 0; +// while (!(Map[*s1 >> 3] & (1 << (*s1 & 7)))) { +// Count++; +// s1++; +// } +// +// return Count; +//} +// +//char * +//strcpy ( +// char *strDest, +// const char *strSource +// ) +//{ +// AsciiStrCpyS (strDest, MAX_STRING_SIZE, strSource); +// return strDest; +//} +// +//int +//strcmp ( +// const char *s1, +// const char *s2 +// ) +//{ +// return (int)AsciiStrCmp (s1, s2); +//} +// +//// +//// -- Character Classification Routines -- +//// +// +///* Determines if a particular character is a decimal-digit character */ +//int +//isdigit ( +// int c +// ) +//{ +// // +// // ::= [0-9] +// // +// return (('0' <= (c)) && ((c) <= '9')); +//} +// +///* Determine if an integer represents character that is a hex digit */ +//int +//isxdigit ( +// int c +// ) +//{ +// // +// // ::= [0-9] | [a-f] | [A-F] +// // +// return ((('0' <= (c)) && ((c) <= '9')) || +// (('a' <= (c)) && ((c) <= 'f')) || +// (('A' <= (c)) && ((c) <= 'F'))); +//} /* Determines if a particular character represents a space character */ int @@ -326,31 +327,31 @@ isspace ( return ((c) == ' '); } -/* Determine if a particular character is an alphanumeric character */ -int -isalnum ( - int c - ) -{ - // - // ::= [0-9] | [a-z] | [A-Z] - // - return ((('0' <= (c)) && ((c) <= '9')) || - (('a' <= (c)) && ((c) <= 'z')) || - (('A' <= (c)) && ((c) <= 'Z'))); -} - -/* Determines if a particular character is in upper case */ -int -isupper ( - int c - ) -{ - // - // := [A-Z] - // - return (('A' <= (c)) && ((c) <= 'Z')); -} +///* Determine if a particular character is an alphanumeric character */ +//int +//isalnum ( +// int c +// ) +//{ +// // +// // ::= [0-9] | [a-z] | [A-Z] +// // +// return ((('0' <= (c)) && ((c) <= '9')) || +// (('a' <= (c)) && ((c) <= 'z')) || +// (('A' <= (c)) && ((c) <= 'Z'))); +//} +// +///* Determines if a particular character is in upper case */ +//int +//isupper ( +// int c +// ) +//{ +// // +// // := [A-Z] +// // +// return (('A' <= (c)) && ((c) <= 'Z')); +//} // // -- Data Conversion Routines -- @@ -386,18 +387,18 @@ strtoul ( return 0; } -/* Convert character to lowercase */ -int -tolower ( - int c - ) -{ - if (('A' <= (c)) && ((c) <= 'Z')) { - return (c - ('A' - 'a')); - } - - return (c); -} +///* Convert character to lowercase */ +//int +//tolower ( +// int c +// ) +//{ +// if (('A' <= (c)) && ((c) <= 'Z')) { +// return (c - ('A' - 'a')); +// } +// +// return (c); +//} // // -- Searching and Sorting Routines -- @@ -420,7 +421,7 @@ qsort ( // // Use CRT-style malloc to cover BS and RT memory allocation. // - Buffer = malloc (width); + Buffer = CryptoPkg_BaseMemAllocation_malloc (width); ASSERT (Buffer != NULL); // @@ -428,7 +429,7 @@ qsort ( // QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer); - free (Buffer); + CryptoPkg_BaseMemAllocation_free (Buffer); return; } @@ -449,144 +450,144 @@ getenv ( return NULL; } -/* Get a value from the current environment */ -char * -secure_getenv ( - const char *varname - ) -{ - // - // Null secure_getenv() function implementation to satisfy the linker, since - // there is no direct functionality logic dependency in present UEFI cases. - // - // From the secure_getenv() manual: 'just like getenv() except that it - // returns NULL in cases where "secure execution" is required'. - // - return NULL; -} - +///* Get a value from the current environment */ +//char * +//secure_getenv ( +// const char *varname +// ) +//{ +// // +// // Null secure_getenv() function implementation to satisfy the linker, since +// // there is no direct functionality logic dependency in present UEFI cases. +// // +// // From the secure_getenv() manual: 'just like getenv() except that it +// // returns NULL in cases where "secure execution" is required'. +// // +// return NULL; +//} // -// -- Stream I/O Routines -- +//// +//// -- Stream I/O Routines -- +//// // - -/* Write data to a stream */ -size_t -fwrite ( - const void *buffer, - size_t size, - size_t count, - FILE *stream - ) -{ - return 0; -} - -#ifdef __GNUC__ - -typedef -VOID -(EFIAPI *NoReturnFuncPtr)( - VOID - ) __attribute__ ((__noreturn__)); - -STATIC -VOID -EFIAPI -NopFunction ( - VOID - ) -{ -} - -void -abort ( - void - ) -{ - NoReturnFuncPtr NoReturnFunc; - - NoReturnFunc = (NoReturnFuncPtr)NopFunction; - - NoReturnFunc (); -} - -#else - -void -abort ( - void - ) -{ - // Do nothing -} - -#endif - -int -fclose ( - FILE *f - ) -{ - return 0; -} - -FILE * -fopen ( - const char *c, - const char *m - ) -{ - return NULL; -} - -size_t -fread ( - void *b, - size_t c, - size_t i, - FILE *f - ) -{ - return 0; -} - -uid_t -getuid ( - void - ) -{ - return 0; -} - -uid_t -geteuid ( - void - ) -{ - return 0; -} - -gid_t -getgid ( - void - ) -{ - return 0; -} - -gid_t -getegid ( - void - ) -{ - return 0; -} - -int -printf ( - char const *fmt, - ... - ) -{ - return 0; -} +///* Write data to a stream */ +//size_t +//fwrite ( +// const void *buffer, +// size_t size, +// size_t count, +// FILE *stream +// ) +//{ +// return 0; +//} +// +//#ifdef __GNUC__ +// +//typedef +//VOID +//(EFIAPI *NoReturnFuncPtr)( +// VOID +// ) __attribute__ ((__noreturn__)); +// +//STATIC +//VOID +//EFIAPI +//NopFunction ( +// VOID +// ) +//{ +//} +// +//void +//abort ( +// void +// ) +//{ +// NoReturnFuncPtr NoReturnFunc; +// +// NoReturnFunc = (NoReturnFuncPtr)NopFunction; +// +// NoReturnFunc (); +//} +// +//#else +// +//void +//abort ( +// void +// ) +//{ +// // Do nothing +//} +// +//#endif +// +//int +//fclose ( +// FILE *f +// ) +//{ +// return 0; +//} +// +//FILE * +//fopen ( +// const char *c, +// const char *m +// ) +//{ +// return NULL; +//} +// +//size_t +//fread ( +// void *b, +// size_t c, +// size_t i, +// FILE *f +// ) +//{ +// return 0; +//} +// +//uid_t +//getuid ( +// void +// ) +//{ +// return 0; +//} +// +//uid_t +//geteuid ( +// void +// ) +//{ +// return 0; +//} +// +//gid_t +//getgid ( +// void +// ) +//{ +// return 0; +//} +// +//gid_t +//getegid ( +// void +// ) +//{ +// return 0; +//} +// +//int +//printf ( +// char const *fmt, +// ... +// ) +//{ +// return 0; +//} diff --git a/Library/OpensslLib/CryptoPkg/Include/CrtLibSupport.h b/Library/OpensslLib/CryptoPkg/Include/CrtLibSupport.h index f36fe08f0..a7ca59b1e 100644 --- a/Library/OpensslLib/CryptoPkg/Include/CrtLibSupport.h +++ b/Library/OpensslLib/CryptoPkg/Include/CrtLibSupport.h @@ -8,10 +8,10 @@ Copyright (c) 2022, Loongson Technology Corporation Limited. All rights reserved SPDX-License-Identifier: BSD-2-Clause-Patent **/ - #ifndef __CRT_LIB_SUPPORT_H__ #define __CRT_LIB_SUPPORT_H__ +#include "../../../rEFIt_UEFI/PlatformEFI/posix/posix.h" #include #include #include @@ -65,10 +65,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h // #if !defined (__CC_ARM) // if va_list is not already defined -#define va_list VA_LIST -#define va_arg VA_ARG -#define va_start VA_START -#define va_end VA_END +//#define va_list VA_LIST +//#define va_arg VA_ARG +//#define va_start VA_START +//#define va_end VA_END #else // __CC_ARM #define va_start(Marker, Parameter) __va_start(Marker, Parameter) #define va_arg(Marker, TYPE) __va_arg(Marker, TYPE) @@ -80,14 +80,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // #define EINVAL 22 /* Invalid argument */ #define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ -#define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */ -#define INT_MIN (-INT_MAX-1) /* Minimum (signed) int value */ -#define LONG_MAX 0X7FFFFFFFL /* max value for a long */ -#define LONG_MIN (-LONG_MAX-1) /* min value for a long */ -#define UINT_MAX 0xFFFFFFFF /* Maximum unsigned int value */ -#define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */ +//#define INT_MAX 0x7FFFFFFF /* Maximum (signed) int value */ +//#define INT_MIN (-INT_MAX-1) /* Minimum (signed) int value */ +//#define LONG_MAX 0X7FFFFFFFL /* max value for a long */ +//#define LONG_MIN (-LONG_MAX-1) /* min value for a long */ +//#define UINT_MAX 0xFFFFFFFF /* Maximum unsigned int value */ +//#define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */ #define CHAR_BIT 8 /* Number of bits in a char */ +#ifndef SIZE_MAX #define SIZE_MAX 0xFFFFFFFF /* Maximum unsigned size_t */ +#endif // // Address families. @@ -105,7 +107,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // Basic types mapping // -typedef UINTN size_t; +//typedef UINTN size_t; typedef UINTN off_t; typedef UINTN u_int; typedef INTN ptrdiff_t; @@ -116,7 +118,7 @@ typedef UINT8 sa_family_t; typedef UINT8 u_char; typedef UINT32 uid_t; typedef UINT32 gid_t; -typedef CHAR16 wchar_t; +//typedef CHAR16 wchar_t; // // File operations are not required for EFI building, @@ -158,38 +160,42 @@ struct sockaddr { extern int errno; extern FILE *stderr; +#ifdef __cplusplus +extern "C" { +#endif // // Function prototypes of CRT Library routines // +// Jief : need to comment out prototypes that we already have because ours are inlines. These prototypes make the compiler link for a non inline version that we don't have. void * -malloc ( +CryptoPkg_BaseMemAllocation_malloc ( size_t ); void * -realloc ( +CryptoPkg_BaseMemAllocation_realloc ( void *, size_t ); void -free ( +CryptoPkg_BaseMemAllocation_free ( void * ); -void * -memset ( - void *, - int, - size_t - ); - -int -memcmp ( - const void *, - const void *, - size_t - ); +//void * +//memset ( +// void *, +// int, +// size_t +// ); +// +//int +//memcmp ( +// const void *, +// const void *, +// size_t +// ); int isdigit ( @@ -221,30 +227,30 @@ tolower ( int ); -int -strcmp ( - const char *, - const char * - ); - -int -strncasecmp ( - const char *, - const char *, - size_t - ); - -char * -strchr ( - const char *, - int - ); - -char * -strrchr ( - const char *, - int - ); +//int +//strcmp ( +// const char *, +// const char * +// ); +// +//int +//strncasecmp ( +// const char *, +// const char *, +// size_t +// ); +// +//char * +//strchr ( +// const char *, +// int +// ); +// +//char * +//strrchr ( +// const char *, +// int +// ); unsigned long strtoul ( @@ -265,17 +271,17 @@ strerror ( int ); -size_t -strspn ( - const char *, - const char * - ); - -size_t -strcspn ( - const char *, - const char * - ); +//size_t +//strspn ( +// const char *, +// const char * +// ); +// +//size_t +//strcspn ( +// const char *, +// const char * +// ); int printf ( @@ -403,25 +409,31 @@ strcpy ( const char *strSource ); +int snprintf(char* str, size_t size, const char* format, ...); // // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions // -#define memcpy(dest, source, count) CopyMem(dest,source,(UINTN)(count)) -#define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch)) +// Jief : comment out macro we already have +//#define memcpy(dest, source, count) CopyMem(dest,source,(UINTN)(count)) +//#define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch)) #define memchr(buf, ch, count) ScanMem8(buf,(UINTN)(count),(UINT8)ch) -#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count))) -#define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count)) -#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE)) -#define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count) -#define strcat(strDest, strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource) -#define strncmp(string1, string2, count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count))) -#define strcasecmp(str1, str2) (int)AsciiStriCmp(str1,str2) -#define strstr(s1, s2) AsciiStrStr(s1,s2) -#define sprintf(buf, ...) AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__) +//#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count))) +//#define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count)) +//#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE)) +//#define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count) +//#define strcat(strDest, strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource) +//#define strncmp(string1, string2, count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count))) +//#define strcasecmp(str1, str2) (int)AsciiStriCmp(str1,str2) +//#define strstr(s1, s2) AsciiStrStr(s1,s2) +//#define sprintf(buf, ...) AsciiSPrint(buf,MAX_STRING_SIZE,__VA_ARGS__) #define localtime(timer) NULL -#define assert(expression) +//#define assert(expression) #define offsetof(type, member) OFFSET_OF(type,member) #define atoi(nptr) AsciiStrDecimalToUintn(nptr) #define gettimeofday(tvp, tz) do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0) +#ifdef __cplusplus +} +#endif + #endif diff --git a/Library/OpensslLib/CryptoPkg/Include/stdint.h b/Library/OpensslLib/CryptoPkg/Include/stdint.h deleted file mode 100644 index 17b8c767d..000000000 --- a/Library/OpensslLib/CryptoPkg/Include/stdint.h +++ /dev/null @@ -1,19 +0,0 @@ -/** @file - Include file to support building the third-party cryptographic library. - -Copyright (c) 2023, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include - -typedef INT8 int8_t; -typedef UINT8 uint8_t; -typedef INT16 int16_t; -typedef UINT16 uint16_t; -typedef INT32 int32_t; -typedef UINT32 uint32_t; -typedef INT64 int64_t; -typedef UINT64 uint64_t; -typedef UINTN uintptr_t; diff --git a/Library/OpensslLib/CryptoPkg/Include/stdint.h.dis b/Library/OpensslLib/CryptoPkg/Include/stdint.h.dis new file mode 100644 index 000000000..8696633a8 --- /dev/null +++ b/Library/OpensslLib/CryptoPkg/Include/stdint.h.dis @@ -0,0 +1,19 @@ +/** @file + Include file to support building the third-party cryptographic library. + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +//typedef INT8 int8_t; +//typedef UINT8 uint8_t; +//typedef INT16 int16_t; +//typedef UINT16 uint16_t; +//typedef INT32 int32_t; +//typedef UINT32 uint32_t; +//typedef INT64 int64_t; +//typedef UINT64 uint64_t; +//typedef UINTN uintptr_t; diff --git a/Library/OpensslLib/CryptoPkg/TimerWrapper.c b/Library/OpensslLib/CryptoPkg/TimerWrapper.c index 2dfc6fe6c..2bcce985f 100644 --- a/Library/OpensslLib/CryptoPkg/TimerWrapper.c +++ b/Library/OpensslLib/CryptoPkg/TimerWrapper.c @@ -148,7 +148,7 @@ gmtime ( return NULL; } - GmTime = malloc (sizeof (struct tm)); + GmTime = CryptoPkg_BaseMemAllocation_malloc (sizeof (struct tm)); if (GmTime == NULL) { return NULL; } diff --git a/Library/OpensslLib/OpensslLib.dec b/Library/OpensslLib/OpensslLib.dec new file mode 100644 index 000000000..cf5d744d6 --- /dev/null +++ b/Library/OpensslLib/OpensslLib.dec @@ -0,0 +1,32 @@ +## @file MdePkg.dec +# This Package provides all definitions, library classes and libraries instances. +# +# It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of +# EFI1.10/UEFI2.7/PI1.7 and some Industry Standards. +# +# Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
+# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + + +[Defines] + DEC_SPECIFICATION = 0x00010005 + PACKAGE_NAME = Openssl + PACKAGE_GUID = A303B781-8C0D-432F-849E-B36B6CCDBE55 + PACKAGE_VERSION = 1 + + +[Includes] + openssl/include + openssl/providers/common/include + openssl/providers/implementations/include + OpensslGen/include + OpensslGen/providers/common/include + CryptoPkg/Include + ../../rEFIt_UEFI/PlatformEFI/posix + ../../Include + diff --git a/Library/OpensslLib/OpensslLib.inf b/Library/OpensslLib/OpensslLib.inf index 7158a1124..7c225ae6c 100644 --- a/Library/OpensslLib/OpensslLib.inf +++ b/Library/OpensslLib/OpensslLib.inf @@ -20,7 +20,7 @@ DEFINE OPENSSL_PATH = openssl DEFINE OPENSSL_GEN_PATH = OpensslGen - DEFINE OPENSSL_FLAGS = -DL_ENDIAN -DOPENSSL_SMALL_FOOTPRINT -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DEDK2_OPENSSL_NOEC=1 -DOPENSSL_NO_ASM + DEFINE OPENSSL_FLAGS = -DL_ENDIAN -DOPENSSL_SMALL_FOOTPRINT -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DEDK2_OPENSSL_NOEC=1 -DOPENSSL_NO_ASM -D__STDC_NO_ATOMICS__ DEFINE OPENSSL_FLAGS_NOASM = # @@ -656,10 +656,14 @@ OpensslStub/SslStatServNull.c OpensslStub/SslExtServNull.c OpensslStub/Pkcs12Null.c + CryptoPkg/CrtWrapper.c + CryptoPkg/TimerWrapper.c + CryptoPkg/BaseMemAllocation.c [Packages] MdePkg/MdePkg.dec - CryptoPkg/CryptoPkg.dec + Library/OpensslLib/OpensslLib.dec +# CryptoPkg/CryptoPkg.dec [LibraryClasses] BaseLib diff --git a/Library/OpensslLib/openssl/crypto/conf/conf_lib.c b/Library/OpensslLib/openssl/crypto/conf/conf_lib.c index a23600352..a486f8344 100644 --- a/Library/OpensslLib/openssl/crypto/conf/conf_lib.c +++ b/Library/OpensslLib/openssl/crypto/conf/conf_lib.c @@ -408,7 +408,7 @@ int NCONF_dump_bio(const CONF *conf, BIO *out) */ OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void) { - OPENSSL_INIT_SETTINGS *ret = malloc(sizeof(*ret)); + OPENSSL_INIT_SETTINGS *ret = CryptoPkg_BaseMemAllocation_malloc(sizeof(*ret)); if (ret == NULL) return NULL; @@ -464,7 +464,7 @@ int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings, void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings) { - free(settings->filename); - free(settings->appname); - free(settings); + CryptoPkg_BaseMemAllocation_free(settings->filename); + CryptoPkg_BaseMemAllocation_free(settings->appname); + CryptoPkg_BaseMemAllocation_free(settings); } diff --git a/Library/OpensslLib/openssl/crypto/mem.c b/Library/OpensslLib/openssl/crypto/mem.c index f6cdcf5a4..e0c655208 100644 --- a/Library/OpensslLib/openssl/crypto/mem.c +++ b/Library/OpensslLib/openssl/crypto/mem.c @@ -187,7 +187,7 @@ void *CRYPTO_malloc(size_t num, const char *file, int line) allow_customize = 0; } - return malloc(num); + return CryptoPkg_BaseMemAllocation_malloc(num); } void *CRYPTO_zalloc(size_t num, const char *file, int line) @@ -217,7 +217,7 @@ void *CRYPTO_realloc(void *str, size_t num, const char *file, int line) return NULL; } - return realloc(str, num); + return CryptoPkg_BaseMemAllocation_realloc(str, num); } void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num, @@ -255,7 +255,7 @@ void CRYPTO_free(void *str, const char *file, int line) return; } - free(str); + CryptoPkg_BaseMemAllocation_free(str); } void CRYPTO_clear_free(void *str, size_t num, const char *file, int line) diff --git a/Library/OpensslLib/openssl/include/internal/tsan_assist.h b/Library/OpensslLib/openssl/include/internal/tsan_assist.h index 60ecbd5f0..8fb653393 100644 --- a/Library/OpensslLib/openssl/include/internal/tsan_assist.h +++ b/Library/OpensslLib/openssl/include/internal/tsan_assist.h @@ -49,6 +49,7 @@ #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \ && !defined(__STDC_NO_ATOMICS__) +# include # include # if defined(ATOMIC_POINTER_LOCK_FREE) \ diff --git a/Library/OpensslLib/openssl/include/openssl/e_os2.h b/Library/OpensslLib/openssl/include/openssl/e_os2.h index 672890927..f53ca459c 100644 --- a/Library/OpensslLib/openssl/include/openssl/e_os2.h +++ b/Library/OpensslLib/openssl/include/openssl/e_os2.h @@ -220,14 +220,15 @@ extern "C" { # define OPENSSL_NO_INTTYPES_H # define OPENSSL_NO_STDINT_H # if defined(OPENSSL_SYS_UEFI) -typedef INT8 int8_t; -typedef UINT8 uint8_t; -typedef INT16 int16_t; -typedef UINT16 uint16_t; -typedef INT32 int32_t; -typedef UINT32 uint32_t; -typedef INT64 int64_t; -typedef UINT64 uint64_t; +//typedef INT8 int8_t; +//typedef UINT8 uint8_t; +//typedef INT16 int16_t; +//typedef UINT16 uint16_t; +//typedef INT32 int32_t; +//typedef UINT32 uint32_t; +//typedef INT64 int64_t; +//typedef UINT64 uint64_t; +#include # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ defined(__osf__) || defined(__sgi) || defined(__hpux) || \ defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__) diff --git a/Library/OpensslLib/openssl/ssl/ssl_lib.c b/Library/OpensslLib/openssl/ssl/ssl_lib.c index 214884b0f..4e9dae0a1 100644 --- a/Library/OpensslLib/openssl/ssl/ssl_lib.c +++ b/Library/OpensslLib/openssl/ssl/ssl_lib.c @@ -5526,13 +5526,13 @@ static int nss_keylog_int(const char *prefix, *cursor++ = ' '; for (i = 0; i < parameter_1_len; i++) { - sprintf(cursor, "%02x", parameter_1[i]); + snprintf(cursor, out_len, "%02x", parameter_1[i]); cursor += 2; } *cursor++ = ' '; for (i = 0; i < parameter_2_len; i++) { - sprintf(cursor, "%02x", parameter_2[i]); + snprintf(cursor, out_len, "%02x", parameter_2[i]); cursor += 2; } *cursor = '\0'; diff --git a/OpenCorePkg b/OpenCorePkg index 0fcc050a4..8270a6fb8 160000 --- a/OpenCorePkg +++ b/OpenCorePkg @@ -1 +1 @@ -Subproject commit 0fcc050a44f6fa06788b349e65b4e10fcdabde67 +Subproject commit 8270a6fb81b95abf957d2b7acd945fcc039ffde6 diff --git a/Protocols/SMCHelper/SMCHelper.c b/Protocols/SMCHelper/SMCHelper.c index 4dcab8ba1..616f4b23d 100644 --- a/Protocols/SMCHelper/SMCHelper.c +++ b/Protocols/SMCHelper/SMCHelper.c @@ -4,7 +4,7 @@ * Created by Slice on 03.10.2016. * */ -/* + #include #include #include @@ -16,8 +16,7 @@ #include #include -*/ -#include "SmcHelper.h" + // DBG_TO: 0=no debug, 1=serial, 2=console 3=log // serial requires diff --git a/rEFIt_UEFI/PlatformEFI/posix/abort.cpp b/rEFIt_UEFI/PlatformEFI/posix/abort.cpp index d72f053b2..a2a58f698 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/abort.cpp +++ b/rEFIt_UEFI/PlatformEFI/posix/abort.cpp @@ -142,13 +142,3 @@ void panic(void) { panic(nullptr); } - - -void _assert(bool b, const char* format, ...) -{ - if ( !b ) { - VA_LIST va; - VA_START(va, format); - panic_(format, va); // panic doesn't return - } -} diff --git a/rEFIt_UEFI/PlatformEFI/posix/abort.h b/rEFIt_UEFI/PlatformEFI/posix/abort.h index 007ac0fa4..4bb76f774 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/abort.h +++ b/rEFIt_UEFI/PlatformEFI/posix/abort.h @@ -5,9 +5,7 @@ # define __attribute__(x) #endif -#ifndef __cplusplus // C doesn't know bool -#define bool unsigned char -#endif +#include "stdbool.h" // C doesn't know bool, in case this header is included by a C source extern bool stop_at_panic; extern bool i_have_panicked; @@ -36,15 +34,6 @@ void panic(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)) void log_technical_bug(const char* format, ...) __attribute__((__format__(__printf__, 1, 2))); -#ifdef _MSC_VER -# define assert(expr) _assert(expr, "Expression \"%s\" failed in %s", #expr, __FUNCSIG__) -#else -# define assert(expr) _assert(expr, "Expression \"%s\" failed in %s", #expr, __PRETTY_FUNCTION__) -#endif -#define assertf(...) _assert(__VA_ARGS__) - -void _assert(bool b, const char* format, ...) __attribute__((__format__(__printf__, 2, 3))); - #ifdef __cplusplus class DontStopAtPanic { diff --git a/rEFIt_UEFI/PlatformEFI/posix/assert.cpp b/rEFIt_UEFI/PlatformEFI/posix/assert.cpp new file mode 100644 index 000000000..4210d5a92 --- /dev/null +++ b/rEFIt_UEFI/PlatformEFI/posix/assert.cpp @@ -0,0 +1,15 @@ + +#include // Only use angled for Platform, else, xcode project won't compile +#include "assert.h" +#include "abort.h" + + + +void _assert(bool b, const char* format, ...) +{ + if ( !b ) { + VA_LIST va; + VA_START(va, format); + log_technical_bug(format, va); // panic doesn't return + } +} diff --git a/rEFIt_UEFI/PlatformEFI/posix/assert.h b/rEFIt_UEFI/PlatformEFI/posix/assert.h new file mode 100644 index 000000000..545d92dc7 --- /dev/null +++ b/rEFIt_UEFI/PlatformEFI/posix/assert.h @@ -0,0 +1,24 @@ +#ifndef __ASSERT_H__ +#define __ASSERT_H__ + +#include "stdbool.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef _MSC_VER +# define assert(expr) _assert(expr, "Expression \"%s\" failed in %s", #expr, __FUNCSIG__) +#else +# define assert(expr) _assert(expr, "Expression \"%s\" failed in %s", #expr, __PRETTY_FUNCTION__) +#endif +#define assertf(...) _assert(__VA_ARGS__) + +void _assert(bool b, const char* format, ...) __attribute__((__format__(__printf__, 2, 3))); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/rEFIt_UEFI/PlatformEFI/posix/limits.h b/rEFIt_UEFI/PlatformEFI/posix/limits.h index d6181aeaf..9e654143f 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/limits.h +++ b/rEFIt_UEFI/PlatformEFI/posix/limits.h @@ -1,37 +1,97 @@ //#define UINT_MAX #define SIZE_T_MAX MAX_UINTN +#ifndef INT8_MIN #define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#ifndef INT16_MIN +#endif #define INT16_MIN (-32768) +#endif +#ifndef INT32_MIN #define INT32_MIN (-2147483647 - 1) +#endif +#ifndef INT64_MIN #define INT64_MIN (-9223372036854775807LL - 1) +#endif +#ifndef INT8_MAX #define INT8_MAX 127 +#endif +#ifndef INT16_MAX #define INT16_MAX 32767 +#endif +#ifndef INT32_MAX #define INT32_MAX 2147483647 +#endif +#ifndef INT64_MAX #define INT64_MAX 9223372036854775807LL +#endif +#ifndef UINT8_MAX #define UINT8_MAX 0xff /* 255U */ +#endif +#ifndef UINT16_MAX #define UINT16_MAX 0xffff /* 65535U */ +#endif +#ifndef UINT32_MAX #define UINT32_MAX 0xffffffff /* 4294967295U */ +#endif +#ifndef UINT64_MAX #define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ +#endif +#ifndef CHAR_MIN #define CHAR_MIN (-128) +#endif +#ifndef SCHAR_MIN #define SCHAR_MIN (-128) +#endif +#ifndef SHRT_MIN #define SHRT_MIN (-32768) +#endif +#ifndef INT_MIN #define INT_MIN INT32_MIN +#endif +#ifndef LONG_MIN #define LONG_MIN INT64_MIN +#endif +#ifndef LLONG_MIN #define LLONG_MIN INT64_MIN +#endif +#ifndef CHAR_MAX #define CHAR_MAX 127 +#endif +#ifndef SCHAR_MAX #define SCHAR_MAX 127 +#endif +#ifndef SHRT_MAX #define SHRT_MAX 32767 +#endif +#ifndef INT_MAX #define INT_MAX INT32_MAX +#endif +#ifndef LONG_MAX #define LONG_MAX INT64_MAX +#endif +#ifndef LLONG_MAX #define LLONG_MAX INT64_MAX +#endif +#ifndef UCHAR_MAX #define UCHAR_MAX 255 +#endif +#ifndef USHRT_MAX #define USHRT_MAX 65535 +#endif +#ifndef UINT_MAX #define UINT_MAX UINT32_MAX +#endif +#ifndef ULONG_MAX #define ULONG_MAX UINT64_MAX +#endif +#ifndef ULLONG_MAX #define ULLONG_MAX UINT64_MAX +#endif diff --git a/rEFIt_UEFI/PlatformEFI/posix/posix.h b/rEFIt_UEFI/PlatformEFI/posix/posix.h index ca7afed8d..835f2ebfc 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/posix.h +++ b/rEFIt_UEFI/PlatformEFI/posix/posix.h @@ -18,6 +18,7 @@ #include "strings.h" #include "wchar.h" #include "abort.h" +#include "assert.h" #include "posix_additions.h" // // Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions @@ -48,7 +49,7 @@ void abort(void); #endif -inline float fabsf(float x) { +static inline __attribute__((always_inline)) float fabsf(float x) { if (x < 0.f) return -x; return x; } diff --git a/rEFIt_UEFI/PlatformEFI/posix/stdint.h b/rEFIt_UEFI/PlatformEFI/posix/stdint.h index 2748c0a42..1fdb3e203 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/stdint.h +++ b/rEFIt_UEFI/PlatformEFI/posix/stdint.h @@ -13,6 +13,14 @@ static_assert(sizeof(long long) == 8, "sizeof(long long) != 8"); static_assert(true, "true"); #endif +////#if defined(OPENSSL_SMALL_FOOTPRINT) && defined(__clang__) +//// let's include the one from the compiler. Except for uintptr_t because it's define as a long and we prefer long long for microsoft compatibility. It's same on macos. +//// It's currently (Jan 2024) only needed when you compile with OpenSsl and xcode because of the inclusion of stdatomic +//#define _UINTPTR_T // for clang to avoid to declare uintptr_t +//#undef __UINTPTR_TYPE__ +//#include_next +////#endif + typedef UINT8 uint8_t; typedef UINT16 uint16_t; diff --git a/rEFIt_UEFI/PlatformEFI/posix/stdlib.h b/rEFIt_UEFI/PlatformEFI/posix/stdlib.h index d23afef06..5ea212f30 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/stdlib.h +++ b/rEFIt_UEFI/PlatformEFI/posix/stdlib.h @@ -1,6 +1,7 @@ #ifndef __CLOVER_STDLIB_H__ #define __CLOVER_STDLIB_H__ + #ifdef __cplusplus extern "C" { #endif @@ -18,28 +19,37 @@ extern "C" { extern "C" { #endif -void abort(void); -inline void* malloc(size_t size) +void abort(void); // abort() is defined in stdlib.h + + +#ifndef OPENSSL_SMALL_FOOTPRINT +// can't use these memory function with OpenSslLib + +static inline __attribute__((always_inline)) void* malloc(size_t size) { void* ptr = AllocatePool(size); // MemLogf(false, 0, "malloc(%zd) %llx\n", size, uintptr_t(ptr)); return ptr; } -inline void* reallocWithOldSize(void *ptr, size_t newsize, size_t oldsize) // not the posix realloc. For EFI we need oldsize +static inline __attribute__((always_inline)) void* reallocWithOldSize(void *ptr, size_t newsize, size_t oldsize) // not the posix realloc. For EFI we need oldsize { void* newptr = ReallocatePool(oldsize, newsize, ptr); // MemLogf(false, 0, "reallocWithOldSize(%llx %zd %zd) %llx\n", uintptr_t(ptr), newsize, oldsize, uintptr_t(newptr)); return newptr; } -inline void free(void *ptr) +static inline __attribute__((always_inline)) void free(void *ptr) { // MemLogf(false, 0, "free(%llx)\n", uintptr_t(ptr)); FreePool(ptr); } +#endif + + + #ifdef __cplusplus } #endif diff --git a/rEFIt_UEFI/PlatformEFI/posix/string.cpp b/rEFIt_UEFI/PlatformEFI/posix/string.cpp index 636e51686..8ef615a33 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/string.cpp +++ b/rEFIt_UEFI/PlatformEFI/posix/string.cpp @@ -175,4 +175,81 @@ char* strstr(const char *haystack, const char *needle) } +/* Computes the length of the maximum initial segment of the string pointed to by s1 + which consists entirely of characters from the string pointed to by s2. */ +size_t strspn(const char *s1, const char *s2) +{ + UINT8 Map[32]; + UINT32 Index; + size_t Count; + + for (Index = 0; Index < 32; Index++) { + Map[Index] = 0; + } + + while (*s2) { + Map[*s2 >> 3] |= (1 << (*s2 & 7)); + s2++; + } + + if (*s1) { + Count = 0; + while (Map[*s1 >> 3] & (1 << (*s1 & 7))) { + Count++; + s1++; + } + + return Count; + } + + return 0; +} + +/* Computes the length of the maximum initial segment of the string pointed to by s1 + which consists entirely of characters not from the string pointed to by s2. */ +size_t strcspn(const char *s1, const char *s2) +{ + UINT8 Map[32]; + UINT32 Index; + size_t Count; + + for (Index = 0; Index < 32; Index++) { + Map[Index] = 0; + } + + while (*s2) { + Map[*s2 >> 3] |= (1 << (*s2 & 7)); + s2++; + } + + Map[0] |= 1; + + Count = 0; + while (!(Map[*s1 >> 3] & (1 << (*s1 & 7)))) { + Count++; + s1++; + } + + return Count; +} + + +/* Scan a string for the last occurrence of a character */ +char* strrchr(const char *str, int c) +{ + char *save; + + for (save = NULL; ; ++str) { + if (*str == c) { + save = (char *)str; + } + + if (*str == 0) { + return (save); + } + } +} + + + #endif diff --git a/rEFIt_UEFI/PlatformEFI/posix/string.h b/rEFIt_UEFI/PlatformEFI/posix/string.h index 75524724e..947e3c70a 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/string.h +++ b/rEFIt_UEFI/PlatformEFI/posix/string.h @@ -17,14 +17,14 @@ void* memcpy(void *dst, const void *src, size_t len) __attribute__ ((used)); #endif -inline void* memmove(void *dst, const void *src, size_t len) +static inline __attribute__((always_inline)) void* memmove(void *dst, const void *src, size_t len) { return CopyMem(dst, (void*)(src), len); } void* memcpy(void *dst, const void *src, size_t len); -//inline void* memcpy(void *dst, const void *src, size_t len) +//static inline __attribute__((always_inline)) void* memcpy(void *dst, const void *src, size_t len) //{ // return CopyMem(dst,src,len); //} @@ -33,7 +33,7 @@ int memcmp(const void *s1, const void *s2, size_t n); size_t strlen(const char *str); -inline char* strcat(char* s1, const char* s2) +static inline __attribute__((always_inline)) char* strcat(char* s1, const char* s2) { AsciiStrCatS(s1, AsciiStrLen(s1)+1, s2); return s1; @@ -42,13 +42,13 @@ inline char* strcat(char* s1, const char* s2) char* strncat(char* s1, const char* s2, size_t n); -inline char* strcpy(char* dst, const char* src) +static inline __attribute__((always_inline)) char* strcpy(char* dst, const char* src) { AsciiStrCpyS(dst,AsciiStrLen(src)+1,src); return dst; } -inline char* strncpy(char * dst, const char * src, size_t len) +static inline __attribute__((always_inline)) char* strncpy(char * dst, const char * src, size_t len) { AsciiStrnCpyS(dst,(UINTN)len+1,src,(UINTN)len); return dst; @@ -60,20 +60,36 @@ int strncmp(const char* s1, const char* s2, size_t n); int strncmp(const char *s1, const char *s2, size_t n); -extern void* memset(void *b, int c, size_t len); // memset is defined in cpp_util/memory.cpp because it is required by c++ -//inline void* memset(void *b, int c, size_t len) +void* memset(void *b, int c, size_t len); // memset is defined in cpp_util/memory.cpp because it is required by c++ +//static inline __attribute__((always_inline)) void* memset(void *b, int c, size_t len) //{ // SetMem(b, len, c); // return b; //} -//inline char* strncat(char *restrict s1, const char *restrict s2, size_t n) +//static inline __attribute__((always_inline)) char* strncat(char *restrict s1, const char *restrict s2, size_t n) //{ // return AsciiStrCatS(s1, AsciiStrLen(strDest)+1,strSource) //} // - char* strstr(const char *haystack, const char *needle); +static inline __attribute__((always_inline)) char* strchr(const char *s, int c) +{ + return (char*)ScanMem8((void *)(s),AsciiStrSize(s),(UINT8)c); +} + +/* Scan a string for the last occurrence of a character */ +char* strrchr (const char *str, int c); + +char* strstr(const char *haystack, const char *needle); + +/* Computes the length of the maximum initial segment of the string pointed to by s1 + which consists entirely of characters from the string pointed to by s2. */ +size_t strspn(const char *s1, const char *s2); + +/* Computes the length of the maximum initial segment of the string pointed to by s1 + which consists entirely of characters not from the string pointed to by s2. */ +size_t strcspn(const char *s1, const char *s2); #ifdef __cplusplus } diff --git a/rEFIt_UEFI/PlatformEFI/posix/strings.h b/rEFIt_UEFI/PlatformEFI/posix/strings.h index 3cd099c9e..a3ac3c56f 100644 --- a/rEFIt_UEFI/PlatformEFI/posix/strings.h +++ b/rEFIt_UEFI/PlatformEFI/posix/strings.h @@ -8,8 +8,7 @@ #ifndef strings_h #define strings_h -//#include -#include +#include "stddef.h" #ifdef __cplusplus extern "C" { diff --git a/rEFIt_UEFI/entry_scan/securehash.cpp b/rEFIt_UEFI/entry_scan/securehash.cpp index 5472f7487..037f73530 100644 --- a/rEFIt_UEFI/entry_scan/securehash.cpp +++ b/rEFIt_UEFI/entry_scan/securehash.cpp @@ -39,7 +39,7 @@ #include #include "entry_scan.h" -#include "../../Library/OpensslLib/openssl-1.0.1e/include/openssl/sha.h" +#include #include #include //#include diff --git a/rEFIt_UEFI/entry_scan/securevars.cpp b/rEFIt_UEFI/entry_scan/securevars.cpp index 1488d179d..f8f559a13 100644 --- a/rEFIt_UEFI/entry_scan/securevars.cpp +++ b/rEFIt_UEFI/entry_scan/securevars.cpp @@ -45,11 +45,14 @@ #include "securebootkeys.h" -#include "../../Library/OpensslLib/Include/OpenSslSupport.h" -#include "../../Library/OpensslLib/openssl-1.0.1e/include/openssl/err.h" -#include "../../Library/OpensslLib/openssl-1.0.1e/include/openssl/pem.h" -#include "../../Library/OpensslLib/openssl-1.0.1e/include/openssl/sha.h" -#include "../../Library/OpensslLib/openssl-1.0.1e/include/openssl/bio.h" +#include +#undef OPENSSL_NO_DEPRECATED + +#include +#include +#include +#include +#include #ifndef DEBUG_ALL #define DEBUG_SECURE_VARS 1 diff --git a/rEFIt_UEFI/include/SmcHelper.h b/rEFIt_UEFI/include/SmcHelper.h deleted file mode 100644 index 7d4cd3b53..000000000 --- a/rEFIt_UEFI/include/SmcHelper.h +++ /dev/null @@ -1,20 +0,0 @@ -//#ifndef SMC_HELPER_H -//#define SMC_HELPER_H - - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -EFI_STATUS SMCHelperInstall(EFI_HANDLE* Handle); - -//#endif diff --git a/rEFIt_UEFI/refit.inf b/rEFIt_UEFI/refit.inf index 6bb00ee84..c18dbafb3 100644 --- a/rEFIt_UEFI/refit.inf +++ b/rEFIt_UEFI/refit.inf @@ -162,8 +162,7 @@ include/QuirksCodes.h include/remove_ref.h include/rename_helper.h - include/SmcHelper.h - include/syslinux_mbr.h + include/syslinux_mbr.h include/TagTypes.h include/VolumeTypes.h libeg/AppleImageCodec.cpp @@ -342,6 +341,8 @@ PlatformEFI/include/printf_lite-test-cpp_conf.h PlatformEFI/include/printlib-test-cpp_conf.h PlatformEFI/include/XToolsConf.h + PlatformEFI/posix/assert.cpp + PlatformEFI/posix/assert.h PlatformEFI/posix/abort.cpp PlatformEFI/posix/abort.h PlatformEFI/posix/limits.h @@ -417,8 +418,8 @@ IntelFrameworkPkg/IntelFrameworkPkg.dec IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec -# Library/OpensslLib/openssl-1.0.1e/OpensslLib.dec OpenCorePkg/OpenCorePkg.dec # put this at this end of Packages list to avoid conflict with some includes + Library/OpensslLib/OpensslLib.dec # for secureboot. If secureboot is not enabled, OpensslLib = OpensslLibNull [LibraryClasses] UefiApplicationEntryPoint @@ -429,17 +430,18 @@ BaseLib DevicePathLib DxeServicesTableLib # for gDS + DxeServicesLib HdaDevicesLib HobLib IoLib MemLogLib VideoBiosPatchLib -# OpensslLib # for secureboot, I think WaveLib OcMainLib DebugLib OcDebugLogLibOc2Clover CppMemLib + OpensslLib # for secureboot. If secureboot is not enabled, OpensslLib = OpensslLibNull [Guids] gEfiAcpiTableGuid