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