1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 /* 2 /* 3 * This provides an optimized implementation o !! 3 * arch/mips/boot/compressed/string.c 4 * implementation of memset and memmove. These !! 4 * 5 * standard kernel runtime versions are not ye !! 5 * Very small subset of simple string routines 6 * trust the gcc built-in implementations as t << 7 * (e.g. FPU ops) in the minimal decompression << 8 */ 6 */ 9 #include "error.h" << 10 7 11 #include "../string.c" !! 8 #include <linux/compiler_attributes.h> >> 9 #include <linux/types.h> >> 10 #include <asm/string.h> 12 11 13 #ifdef CONFIG_X86_32 !! 12 void *memcpy(void *dest, const void *src, size_t n) 14 static void *____memcpy(void *dest, const void << 15 { << 16 int d0, d1, d2; << 17 asm volatile( << 18 "rep ; movsl\n\t" << 19 "movl %4,%%ecx\n\t" << 20 "rep ; movsb\n\t" << 21 : "=&c" (d0), "=&D" (d1), "=&S << 22 : "" (n >> 2), "g" (n & 3), "1 << 23 : "memory"); << 24 << 25 return dest; << 26 } << 27 #else << 28 static void *____memcpy(void *dest, const void << 29 { 13 { 30 long d0, d1, d2; !! 14 int i; 31 asm volatile( !! 15 const char *s = src; 32 "rep ; movsq\n\t" !! 16 char *d = dest; 33 "movq %4,%%rcx\n\t" << 34 "rep ; movsb\n\t" << 35 : "=&c" (d0), "=&D" (d1), "=&S << 36 : "" (n >> 3), "g" (n & 7), "1 << 37 : "memory"); << 38 17 >> 18 for (i = 0; i < n; i++) >> 19 d[i] = s[i]; 39 return dest; 20 return dest; 40 } 21 } 41 #endif << 42 22 43 void *memset(void *s, int c, size_t n) 23 void *memset(void *s, int c, size_t n) 44 { 24 { 45 int i; 25 int i; 46 char *ss = s; 26 char *ss = s; 47 27 48 for (i = 0; i < n; i++) 28 for (i = 0; i < n; i++) 49 ss[i] = c; 29 ss[i] = c; 50 return s; 30 return s; 51 } 31 } 52 32 53 void *memmove(void *dest, const void *src, siz !! 33 void * __weak memmove(void *dest, const void *src, size_t n) 54 { 34 { 55 unsigned char *d = dest; !! 35 unsigned int i; 56 const unsigned char *s = src; !! 36 const char *s = src; 57 !! 37 char *d = dest; 58 if (d <= s || d - s >= n) !! 38 59 return ____memcpy(dest, src, n !! 39 if ((uintptr_t)dest < (uintptr_t)src) { 60 !! 40 for (i = 0; i < n; i++) 61 while (n-- > 0) !! 41 d[i] = s[i]; 62 d[n] = s[n]; !! 42 } else { 63 !! 43 for (i = n; i > 0; i--) 64 return dest; !! 44 d[i - 1] = s[i - 1]; 65 } << 66 << 67 /* Detect and warn about potential overlaps, b << 68 void *memcpy(void *dest, const void *src, size << 69 { << 70 if (dest > src && dest - src < n) { << 71 warn("Avoiding potentially uns << 72 return memmove(dest, src, n); << 73 } 45 } 74 return ____memcpy(dest, src, n); !! 46 return dest; 75 } 47 } 76 << 77 #ifdef CONFIG_KASAN << 78 extern void *__memset(void *s, int c, size_t n << 79 extern void *__memmove(void *dest, const void << 80 extern void *__memcpy(void *dest, const void * << 81 #endif << 82 48
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.