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 void asan_set_shadowed(const void *va_begin, const void *va_end);
23 void asan_start(void);
24 
25 #ifdef CFG_CORE_SANITIZE_KADDRESS
26 void asan_tag_no_access(const void *begin, const void *end);
27 void asan_tag_access(const void *begin, const void *end);
28 void asan_tag_heap_free(const void *begin, const void *end);
29 void *asan_memset_unchecked(void *s, int c, size_t n);
30 void *asan_memcpy_unchecked(void *__restrict s1, const void *__restrict s2,
31 			    size_t n);
32 #else
asan_tag_no_access(const void * begin __unused,const void * end __unused)33 static inline void asan_tag_no_access(const void *begin __unused,
34 				      const void *end __unused)
35 {
36 }
asan_tag_access(const void * begin __unused,const void * end __unused)37 static inline void asan_tag_access(const void *begin __unused,
38 				   const void *end __unused)
39 {
40 }
asan_tag_heap_free(const void * begin __unused,const void * end __unused)41 static inline void asan_tag_heap_free(const void *begin __unused,
42 				      const void *end __unused)
43 {
44 }
45 
asan_memset_unchecked(void * s,int c,size_t n)46 static inline void *asan_memset_unchecked(void *s, int c, size_t n)
47 {
48 	return memset(s, c, n);
49 }
50 
asan_memcpy_unchecked(void * __restrict s1,const void * __restrict s2,size_t n)51 static inline void *asan_memcpy_unchecked(void *__restrict s1,
52 					  const void *__restrict s2, size_t n)
53 {
54 	return memcpy(s1, s2, n);
55 }
56 
57 #endif
58 
59 #endif /*__ASSEMBLER__*/
60 #endif /*__KERNEL_ASAN_H*/
61