1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2016, Linaro Limited 4 * All rights reserved. 5 */ 6 #ifndef __KERNEL_ASAN_H 7 #define __KERNEL_ASAN_H 8 9 10 #define ASAN_DATA_RED_ZONE -1 11 #define ASAN_HEAP_RED_ZONE -2 12 13 #define ASAN_BLOCK_SIZE 8 14 #define ASAN_BLOCK_SHIFT 3 15 #define ASAN_BLOCK_MASK (ASAN_BLOCK_SIZE - 1) 16 17 #ifndef ASM 18 #include <string.h> 19 #include <types_ext.h> 20 21 void asan_set_shadowed(const void *va_begin, const void *va_end); 22 void asan_start(void); 23 24 #ifdef CFG_CORE_SANITIZE_KADDRESS 25 void asan_tag_no_access(const void *begin, const void *end); 26 void asan_tag_access(const void *begin, const void *end); 27 void asan_tag_heap_free(const void *begin, const void *end); 28 void *asan_memset_unchecked(void *s, int c, size_t n); 29 void *asan_memcpy_unchecked(void *__restrict s1, const void *__restrict s2, 30 size_t n); 31 #else 32 static inline void asan_tag_no_access(const void *begin __unused, 33 const void *end __unused) 34 { 35 } 36 static inline void asan_tag_access(const void *begin __unused, 37 const void *end __unused) 38 { 39 } 40 static inline void asan_tag_heap_free(const void *begin __unused, 41 const void *end __unused) 42 { 43 } 44 45 static inline void *asan_memset_unchecked(void *s, int c, size_t n) 46 { 47 return memset(s, c, n); 48 } 49 50 static inline void *asan_memcpy_unchecked(void *__restrict s1, 51 const void *__restrict s2, size_t n) 52 { 53 return memcpy(s1, s2, n); 54 } 55 56 #endif 57 58 #endif /*ASM*/ 59 #endif /*__KERNEL_ASAN_H*/ 60