1 // SPDX-License-Identifier: GPL-2.0
3 * arch/arm/boot/compressed/string.c
5 * Small subset of simple string routines
8 #include <linux/string.h>
11 * The decompressor is built without KASan but uses the same redirects as the
12 * rest of the kernel when CONFIG_KASAN is enabled, defining e.g. memcpy()
13 * to __memcpy() but since we are not linking with the main kernel string
14 * library in the decompressor, that will lead to link failures.
16 * Undefine KASan's versions, define the wrapped functions and alias them to
17 * the right names so that when e.g. __memcpy() appear in the code, it will
18 * still be linked to this local version of memcpy().
24 void *__memcpy(void *__dest, __const void *__src, size_t __n) __alias(memcpy);
25 void *__memmove(void *__dest, __const void *__src, size_t count) __alias(memmove);
26 void *__memset(void *s, int c, size_t count) __alias(memset);
29 void *memcpy(void *__dest, __const void *__src, size_t __n)
32 unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
34 for (i = __n >> 3; i > 0; i--) {
63 void *memmove(void *__dest, __const void *__src, size_t count)
65 unsigned char *d = __dest;
66 const unsigned char *s = __src;
72 return memcpy(__dest, __src, count);
79 size_t strlen(const char *s)
88 size_t strnlen(const char *s, size_t count)
92 for (sc = s; count-- && *sc != '\0'; ++sc)
97 int memcmp(const void *cs, const void *ct, size_t count)
99 const unsigned char *su1 = cs, *su2 = ct, *end = su1 + count;
103 res = *su1++ - *su2++;
110 int strcmp(const char *cs, const char *ct)
112 unsigned char c1, c2;
125 void *memchr(const void *s, int c, size_t count)
127 const unsigned char *p = s;
130 if ((unsigned char)c == *p++)
131 return (void *)(p - 1);
135 char *strchr(const char *s, int c)
137 while (*s != (char)c)
143 char *strrchr(const char *s, int c)
145 const char *last = NULL;
155 void *memset(void *s, int c, size_t count)