Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * arch/arm/boot/compressed/string.c
  4 *
  5 * Small subset of simple string routines
  6 */
  7
  8#define __NO_FORTIFY
  9#include <linux/string.h>
 10
 11/*
 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.
 16 *
 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().
 20 */
 21#ifdef CONFIG_KASAN
 22#undef memcpy
 23#undef memmove
 24#undef memset
 25void *__memcpy(void *__dest, __const void *__src, size_t __n) __alias(memcpy);
 26void *__memmove(void *__dest, __const void *__src, size_t count) __alias(memmove);
 27void *__memset(void *s, int c, size_t count) __alias(memset);
 28#endif
 29
 30void *memcpy(void *__dest, __const void *__src, size_t __n)
 31{
 32	int i = 0;
 33	unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
 34
 35	for (i = __n >> 3; i > 0; i--) {
 36		*d++ = *s++;
 37		*d++ = *s++;
 38		*d++ = *s++;
 39		*d++ = *s++;
 40		*d++ = *s++;
 41		*d++ = *s++;
 42		*d++ = *s++;
 43		*d++ = *s++;
 44	}
 45
 46	if (__n & 1 << 2) {
 47		*d++ = *s++;
 48		*d++ = *s++;
 49		*d++ = *s++;
 50		*d++ = *s++;
 51	}
 52
 53	if (__n & 1 << 1) {
 54		*d++ = *s++;
 55		*d++ = *s++;
 56	}
 57
 58	if (__n & 1)
 59		*d++ = *s++;
 60
 61	return __dest;
 62}
 63
 64void *memmove(void *__dest, __const void *__src, size_t count)
 65{
 66	unsigned char *d = __dest;
 67	const unsigned char *s = __src;
 68
 69	if (__dest == __src)
 70		return __dest;
 71
 72	if (__dest < __src)
 73		return memcpy(__dest, __src, count);
 74
 75	while (count--)
 76		d[count] = s[count];
 77	return __dest;
 78}
 79
 80size_t strlen(const char *s)
 81{
 82	const char *sc = s;
 83
 84	while (*sc != '\0')
 85		sc++;
 86	return sc - s;
 87}
 88
 89size_t strnlen(const char *s, size_t count)
 90{
 91	const char *sc;
 92
 93	for (sc = s; count-- && *sc != '\0'; ++sc)
 94		/* nothing */;
 95	return sc - s;
 96}
 97
 98int memcmp(const void *cs, const void *ct, size_t count)
 99{
100	const unsigned char *su1 = cs, *su2 = ct, *end = su1 + count;
101	int res = 0;
102
103	while (su1 < end) {
104		res = *su1++ - *su2++;
105		if (res)
106			break;
107	}
108	return res;
109}
110
111int strcmp(const char *cs, const char *ct)
112{
113	unsigned char c1, c2;
114	int res = 0;
115
116	do {
117		c1 = *cs++;
118		c2 = *ct++;
119		res = c1 - c2;
120		if (res)
121			break;
122	} while (c1);
123	return res;
124}
125
126void *memchr(const void *s, int c, size_t count)
127{
128	const unsigned char *p = s;
129
130	while (count--)
131		if ((unsigned char)c == *p++)
132			return (void *)(p - 1);
133	return NULL;
134}
135
136char *strchr(const char *s, int c)
137{
138	while (*s != (char)c)
139		if (*s++ == '\0')
140			return NULL;
141	return (char *)s;
142}
143
144char *strrchr(const char *s, int c)
145{
146	const char *last = NULL;
147	do {
148		if (*s == (char)c)
149			last = s;
150	} while (*s++);
151	return (char *)last;
152}
153
154#undef memset
155
156void *memset(void *s, int c, size_t count)
157{
158	char *xs = s;
159	while (count--)
160		*xs++ = c;
161	return s;
 
 
 
 
 
162}
v3.5.6
 
  1/*
  2 * arch/arm/boot/compressed/string.c
  3 *
  4 * Small subset of simple string routines
  5 */
  6
 
  7#include <linux/string.h>
  8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  9void *memcpy(void *__dest, __const void *__src, size_t __n)
 10{
 11	int i = 0;
 12	unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
 13
 14	for (i = __n >> 3; i > 0; i--) {
 15		*d++ = *s++;
 16		*d++ = *s++;
 17		*d++ = *s++;
 18		*d++ = *s++;
 19		*d++ = *s++;
 20		*d++ = *s++;
 21		*d++ = *s++;
 22		*d++ = *s++;
 23	}
 24
 25	if (__n & 1 << 2) {
 26		*d++ = *s++;
 27		*d++ = *s++;
 28		*d++ = *s++;
 29		*d++ = *s++;
 30	}
 31
 32	if (__n & 1 << 1) {
 33		*d++ = *s++;
 34		*d++ = *s++;
 35	}
 36
 37	if (__n & 1)
 38		*d++ = *s++;
 39
 40	return __dest;
 41}
 42
 43void *memmove(void *__dest, __const void *__src, size_t count)
 44{
 45	unsigned char *d = __dest;
 46	const unsigned char *s = __src;
 47
 48	if (__dest == __src)
 49		return __dest;
 50
 51	if (__dest < __src)
 52		return memcpy(__dest, __src, count);
 53
 54	while (count--)
 55		d[count] = s[count];
 56	return __dest;
 57}
 58
 59size_t strlen(const char *s)
 60{
 61	const char *sc = s;
 62
 63	while (*sc != '\0')
 64		sc++;
 65	return sc - s;
 66}
 67
 
 
 
 
 
 
 
 
 
 68int memcmp(const void *cs, const void *ct, size_t count)
 69{
 70	const unsigned char *su1 = cs, *su2 = ct, *end = su1 + count;
 71	int res = 0;
 72
 73	while (su1 < end) {
 74		res = *su1++ - *su2++;
 75		if (res)
 76			break;
 77	}
 78	return res;
 79}
 80
 81int strcmp(const char *cs, const char *ct)
 82{
 83	unsigned char c1, c2;
 84	int res = 0;
 85
 86	do {
 87		c1 = *cs++;
 88		c2 = *ct++;
 89		res = c1 - c2;
 90		if (res)
 91			break;
 92	} while (c1);
 93	return res;
 94}
 95
 96void *memchr(const void *s, int c, size_t count)
 97{
 98	const unsigned char *p = s;
 99
100	while (count--)
101		if ((unsigned char)c == *p++)
102			return (void *)(p - 1);
103	return NULL;
104}
105
106char *strchr(const char *s, int c)
107{
108	while (*s != (char)c)
109		if (*s++ == '\0')
110			return NULL;
111	return (char *)s;
112}
113
 
 
 
 
 
 
 
 
 
 
114#undef memset
115
116void *memset(void *s, int c, size_t count)
117{
118	char *xs = s;
119	while (count--)
120		*xs++ = c;
121	return s;
122}
123
124void __memzero(void *s, size_t count)
125{
126	memset(s, 0, count);
127}