Path: blob/master/drivers/firmware/efi/libstub/intrinsics.c
26483 views
// SPDX-License-Identifier: GPL-2.012#include <linux/efi.h>3#include <asm/efi.h>4#include <asm/string.h>56#include "efistub.h"78#ifdef CONFIG_KASAN9#undef memcpy10#undef memmove11#undef memset12void *__memcpy(void *__dest, const void *__src, size_t __n) __alias(memcpy);13void *__memmove(void *__dest, const void *__src, size_t count) __alias(memmove);14void *__memset(void *s, int c, size_t count) __alias(memset);15#endif1617static void *efistub_memmove(u8 *dst, const u8 *src, size_t len)18{19if (src > dst || dst >= (src + len))20for (size_t i = 0; i < len; i++)21dst[i] = src[i];22else23for (ssize_t i = len - 1; i >= 0; i--)24dst[i] = src[i];2526return dst;27}2829static void *efistub_memset(void *dst, int c, size_t len)30{31for (u8 *d = dst; len--; d++)32*d = c;3334return dst;35}3637void *memcpy(void *dst, const void *src, size_t len)38{39if (efi_table_attr(efi_system_table, boottime) == NULL)40return efistub_memmove(dst, src, len);4142efi_bs_call(copy_mem, dst, src, len);43return dst;44}4546extern void *memmove(void *dst, const void *src, size_t len) __alias(memcpy);4748void *memset(void *dst, int c, size_t len)49{50if (efi_table_attr(efi_system_table, boottime) == NULL)51return efistub_memset(dst, c, len);5253efi_bs_call(set_mem, dst, len, c & U8_MAX);54return dst;55}5657/**58* memcmp - Compare two areas of memory59* @cs: One area of memory60* @ct: Another area of memory61* @count: The size of the area.62*/63#undef memcmp64int memcmp(const void *cs, const void *ct, size_t count)65{66const unsigned char *su1, *su2;67int res = 0;6869for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)70if ((res = *su1 - *su2) != 0)71break;72return res;73}747576