18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_STRING_64_H 38c2ecf20Sopenharmony_ci#define _ASM_X86_STRING_64_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 68c2ecf20Sopenharmony_ci#include <linux/jump_label.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* Written 2002 by Andi Kleen */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* Even with __builtin_ the compiler may decide to use the out of line 118c2ecf20Sopenharmony_ci function. */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMCPY 1 148c2ecf20Sopenharmony_ciextern void *memcpy(void *to, const void *from, size_t len); 158c2ecf20Sopenharmony_ciextern void *__memcpy(void *to, const void *from, size_t len); 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMSET 188c2ecf20Sopenharmony_civoid *memset(void *s, int c, size_t n); 198c2ecf20Sopenharmony_civoid *__memset(void *s, int c, size_t n); 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMSET16 228c2ecf20Sopenharmony_cistatic inline void *memset16(uint16_t *s, uint16_t v, size_t n) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci long d0, d1; 258c2ecf20Sopenharmony_ci asm volatile("rep\n\t" 268c2ecf20Sopenharmony_ci "stosw" 278c2ecf20Sopenharmony_ci : "=&c" (d0), "=&D" (d1) 288c2ecf20Sopenharmony_ci : "a" (v), "1" (s), "0" (n) 298c2ecf20Sopenharmony_ci : "memory"); 308c2ecf20Sopenharmony_ci return s; 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMSET32 348c2ecf20Sopenharmony_cistatic inline void *memset32(uint32_t *s, uint32_t v, size_t n) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci long d0, d1; 378c2ecf20Sopenharmony_ci asm volatile("rep\n\t" 388c2ecf20Sopenharmony_ci "stosl" 398c2ecf20Sopenharmony_ci : "=&c" (d0), "=&D" (d1) 408c2ecf20Sopenharmony_ci : "a" (v), "1" (s), "0" (n) 418c2ecf20Sopenharmony_ci : "memory"); 428c2ecf20Sopenharmony_ci return s; 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMSET64 468c2ecf20Sopenharmony_cistatic inline void *memset64(uint64_t *s, uint64_t v, size_t n) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci long d0, d1; 498c2ecf20Sopenharmony_ci asm volatile("rep\n\t" 508c2ecf20Sopenharmony_ci "stosq" 518c2ecf20Sopenharmony_ci : "=&c" (d0), "=&D" (d1) 528c2ecf20Sopenharmony_ci : "a" (v), "1" (s), "0" (n) 538c2ecf20Sopenharmony_ci : "memory"); 548c2ecf20Sopenharmony_ci return s; 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMMOVE 588c2ecf20Sopenharmony_civoid *memmove(void *dest, const void *src, size_t count); 598c2ecf20Sopenharmony_civoid *__memmove(void *dest, const void *src, size_t count); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciint memcmp(const void *cs, const void *ct, size_t count); 628c2ecf20Sopenharmony_cisize_t strlen(const char *s); 638c2ecf20Sopenharmony_cichar *strcpy(char *dest, const char *src); 648c2ecf20Sopenharmony_cichar *strcat(char *dest, const char *src); 658c2ecf20Sopenharmony_ciint strcmp(const char *cs, const char *ct); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* 708c2ecf20Sopenharmony_ci * For files that not instrumented (e.g. mm/slub.c) we 718c2ecf20Sopenharmony_ci * should use not instrumented version of mem* functions. 728c2ecf20Sopenharmony_ci */ 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#undef memcpy 758c2ecf20Sopenharmony_ci#define memcpy(dst, src, len) __memcpy(dst, src, len) 768c2ecf20Sopenharmony_ci#define memmove(dst, src, len) __memmove(dst, src, len) 778c2ecf20Sopenharmony_ci#define memset(s, c, n) __memset(s, c, n) 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#ifndef __NO_FORTIFY 808c2ecf20Sopenharmony_ci#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */ 818c2ecf20Sopenharmony_ci#endif 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#endif 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE 868c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMCPY_FLUSHCACHE 1 878c2ecf20Sopenharmony_civoid __memcpy_flushcache(void *dst, const void *src, size_t cnt); 888c2ecf20Sopenharmony_cistatic __always_inline void memcpy_flushcache(void *dst, const void *src, size_t cnt) 898c2ecf20Sopenharmony_ci{ 908c2ecf20Sopenharmony_ci if (__builtin_constant_p(cnt)) { 918c2ecf20Sopenharmony_ci switch (cnt) { 928c2ecf20Sopenharmony_ci case 4: 938c2ecf20Sopenharmony_ci asm ("movntil %1, %0" : "=m"(*(u32 *)dst) : "r"(*(u32 *)src)); 948c2ecf20Sopenharmony_ci return; 958c2ecf20Sopenharmony_ci case 8: 968c2ecf20Sopenharmony_ci asm ("movntiq %1, %0" : "=m"(*(u64 *)dst) : "r"(*(u64 *)src)); 978c2ecf20Sopenharmony_ci return; 988c2ecf20Sopenharmony_ci case 16: 998c2ecf20Sopenharmony_ci asm ("movntiq %1, %0" : "=m"(*(u64 *)dst) : "r"(*(u64 *)src)); 1008c2ecf20Sopenharmony_ci asm ("movntiq %1, %0" : "=m"(*(u64 *)(dst + 8)) : "r"(*(u64 *)(src + 8))); 1018c2ecf20Sopenharmony_ci return; 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci } 1048c2ecf20Sopenharmony_ci __memcpy_flushcache(dst, src, cnt); 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci#endif 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */ 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci#endif /* _ASM_X86_STRING_64_H */ 111