1 // SPDX-License-Identifier: GPL-2.0
3 * arch/arm/boot/compressed/string.c
5 * Small subset of simple string routines
9 #include <linux/string.h>
12 * The decompressor is built without KASan but uses the same redirects as the
13 * rest of the kernel when CONFIG_KASAN is enabled, defining e.g. memcpy()
14 * to __memcpy() but since we are not linking with the main kernel string
15 * library in the decompressor, that will lead to link failures.
17 * Undefine KASan's versions, define the wrapped functions and alias them to
18 * the right names so that when e.g. __memcpy() appear in the code, it will
19 * still be linked to this local version of memcpy().
25 void *__memcpy(void *__dest, __const void *__src, size_t __n) __alias(memcpy);
26 void *__memmove(void *__dest, __const void *__src, size_t count) __alias(memmove);
27 void *__memset(void *s, int c, size_t count) __alias(memset);
30 void *memcpy(void *__dest, __const void *__src, size_t __n)
33 unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
35 for (i = __n >> 3; i > 0; i--) {
64 void *memmove(void *__dest, __const void *__src, size_t count)
66 unsigned char *d = __dest;
67 const unsigned char *s = __src;
73 return memcpy(__dest, __src, count);
80 size_t strlen(const char *s)
89 size_t strnlen(const char *s, size_t count)
93 for (sc = s; count-- && *sc != '\0'; ++sc)
98 int memcmp(const void *cs, const void *ct, size_t count)
100 const unsigned char *su1 = cs, *su2 = ct, *end = su1 + count;
104 res = *su1++ - *su2++;
111 int strcmp(const char *cs, const char *ct)
113 unsigned char c1, c2;
126 void *memchr(const void *s, int c, size_t count)
128 const unsigned char *p = s;
131 if ((unsigned char)c == *p++)
132 return (void *)(p - 1);
136 char *strchr(const char *s, int c)
138 while (*s != (char)c)
144 char *strrchr(const char *s, int c)
146 const char *last = NULL;
156 void *memset(void *s, int c, size_t count)