.. | .. |
---|
2 | 2 | #ifndef _LINUX_STRING_H_ |
---|
3 | 3 | #define _LINUX_STRING_H_ |
---|
4 | 4 | |
---|
5 | | - |
---|
6 | 5 | #include <linux/compiler.h> /* for inline */ |
---|
7 | 6 | #include <linux/types.h> /* for size_t */ |
---|
8 | 7 | #include <linux/stddef.h> /* for NULL */ |
---|
.. | .. |
---|
62 | 61 | #ifndef __HAVE_ARCH_STRCHRNUL |
---|
63 | 62 | extern char * strchrnul(const char *,int); |
---|
64 | 63 | #endif |
---|
| 64 | +extern char * strnchrnul(const char *, size_t, int); |
---|
65 | 65 | #ifndef __HAVE_ARCH_STRNCHR |
---|
66 | 66 | extern char * strnchr(const char *, size_t, int); |
---|
67 | 67 | #endif |
---|
.. | .. |
---|
135 | 135 | return memset64((uint64_t *)p, (uintptr_t)v, n); |
---|
136 | 136 | } |
---|
137 | 137 | |
---|
| 138 | +extern void **__memcat_p(void **a, void **b); |
---|
| 139 | +#define memcat_p(a, b) ({ \ |
---|
| 140 | + BUILD_BUG_ON_MSG(!__same_type(*(a), *(b)), \ |
---|
| 141 | + "type mismatch in memcat_p()"); \ |
---|
| 142 | + (typeof(*a) *)__memcat_p((void **)(a), (void **)(b)); \ |
---|
| 143 | +}) |
---|
| 144 | + |
---|
138 | 145 | #ifndef __HAVE_ARCH_MEMCPY |
---|
139 | 146 | extern void * memcpy(void *,const void *,__kernel_size_t); |
---|
140 | 147 | #endif |
---|
.. | .. |
---|
153 | 160 | #ifndef __HAVE_ARCH_MEMCHR |
---|
154 | 161 | extern void * memchr(const void *,int,__kernel_size_t); |
---|
155 | 162 | #endif |
---|
156 | | -#ifndef __HAVE_ARCH_MEMCPY_MCSAFE |
---|
157 | | -static inline __must_check unsigned long memcpy_mcsafe(void *dst, |
---|
158 | | - const void *src, size_t cnt) |
---|
159 | | -{ |
---|
160 | | - memcpy(dst, src, cnt); |
---|
161 | | - return 0; |
---|
162 | | -} |
---|
163 | | -#endif |
---|
164 | 163 | #ifndef __HAVE_ARCH_MEMCPY_FLUSHCACHE |
---|
165 | 164 | static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt) |
---|
166 | 165 | { |
---|
167 | 166 | memcpy(dst, src, cnt); |
---|
168 | 167 | } |
---|
169 | 168 | #endif |
---|
| 169 | + |
---|
170 | 170 | void *memchr_inv(const void *s, int c, size_t n); |
---|
171 | 171 | char *strreplace(char *s, char old, char new); |
---|
172 | 172 | |
---|
.. | .. |
---|
182 | 182 | extern void argv_free(char **argv); |
---|
183 | 183 | |
---|
184 | 184 | extern bool sysfs_streq(const char *s1, const char *s2); |
---|
185 | | -extern int kstrtobool(const char *s, bool *res); |
---|
186 | | -static inline int strtobool(const char *s, bool *res) |
---|
187 | | -{ |
---|
188 | | - return kstrtobool(s, res); |
---|
189 | | -} |
---|
190 | | - |
---|
191 | 185 | int match_string(const char * const *array, size_t n, const char *string); |
---|
192 | 186 | int __sysfs_match_string(const char * const *array, size_t n, const char *s); |
---|
193 | 187 | |
---|
.. | .. |
---|
222 | 216 | } |
---|
223 | 217 | |
---|
224 | 218 | size_t memweight(const void *ptr, size_t bytes); |
---|
225 | | -void memzero_explicit(void *s, size_t count); |
---|
| 219 | + |
---|
| 220 | +/** |
---|
| 221 | + * memzero_explicit - Fill a region of memory (e.g. sensitive |
---|
| 222 | + * keying data) with 0s. |
---|
| 223 | + * @s: Pointer to the start of the area. |
---|
| 224 | + * @count: The size of the area. |
---|
| 225 | + * |
---|
| 226 | + * Note: usually using memset() is just fine (!), but in cases |
---|
| 227 | + * where clearing out _local_ data at the end of a scope is |
---|
| 228 | + * necessary, memzero_explicit() should be used instead in |
---|
| 229 | + * order to prevent the compiler from optimising away zeroing. |
---|
| 230 | + * |
---|
| 231 | + * memzero_explicit() doesn't need an arch-specific version as |
---|
| 232 | + * it just invokes the one of memset() implicitly. |
---|
| 233 | + */ |
---|
| 234 | +static inline void memzero_explicit(void *s, size_t count) |
---|
| 235 | +{ |
---|
| 236 | + memset(s, 0, count); |
---|
| 237 | + barrier_data(s); |
---|
| 238 | +} |
---|
226 | 239 | |
---|
227 | 240 | /** |
---|
228 | 241 | * kbasename - return the last part of a pathname. |
---|
.. | .. |
---|
246 | 259 | |
---|
247 | 260 | #if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE) |
---|
248 | 261 | |
---|
249 | | -#ifdef CONFIG_KASAN |
---|
| 262 | +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) |
---|
250 | 263 | extern void *__underlying_memchr(const void *p, int c, __kernel_size_t size) __RENAME(memchr); |
---|
251 | 264 | extern int __underlying_memcmp(const void *p, const void *q, __kernel_size_t size) __RENAME(memcmp); |
---|
252 | 265 | extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t size) __RENAME(memcpy); |
---|
.. | .. |
---|
494 | 507 | memcpy(dest, src, dest_len); |
---|
495 | 508 | } |
---|
496 | 509 | |
---|
| 510 | +/** |
---|
| 511 | + * str_has_prefix - Test if a string has a given prefix |
---|
| 512 | + * @str: The string to test |
---|
| 513 | + * @prefix: The string to see if @str starts with |
---|
| 514 | + * |
---|
| 515 | + * A common way to test a prefix of a string is to do: |
---|
| 516 | + * strncmp(str, prefix, sizeof(prefix) - 1) |
---|
| 517 | + * |
---|
| 518 | + * But this can lead to bugs due to typos, or if prefix is a pointer |
---|
| 519 | + * and not a constant. Instead use str_has_prefix(). |
---|
| 520 | + * |
---|
| 521 | + * Returns: |
---|
| 522 | + * * strlen(@prefix) if @str starts with @prefix |
---|
| 523 | + * * 0 if @str does not start with @prefix |
---|
| 524 | + */ |
---|
| 525 | +static __always_inline size_t str_has_prefix(const char *str, const char *prefix) |
---|
| 526 | +{ |
---|
| 527 | + size_t len = strlen(prefix); |
---|
| 528 | + return strncmp(str, prefix, len) == 0 ? len : 0; |
---|
| 529 | +} |
---|
| 530 | + |
---|
497 | 531 | #endif /* _LINUX_STRING_H_ */ |
---|