Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 1 | #ifndef _LINUX_KASAN_H |
| 2 | #define _LINUX_KASAN_H |
| 3 | |
| 4 | #include <linux/types.h> |
| 5 | |
| 6 | struct kmem_cache; |
| 7 | struct 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 | |
| 17 | static 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() */ |
| 24 | static inline void kasan_enable_current(void) |
| 25 | { |
| 26 | current->kasan_depth++; |
| 27 | } |
| 28 | |
| 29 | /* Disable reporting bugs for current task */ |
| 30 | static inline void kasan_disable_current(void) |
| 31 | { |
| 32 | current->kasan_depth--; |
| 33 | } |
| 34 | |
| 35 | void kasan_unpoison_shadow(const void *address, size_t size); |
| 36 | |
Andrey Ryabinin | b8c73fc | 2015-02-13 14:39:28 -0800 | [diff] [blame^] | 37 | void kasan_alloc_pages(struct page *page, unsigned int order); |
| 38 | void kasan_free_pages(struct page *page, unsigned int order); |
| 39 | |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 40 | #else /* CONFIG_KASAN */ |
| 41 | |
| 42 | static inline void kasan_unpoison_shadow(const void *address, size_t size) {} |
| 43 | |
| 44 | static inline void kasan_enable_current(void) {} |
| 45 | static inline void kasan_disable_current(void) {} |
| 46 | |
Andrey Ryabinin | b8c73fc | 2015-02-13 14:39:28 -0800 | [diff] [blame^] | 47 | static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} |
| 48 | static inline void kasan_free_pages(struct page *page, unsigned int order) {} |
| 49 | |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 50 | #endif /* CONFIG_KASAN */ |
| 51 | |
| 52 | #endif /* LINUX_KASAN_H */ |