TianoCore EDK2 master
Loading...
Searching...
No Matches
MemLibWrapper.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
13#include "hal/base.h"
14#include "hal/library/memlib.h"
15
52void
54 void *dst_buf,
55 size_t dst_len,
56 const void *src_buf,
57 size_t src_len
58 )
59{
60 volatile uint8_t *dst;
61 const volatile uint8_t *src;
62
63 dst = (volatile uint8_t *)dst_buf;
64 src = (const volatile uint8_t *)src_buf;
65
66 /* Check for case where "dst" or "dst_len" may be invalid.
67 * Do not zero "dst" in this case. */
68 if ((dst == NULL) || (dst_len > (SIZE_MAX >> 1))) {
69 ASSERT (0);
70 }
71
72 /* Gaurd against invalid source. Zero "dst" in this case. */
73 if (src == NULL) {
74 ZeroMem (dst_buf, dst_len);
75 ASSERT (0);
76 }
77
78 /* Guard against overlap case. Zero "dst" in these cases. */
79 if (((src < dst) && (src + src_len > dst)) || ((dst < src) && (dst + src_len > src))) {
80 ZeroMem (dst_buf, dst_len);
81 ASSERT (0);
82 }
83
84 /* Guard against invalid lengths. Zero "dst" in these cases. */
85 if ((src_len > dst_len) ||
86 (src_len > (SIZE_MAX >> 1)))
87 {
88 ZeroMem (dst_buf, dst_len);
89 ASSERT (0);
90 }
91
92 while (src_len-- != 0) {
93 *(dst++) = *(src++);
94 }
95}
96
111void
113 void *buffer,
114 size_t length,
115 uint8_t value
116 )
117{
118 SetMem (buffer, length, value);
119}
120
135void
137 void *buffer,
138 size_t length
139 )
140{
141 ZeroMem (buffer, length);
142}
143
165bool
167 const void *destination_buffer,
168 const void *source_buffer,
169 size_t length
170 )
171{
172 if (CompareMem (destination_buffer, source_buffer, length) == 0) {
173 return true;
174 } else {
175 return false;
176 }
177}
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
bool libspdm_consttime_is_mem_equal(const void *destination_buffer, const void *source_buffer, size_t length)
void libspdm_set_mem(void *buffer, size_t length, uint8_t value)
void libspdm_zero_mem(void *buffer, size_t length)
void libspdm_copy_mem(void *dst_buf, size_t dst_len, const void *src_buf, size_t src_len)
Definition: MemLibWrapper.c:53