1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/efi.h>
4 #include <asm/efi.h>
5 #include <asm/string.h>
6 
7 #include "efistub.h"
8 
9 #ifdef CONFIG_KASAN
10 #undef memcpy
11 #undef memmove
12 #undef memset
13 void *__memcpy(void *__dest, const void *__src, size_t __n) __alias(memcpy);
14 void *__memmove(void *__dest, const void *__src, size_t count) __alias(memmove);
15 void *__memset(void *s, int c, size_t count) __alias(memset);
16 #endif
17 
memcpy(void * dst,const void * src,size_t len)18 void *memcpy(void *dst, const void *src, size_t len)
19 {
20 	efi_bs_call(copy_mem, dst, src, len);
21 	return dst;
22 }
23 
24 extern void *memmove(void *dst, const void *src, size_t len) __alias(memcpy);
25 
memset(void * dst,int c,size_t len)26 void *memset(void *dst, int c, size_t len)
27 {
28 	efi_bs_call(set_mem, dst, len, c & U8_MAX);
29 	return dst;
30 }
31 
32 /**
33  * memcmp - Compare two areas of memory
34  * @cs: One area of memory
35  * @ct: Another area of memory
36  * @count: The size of the area.
37  */
38 #undef memcmp
memcmp(const void * cs,const void * ct,size_t count)39 int memcmp(const void *cs, const void *ct, size_t count)
40 {
41 	const unsigned char *su1, *su2;
42 	int res = 0;
43 
44 	for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
45 		if ((res = *su1 - *su2) != 0)
46 			break;
47 	return res;
48 }
49