1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_ARM_STRING_H
3 #define __ASM_ARM_STRING_H
4
5 /*
6 * We don't do inline string functions, since the
7 * optimised inline asm versions are not small.
8 *
9 * The __underscore versions of some functions are for KASan to be able
10 * to replace them with instrumented versions.
11 */
12
13 #define __HAVE_ARCH_STRRCHR
14 extern char * strrchr(const char * s, int c);
15
16 #define __HAVE_ARCH_STRCHR
17 extern char * strchr(const char * s, int c);
18
19 #define __HAVE_ARCH_MEMCPY
20 extern void * memcpy(void *, const void *, __kernel_size_t);
21 extern void *__memcpy(void *dest, const void *src, __kernel_size_t n);
22
23 #define __HAVE_ARCH_MEMMOVE
24 extern void * memmove(void *, const void *, __kernel_size_t);
25 extern void *__memmove(void *dest, const void *src, __kernel_size_t n);
26
27 #define __HAVE_ARCH_MEMCHR
28 extern void * memchr(const void *, int, __kernel_size_t);
29
30 #define __HAVE_ARCH_MEMSET
31 extern void * memset(void *, int, __kernel_size_t);
32 extern void *__memset(void *s, int c, __kernel_size_t n);
33
34 #define __HAVE_ARCH_MEMSET32
35 extern void *__memset32(uint32_t *, uint32_t v, __kernel_size_t);
memset32(uint32_t * p,uint32_t v,__kernel_size_t n)36 static inline void *memset32(uint32_t *p, uint32_t v, __kernel_size_t n)
37 {
38 return __memset32(p, v, n * 4);
39 }
40
41 #define __HAVE_ARCH_MEMSET64
42 extern void *__memset64(uint64_t *, uint32_t low, __kernel_size_t, uint32_t hi);
memset64(uint64_t * p,uint64_t v,__kernel_size_t n)43 static inline void *memset64(uint64_t *p, uint64_t v, __kernel_size_t n)
44 {
45 return __memset64(p, v, n * 8, v >> 32);
46 }
47
48 /*
49 * For files that are not instrumented (e.g. mm/slub.c) we
50 * must use non-instrumented versions of the mem*
51 * functions named __memcpy() etc. All such kernel code has
52 * been tagged with KASAN_SANITIZE_file.o = n, which means
53 * that the address sanitization argument isn't passed to the
54 * compiler, and __SANITIZE_ADDRESS__ is not set. As a result
55 * these defines kick in.
56 */
57 #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
58 #define memcpy(dst, src, len) __memcpy(dst, src, len)
59 #define memmove(dst, src, len) __memmove(dst, src, len)
60 #define memset(s, c, n) __memset(s, c, n)
61
62 #ifndef __NO_FORTIFY
63 #define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
64 #endif
65
66 #endif
67
68 #endif
69