Path: blob/master/tools/testing/selftests/kvm/lib/string_override.c
38237 views
// SPDX-License-Identifier: GPL-2.0-only1#include <stddef.h>23/*4* Override the "basic" built-in string helpers so that they can be used in5* guest code. KVM selftests don't support dynamic loading in guest code and6* will jump into the weeds if the compiler decides to insert an out-of-line7* call via the PLT.8*/9int memcmp(const void *cs, const void *ct, size_t count)10{11const unsigned char *su1, *su2;12int res = 0;1314for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) {15if ((res = *su1 - *su2) != 0)16break;17}18return res;19}2021void *memcpy(void *dest, const void *src, size_t count)22{23char *tmp = dest;24const char *s = src;2526while (count--)27*tmp++ = *s++;28return dest;29}3031void *memset(void *s, int c, size_t count)32{33char *xs = s;3435while (count--)36*xs++ = c;37return s;38}3940size_t strnlen(const char *s, size_t count)41{42const char *sc;4344for (sc = s; count-- && *sc != '\0'; ++sc)45/* nothing */;46return sc - s;47}484950