blob: f00c15c412354e523a477b4e0e37bbf68eb5de8f [file] [log] [blame]
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -08001#ifndef _LINUX_KASAN_H
2#define _LINUX_KASAN_H
3
4#include <linux/types.h>
5
6struct kmem_cache;
7struct page;
8
9#ifdef CONFIG_KASAN
10
11#define KASAN_SHADOW_SCALE_SHIFT 3
12#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
13
14#include <asm/kasan.h>
15#include <linux/sched.h>
16
17static inline void *kasan_mem_to_shadow(const void *addr)
18{
19 return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT)
20 + KASAN_SHADOW_OFFSET;
21}
22
23/* Enable reporting bugs after kasan_disable_current() */
24static inline void kasan_enable_current(void)
25{
26 current->kasan_depth++;
27}
28
29/* Disable reporting bugs for current task */
30static inline void kasan_disable_current(void)
31{
32 current->kasan_depth--;
33}
34
35void kasan_unpoison_shadow(const void *address, size_t size);
36
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080037void kasan_alloc_pages(struct page *page, unsigned int order);
38void kasan_free_pages(struct page *page, unsigned int order);
39
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080040#else /* CONFIG_KASAN */
41
42static inline void kasan_unpoison_shadow(const void *address, size_t size) {}
43
44static inline void kasan_enable_current(void) {}
45static inline void kasan_disable_current(void) {}
46
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080047static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
48static inline void kasan_free_pages(struct page *page, unsigned int order) {}
49
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080050#endif /* CONFIG_KASAN */
51
52#endif /* LINUX_KASAN_H */