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 | 0316bec | 2015-02-13 14:39:42 -0800 | [diff] [blame] | 40 | void kasan_poison_slab(struct page *page); |
| 41 | void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); |
| 42 | void kasan_poison_object_data(struct kmem_cache *cache, void *object); |
| 43 | |
| 44 | void kasan_kmalloc_large(const void *ptr, size_t size); |
| 45 | void kasan_kfree_large(const void *ptr); |
| 46 | void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size); |
| 47 | void kasan_krealloc(const void *object, size_t new_size); |
| 48 | |
| 49 | void kasan_slab_alloc(struct kmem_cache *s, void *object); |
| 50 | void kasan_slab_free(struct kmem_cache *s, void *object); |
| 51 | |
Andrey Ryabinin | bebf56a | 2015-02-13 14:40:17 -0800 | [diff] [blame] | 52 | #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) |
| 53 | |
| 54 | int kasan_module_alloc(void *addr, size_t size); |
| 55 | void kasan_module_free(void *addr); |
| 56 | |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 57 | #else /* CONFIG_KASAN */ |
| 58 | |
Andrey Ryabinin | bebf56a | 2015-02-13 14:40:17 -0800 | [diff] [blame] | 59 | #define MODULE_ALIGN 1 |
| 60 | |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 61 | static inline void kasan_unpoison_shadow(const void *address, size_t size) {} |
| 62 | |
| 63 | static inline void kasan_enable_current(void) {} |
| 64 | static inline void kasan_disable_current(void) {} |
| 65 | |
Andrey Ryabinin | b8c73fc | 2015-02-13 14:39:28 -0800 | [diff] [blame] | 66 | static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} |
| 67 | static inline void kasan_free_pages(struct page *page, unsigned int order) {} |
| 68 | |
Andrey Ryabinin | 0316bec | 2015-02-13 14:39:42 -0800 | [diff] [blame] | 69 | static inline void kasan_poison_slab(struct page *page) {} |
| 70 | static inline void kasan_unpoison_object_data(struct kmem_cache *cache, |
| 71 | void *object) {} |
| 72 | static inline void kasan_poison_object_data(struct kmem_cache *cache, |
| 73 | void *object) {} |
| 74 | |
| 75 | static inline void kasan_kmalloc_large(void *ptr, size_t size) {} |
| 76 | static inline void kasan_kfree_large(const void *ptr) {} |
| 77 | static inline void kasan_kmalloc(struct kmem_cache *s, const void *object, |
| 78 | size_t size) {} |
| 79 | static inline void kasan_krealloc(const void *object, size_t new_size) {} |
| 80 | |
| 81 | static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {} |
| 82 | static inline void kasan_slab_free(struct kmem_cache *s, void *object) {} |
| 83 | |
Andrey Ryabinin | bebf56a | 2015-02-13 14:40:17 -0800 | [diff] [blame] | 84 | static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } |
| 85 | static inline void kasan_module_free(void *addr) {} |
| 86 | |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 87 | #endif /* CONFIG_KASAN */ |
| 88 | |
| 89 | #endif /* LINUX_KASAN_H */ |