1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_STRING_H
3b8b572e1SStephen Rothwell #define _ASM_POWERPC_STRING_H
4b8b572e1SStephen Rothwell
5b8b572e1SStephen Rothwell #ifdef __KERNEL__
6b8b572e1SStephen Rothwell
726deb043SChristophe Leroy #ifndef CONFIG_KASAN
8b8b572e1SStephen Rothwell #define __HAVE_ARCH_STRNCPY
9b8b572e1SStephen Rothwell #define __HAVE_ARCH_STRNCMP
1026deb043SChristophe Leroy #define __HAVE_ARCH_MEMCHR
1126deb043SChristophe Leroy #define __HAVE_ARCH_MEMCMP
1226deb043SChristophe Leroy #define __HAVE_ARCH_MEMSET16
1326deb043SChristophe Leroy #endif
1426deb043SChristophe Leroy
15b8b572e1SStephen Rothwell #define __HAVE_ARCH_MEMSET
16b8b572e1SStephen Rothwell #define __HAVE_ARCH_MEMCPY
17b8b572e1SStephen Rothwell #define __HAVE_ARCH_MEMMOVE
186c44741dSOliver O'Halloran #define __HAVE_ARCH_MEMCPY_FLUSHCACHE
19b8b572e1SStephen Rothwell
20b8b572e1SStephen Rothwell extern char * strcpy(char *,const char *);
21b8b572e1SStephen Rothwell extern char * strncpy(char *,const char *, __kernel_size_t);
22b8b572e1SStephen Rothwell extern __kernel_size_t strlen(const char *);
23b8b572e1SStephen Rothwell extern int strcmp(const char *,const char *);
24b8b572e1SStephen Rothwell extern int strncmp(const char *, const char *, __kernel_size_t);
25b8b572e1SStephen Rothwell extern char * strcat(char *, const char *);
26b8b572e1SStephen Rothwell extern void * memset(void *,int,__kernel_size_t);
27b8b572e1SStephen Rothwell extern void * memcpy(void *,const void *,__kernel_size_t);
28b8b572e1SStephen Rothwell extern void * memmove(void *,const void *,__kernel_size_t);
29b8b572e1SStephen Rothwell extern int memcmp(const void *,const void *,__kernel_size_t);
30b8b572e1SStephen Rothwell extern void * memchr(const void *,int,__kernel_size_t);
31e2802618SLi RongQing void memcpy_flushcache(void *dest, const void *src, size_t size);
32b8b572e1SStephen Rothwell
33*90db9dbeSMarco Elver #ifdef CONFIG_KASAN
34*90db9dbeSMarco Elver /* __mem variants are used by KASAN to implement instrumented meminstrinsics. */
35*90db9dbeSMarco Elver #ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
36*90db9dbeSMarco Elver #define __memset memset
37*90db9dbeSMarco Elver #define __memcpy memcpy
38*90db9dbeSMarco Elver #define __memmove memmove
39*90db9dbeSMarco Elver #else /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
4026deb043SChristophe Leroy void *__memset(void *s, int c, __kernel_size_t count);
4126deb043SChristophe Leroy void *__memcpy(void *to, const void *from, __kernel_size_t n);
4226deb043SChristophe Leroy void *__memmove(void *to, const void *from, __kernel_size_t n);
43*90db9dbeSMarco Elver #ifndef __SANITIZE_ADDRESS__
4426deb043SChristophe Leroy /*
4526deb043SChristophe Leroy * For files that are not instrumented (e.g. mm/slub.c) we
4626deb043SChristophe Leroy * should use not instrumented version of mem* functions.
4726deb043SChristophe Leroy */
4826deb043SChristophe Leroy #define memcpy(dst, src, len) __memcpy(dst, src, len)
4926deb043SChristophe Leroy #define memmove(dst, src, len) __memmove(dst, src, len)
5026deb043SChristophe Leroy #define memset(s, c, n) __memset(s, c, n)
5126deb043SChristophe Leroy
5226deb043SChristophe Leroy #ifndef __NO_FORTIFY
5326deb043SChristophe Leroy #define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
5426deb043SChristophe Leroy #endif
55*90db9dbeSMarco Elver #endif /* !__SANITIZE_ADDRESS__ */
56*90db9dbeSMarco Elver #endif /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
57*90db9dbeSMarco Elver #endif /* CONFIG_KASAN */
5826deb043SChristophe Leroy
59694fc88cSNaveen N. Rao #ifdef CONFIG_PPC64
6026deb043SChristophe Leroy #ifndef CONFIG_KASAN
61694fc88cSNaveen N. Rao #define __HAVE_ARCH_MEMSET32
62694fc88cSNaveen N. Rao #define __HAVE_ARCH_MEMSET64
63694fc88cSNaveen N. Rao
64694fc88cSNaveen N. Rao extern void *__memset16(uint16_t *, uint16_t v, __kernel_size_t);
65694fc88cSNaveen N. Rao extern void *__memset32(uint32_t *, uint32_t v, __kernel_size_t);
66694fc88cSNaveen N. Rao extern void *__memset64(uint64_t *, uint64_t v, __kernel_size_t);
67694fc88cSNaveen N. Rao
memset16(uint16_t * p,uint16_t v,__kernel_size_t n)68694fc88cSNaveen N. Rao static inline void *memset16(uint16_t *p, uint16_t v, __kernel_size_t n)
69694fc88cSNaveen N. Rao {
70694fc88cSNaveen N. Rao return __memset16(p, v, n * 2);
71694fc88cSNaveen N. Rao }
72694fc88cSNaveen N. Rao
memset32(uint32_t * p,uint32_t v,__kernel_size_t n)73694fc88cSNaveen N. Rao static inline void *memset32(uint32_t *p, uint32_t v, __kernel_size_t n)
74694fc88cSNaveen N. Rao {
75694fc88cSNaveen N. Rao return __memset32(p, v, n * 4);
76694fc88cSNaveen N. Rao }
77694fc88cSNaveen N. Rao
memset64(uint64_t * p,uint64_t v,__kernel_size_t n)78694fc88cSNaveen N. Rao static inline void *memset64(uint64_t *p, uint64_t v, __kernel_size_t n)
79694fc88cSNaveen N. Rao {
80694fc88cSNaveen N. Rao return __memset64(p, v, n * 8);
81694fc88cSNaveen N. Rao }
8226deb043SChristophe Leroy #endif
83da74f659SChristophe Leroy #else
8426deb043SChristophe Leroy #ifndef CONFIG_KASAN
859412b234SChristophe Leroy #define __HAVE_ARCH_STRLEN
8626deb043SChristophe Leroy #endif
879412b234SChristophe Leroy
88da74f659SChristophe Leroy extern void *memset16(uint16_t *, uint16_t, __kernel_size_t);
89694fc88cSNaveen N. Rao #endif
90b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
91b8b572e1SStephen Rothwell
92b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_STRING_H */
93