Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #include <stddef.h>
0003 
0004 /*
0005  * Override the "basic" built-in string helpers so that they can be used in
0006  * guest code.  KVM selftests don't support dynamic loading in guest code and
0007  * will jump into the weeds if the compiler decides to insert an out-of-line
0008  * call via the PLT.
0009  */
0010 int memcmp(const void *cs, const void *ct, size_t count)
0011 {
0012     const unsigned char *su1, *su2;
0013     int res = 0;
0014 
0015     for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) {
0016         if ((res = *su1 - *su2) != 0)
0017             break;
0018     }
0019     return res;
0020 }
0021 
0022 void *memcpy(void *dest, const void *src, size_t count)
0023 {
0024     char *tmp = dest;
0025     const char *s = src;
0026 
0027     while (count--)
0028         *tmp++ = *s++;
0029     return dest;
0030 }
0031 
0032 void *memset(void *s, int c, size_t count)
0033 {
0034     char *xs = s;
0035 
0036     while (count--)
0037         *xs++ = c;
0038     return s;
0039 }