Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / kvm / lib / string_override.c
blob5d1c87277c499d5759813df52a023da506af52d2
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <stddef.h>
4 /*
5 * Override the "basic" built-in string helpers so that they can be used in
6 * guest code. KVM selftests don't support dynamic loading in guest code and
7 * will jump into the weeds if the compiler decides to insert an out-of-line
8 * call via the PLT.
9 */
10 int memcmp(const void *cs, const void *ct, size_t count)
12 const unsigned char *su1, *su2;
13 int res = 0;
15 for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) {
16 if ((res = *su1 - *su2) != 0)
17 break;
19 return res;
22 void *memcpy(void *dest, const void *src, size_t count)
24 char *tmp = dest;
25 const char *s = src;
27 while (count--)
28 *tmp++ = *s++;
29 return dest;
32 void *memset(void *s, int c, size_t count)
34 char *xs = s;
36 while (count--)
37 *xs++ = c;
38 return s;
41 size_t strnlen(const char *s, size_t count)
43 const char *sc;
45 for (sc = s; count-- && *sc != '\0'; ++sc)
46 /* nothing */;
47 return sc - s;