xref: /openbmc/linux/arch/powerpc/include/asm/string.h (revision 50df3be7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_STRING_H
3 #define _ASM_POWERPC_STRING_H
4 
5 #ifdef __KERNEL__
6 
7 #ifndef CONFIG_KASAN
8 #define __HAVE_ARCH_STRNCPY
9 #define __HAVE_ARCH_STRNCMP
10 #define __HAVE_ARCH_MEMCHR
11 #define __HAVE_ARCH_MEMCMP
12 #define __HAVE_ARCH_MEMSET16
13 #endif
14 
15 #define __HAVE_ARCH_MEMSET
16 #define __HAVE_ARCH_MEMCPY
17 #define __HAVE_ARCH_MEMMOVE
18 #define __HAVE_ARCH_MEMCPY_FLUSHCACHE
19 
20 extern char * strcpy(char *,const char *);
21 extern char * strncpy(char *,const char *, __kernel_size_t);
22 extern __kernel_size_t strlen(const char *);
23 extern int strcmp(const char *,const char *);
24 extern int strncmp(const char *, const char *, __kernel_size_t);
25 extern char * strcat(char *, const char *);
26 extern void * memset(void *,int,__kernel_size_t);
27 extern void * memcpy(void *,const void *,__kernel_size_t);
28 extern void * memmove(void *,const void *,__kernel_size_t);
29 extern int memcmp(const void *,const void *,__kernel_size_t);
30 extern void * memchr(const void *,int,__kernel_size_t);
31 extern void * memcpy_flushcache(void *,const void *,__kernel_size_t);
32 
33 void *__memset(void *s, int c, __kernel_size_t count);
34 void *__memcpy(void *to, const void *from, __kernel_size_t n);
35 void *__memmove(void *to, const void *from, __kernel_size_t n);
36 
37 #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
38 /*
39  * For files that are not instrumented (e.g. mm/slub.c) we
40  * should use not instrumented version of mem* functions.
41  */
42 #define memcpy(dst, src, len) __memcpy(dst, src, len)
43 #define memmove(dst, src, len) __memmove(dst, src, len)
44 #define memset(s, c, n) __memset(s, c, n)
45 
46 #ifndef __NO_FORTIFY
47 #define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
48 #endif
49 
50 #endif
51 
52 #ifdef CONFIG_PPC64
53 #ifndef CONFIG_KASAN
54 #define __HAVE_ARCH_MEMSET32
55 #define __HAVE_ARCH_MEMSET64
56 #define __HAVE_ARCH_MEMCPY_MCSAFE
57 
58 extern int memcpy_mcsafe(void *dst, const void *src, __kernel_size_t sz);
59 extern void *__memset16(uint16_t *, uint16_t v, __kernel_size_t);
60 extern void *__memset32(uint32_t *, uint32_t v, __kernel_size_t);
61 extern void *__memset64(uint64_t *, uint64_t v, __kernel_size_t);
62 
63 static inline void *memset16(uint16_t *p, uint16_t v, __kernel_size_t n)
64 {
65 	return __memset16(p, v, n * 2);
66 }
67 
68 static inline void *memset32(uint32_t *p, uint32_t v, __kernel_size_t n)
69 {
70 	return __memset32(p, v, n * 4);
71 }
72 
73 static inline void *memset64(uint64_t *p, uint64_t v, __kernel_size_t n)
74 {
75 	return __memset64(p, v, n * 8);
76 }
77 #endif
78 #else
79 #ifndef CONFIG_KASAN
80 #define __HAVE_ARCH_STRLEN
81 #endif
82 
83 extern void *memset16(uint16_t *, uint16_t, __kernel_size_t);
84 #endif
85 #endif /* __KERNEL__ */
86 
87 #endif	/* _ASM_POWERPC_STRING_H */
88