X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=CryptoPkg%2FLibrary%2FBaseCryptLib%2FSysCall%2FCrtWrapper.c;h=71a2ef34ed2bd99dc986c082199546e6a6516906;hb=2009f6b4c5cbd7dda95a2594288405224173d239;hp=7b3dda70e0941242e5b53af89d9bb878aaeca6df;hpb=f114914b39c03f6af3173ba3aae09395ed65faaa;p=mirror_edk2.git diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c index 7b3dda70e0..71a2ef34ed 100644 --- a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c @@ -2,27 +2,21 @@ C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based Cryptographic Library. -Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
-This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include +#include int errno = 0; FILE *stderr = NULL; -FILE *stdin = NULL; +FILE *stdin = NULL; FILE *stdout = NULL; typedef -INTN +int (*SORT_COMPARE)( IN VOID *Buffer1, IN VOID *Buffer2 @@ -84,14 +78,14 @@ QuickSortWorker ( } } // - // Swap pivot to it's final position (NextSwapLocaiton) + // Swap pivot to its final position (NextSwapLocation) // CopyMem (Buffer, Pivot, ElementSize); CopyMem (Pivot, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize); CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), Buffer, ElementSize); // - // Now recurse on 2 paritial lists. Neither of these will have the 'pivot' element. + // Now recurse on 2 partial lists. Neither of these will have the 'pivot' element. // IE list is sorted left half, pivot element, sorted right half... // QuickSortWorker ( @@ -136,6 +130,30 @@ char *strrchr (const char *str, int c) } } +/* 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 sscanf (const char *buffer, const char *format, ...) { @@ -146,6 +164,70 @@ int sscanf (const char *buffer, const char *format, ...) return 0; } +/* Maps errnum to an error-message string */ +char * strerror (int errnum) +{ + 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; +} + // // -- Character Classification Routines -- // @@ -244,7 +326,10 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c ASSERT (base != NULL); ASSERT (compare != NULL); - Buffer = AllocatePool (width); + // + // Use CRT-style malloc to cover BS and RT memory allocation. + // + Buffer = malloc (width); ASSERT (Buffer != NULL); // @@ -252,7 +337,7 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c // QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer); - FreePool (Buffer); + free (Buffer); return; } @@ -270,16 +355,23 @@ char *getenv (const char *varname) 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 -- // -/* Write formatted output using a pointer to a list of arguments */ -int vfprintf (FILE *stream, const char *format, VA_LIST arg) -{ - return 0; -} - /* Write data to a stream */ size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream) { @@ -300,36 +392,6 @@ int BIO_snprintf(char *buf, size_t n, const char *format, ...) return 0; } -void *UI_OpenSSL(void) -{ - return NULL; -} - -int X509_load_cert_file (VOID *ctx, const char *file, int type) -{ - return 0; -} - -int X509_load_crl_file (VOID *ctx, const char *file, int type) -{ - return 0; -} - -int chmod (const char *c, mode_t m) -{ - return -1; -} - -int close (int f) -{ - return -1; -} - -void closelog (void) -{ - -} - #ifdef __GNUC__ typedef @@ -338,7 +400,6 @@ VOID VOID ) __attribute__((__noreturn__)); - STATIC VOID EFIAPI @@ -348,8 +409,7 @@ NopFunction ( { } - -void exit (int e) +void abort (void) { NoReturnFuncPtr NoReturnFunc; @@ -360,8 +420,9 @@ void exit (int e) #else -void exit (int e) +void abort (void) { + // Do nothing } #endif @@ -381,11 +442,6 @@ size_t fread (void *b, size_t c, size_t i, FILE *f) return 0; } -int fprintf (FILE *f, const char *s, ...) -{ - return 0; -} - uid_t getuid (void) { return 0; @@ -406,42 +462,7 @@ gid_t getegid (void) return 0; } -off_t lseek (int a, off_t o, int d) -{ - return 0; -} - -void openlog (const char *c, int a, int b) -{ - -} - -ssize_t read (int f, void *b, size_t c) -{ - return 0; -} - -int stat (const char *c, struct stat *s) -{ - return -1; -} - -int strcasecmp (const char *c, const char *s) -{ - return 0; -} - -int strncasecmp (const char *c, const char *s, size_t l) -{ - return 0; -} - -void syslog (int a, const char *c, ...) -{ - -} - -ssize_t write (int f, const void *b, size_t l) +int printf (char const *fmt, ...) { return 0; }