]>
Commit | Line | Data |
---|---|---|
97f98500 HT |
1 | /** @file\r |
2 | Intrinsic Memory Routines Wrapper Implementation for OpenSSL-based\r | |
3 | Cryptographic Library.\r | |
4 | \r | |
933681b2 | 5 | Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>\r |
2009f6b4 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
97f98500 HT |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #include <Base.h>\r | |
11 | #include <Library/BaseMemoryLib.h>\r | |
420e5083 | 12 | #include <Library/BaseLib.h>\r |
97f98500 | 13 | \r |
7c342378 | 14 | typedef UINTN size_t;\r |
5d7a1d63 | 15 | \r |
7c342378 MK |
16 | #if defined (__GNUC__) || defined (__clang__)\r |
17 | #define GLOBAL_USED __attribute__((used))\r | |
933681b2 | 18 | #else\r |
7c342378 | 19 | #define GLOBAL_USED\r |
933681b2 LG |
20 | #endif\r |
21 | \r | |
97f98500 HT |
22 | /* OpenSSL will use floating point support, and C compiler produces the _fltused\r |
23 | symbol by default. Simply define this symbol here to satisfy the linker. */\r | |
7c342378 | 24 | int GLOBAL_USED _fltused = 1;\r |
97f98500 HT |
25 | \r |
26 | /* Sets buffers to a specified character */\r | |
7c342378 MK |
27 | void *\r |
28 | memset (\r | |
29 | void *dest,\r | |
30 | int ch,\r | |
31 | size_t count\r | |
32 | )\r | |
97f98500 | 33 | {\r |
1b98d6ce LQ |
34 | //\r |
35 | // NOTE: Here we use one base implementation for memset, instead of the direct\r | |
630f67dd LG |
36 | // optimized SetMem() wrapper. Because the IntrinsicLib has to be built\r |
37 | // without whole program optimization option, and there will be some\r | |
1b98d6ce LQ |
38 | // potential register usage errors when calling other optimized codes.\r |
39 | //\r | |
40 | \r | |
4a567c96 | 41 | //\r |
42 | // Declare the local variables that actually move the data elements as\r | |
43 | // volatile to prevent the optimizer from replacing this function with\r | |
44 | // the intrinsic memset()\r | |
45 | //\r | |
46 | volatile UINT8 *Pointer;\r | |
47 | \r | |
48 | Pointer = (UINT8 *)dest;\r | |
49 | while (count-- != 0) {\r | |
108ff4a0 | 50 | *(Pointer++) = (UINT8)ch;\r |
4a567c96 | 51 | }\r |
630f67dd | 52 | \r |
4a567c96 | 53 | return dest;\r |
97f98500 | 54 | }\r |
420e5083 | 55 | \r |
5d7a1d63 | 56 | /* Compare bytes in two buffers. */\r |
7c342378 MK |
57 | int\r |
58 | memcmp (\r | |
59 | const void *buf1,\r | |
60 | const void *buf2,\r | |
61 | size_t count\r | |
62 | )\r | |
5d7a1d63 | 63 | {\r |
7c342378 | 64 | return (int)CompareMem (buf1, buf2, count);\r |
5d7a1d63 QL |
65 | }\r |
66 | \r | |
7c342378 MK |
67 | int\r |
68 | strcmp (\r | |
69 | const char *s1,\r | |
70 | const char *s2\r | |
71 | )\r | |
420e5083 | 72 | {\r |
7c342378 | 73 | return (int)AsciiStrCmp (s1, s2);\r |
420e5083 | 74 | }\r |