1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright IBM Corp. 1999
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 #ifndef _S390_STRING_H_
9 #define _S390_STRING_H_
11 #ifndef _LINUX_TYPES_H
12 #include <linux/types.h>
15 #define __HAVE_ARCH_MEMCPY /* gcc builtin & arch function */
16 #define __HAVE_ARCH_MEMMOVE /* gcc builtin & arch function */
17 #define __HAVE_ARCH_MEMSET /* gcc builtin & arch function */
18 #define __HAVE_ARCH_MEMSET16 /* arch function */
19 #define __HAVE_ARCH_MEMSET32 /* arch function */
20 #define __HAVE_ARCH_MEMSET64 /* arch function */
22 void *memcpy(void *dest
, const void *src
, size_t n
);
23 void *memset(void *s
, int c
, size_t n
);
24 void *memmove(void *dest
, const void *src
, size_t n
);
27 #define __HAVE_ARCH_MEMCHR /* inline & arch function */
28 #define __HAVE_ARCH_MEMCMP /* arch function */
29 #define __HAVE_ARCH_MEMSCAN /* inline & arch function */
30 #define __HAVE_ARCH_STRCAT /* inline & arch function */
31 #define __HAVE_ARCH_STRCMP /* arch function */
32 #define __HAVE_ARCH_STRCPY /* inline & arch function */
33 #define __HAVE_ARCH_STRLCAT /* arch function */
34 #define __HAVE_ARCH_STRLCPY /* arch function */
35 #define __HAVE_ARCH_STRLEN /* inline & arch function */
36 #define __HAVE_ARCH_STRNCAT /* arch function */
37 #define __HAVE_ARCH_STRNCPY /* arch function */
38 #define __HAVE_ARCH_STRNLEN /* inline & arch function */
39 #define __HAVE_ARCH_STRRCHR /* arch function */
40 #define __HAVE_ARCH_STRSTR /* arch function */
42 /* Prototypes for non-inlined arch strings functions. */
43 int memcmp(const void *s1
, const void *s2
, size_t n
);
44 int strcmp(const char *s1
, const char *s2
);
45 size_t strlcat(char *dest
, const char *src
, size_t n
);
46 size_t strlcpy(char *dest
, const char *src
, size_t size
);
47 char *strncat(char *dest
, const char *src
, size_t n
);
48 char *strncpy(char *dest
, const char *src
, size_t n
);
49 char *strrchr(const char *s
, int c
);
50 char *strstr(const char *s1
, const char *s2
);
51 #endif /* !CONFIG_KASAN */
53 #undef __HAVE_ARCH_STRCHR
54 #undef __HAVE_ARCH_STRNCHR
55 #undef __HAVE_ARCH_STRNCMP
56 #undef __HAVE_ARCH_STRPBRK
57 #undef __HAVE_ARCH_STRSEP
58 #undef __HAVE_ARCH_STRSPN
60 #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
62 extern void *__memcpy(void *dest
, const void *src
, size_t n
);
63 extern void *__memset(void *s
, int c
, size_t n
);
64 extern void *__memmove(void *dest
, const void *src
, size_t n
);
67 * For files that are not instrumented (e.g. mm/slub.c) we
68 * should use not instrumented version of mem* functions.
71 #define memcpy(dst, src, len) __memcpy(dst, src, len)
72 #define memmove(dst, src, len) __memmove(dst, src, len)
73 #define memset(s, c, n) __memset(s, c, n)
76 #define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
79 #endif /* defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) */
81 void *__memset16(uint16_t *s
, uint16_t v
, size_t count
);
82 void *__memset32(uint32_t *s
, uint32_t v
, size_t count
);
83 void *__memset64(uint64_t *s
, uint64_t v
, size_t count
);
85 static inline void *memset16(uint16_t *s
, uint16_t v
, size_t count
)
87 return __memset16(s
, v
, count
* sizeof(v
));
90 static inline void *memset32(uint32_t *s
, uint32_t v
, size_t count
)
92 return __memset32(s
, v
, count
* sizeof(v
));
95 static inline void *memset64(uint64_t *s
, uint64_t v
, size_t count
)
97 return __memset64(s
, v
, count
* sizeof(v
));
100 #if !defined(IN_ARCH_STRING_C) && (!defined(CONFIG_FORTIFY_SOURCE) || defined(__NO_FORTIFY))
102 #ifdef __HAVE_ARCH_MEMCHR
103 static inline void *memchr(const void * s
, int c
, size_t n
)
105 register int r0
asm("0") = (char) c
;
106 const void *ret
= s
+ n
;
114 : "+a" (ret
), "+&a" (s
) : "d" (r0
) : "cc", "memory");
119 #ifdef __HAVE_ARCH_MEMSCAN
120 static inline void *memscan(void *s
, int c
, size_t n
)
122 register int r0
asm("0") = (char) c
;
123 const void *ret
= s
+ n
;
128 : "+a" (ret
), "+&a" (s
) : "d" (r0
) : "cc", "memory");
133 #ifdef __HAVE_ARCH_STRCAT
134 static inline char *strcat(char *dst
, const char *src
)
136 register int r0
asm("0") = 0;
145 : "=&a" (dummy
), "+a" (dst
), "+a" (src
)
146 : "d" (r0
), "0" (0) : "cc", "memory" );
151 #ifdef __HAVE_ARCH_STRCPY
152 static inline char *strcpy(char *dst
, const char *src
)
154 register int r0
asm("0") = 0;
160 : "+&a" (dst
), "+&a" (src
) : "d" (r0
)
166 #ifdef __HAVE_ARCH_STRLEN
167 static inline size_t strlen(const char *s
)
169 register unsigned long r0
asm("0") = 0;
175 : "+d" (r0
), "+a" (tmp
) : : "cc", "memory");
176 return r0
- (unsigned long) s
;
180 #ifdef __HAVE_ARCH_STRNLEN
181 static inline size_t strnlen(const char * s
, size_t n
)
183 register int r0
asm("0") = 0;
185 const char *end
= s
+ n
;
190 : "+a" (end
), "+a" (tmp
) : "d" (r0
) : "cc", "memory");
194 #else /* IN_ARCH_STRING_C */
195 void *memchr(const void * s
, int c
, size_t n
);
196 void *memscan(void *s
, int c
, size_t n
);
197 char *strcat(char *dst
, const char *src
);
198 char *strcpy(char *dst
, const char *src
);
199 size_t strlen(const char *s
);
200 size_t strnlen(const char * s
, size_t n
);
201 #endif /* !IN_ARCH_STRING_C */
203 #endif /* __S390_STRING_H_ */