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