blob: 72ba725ddf9c73054533256a7246f5425c95771b [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 Ryabinin0316bec2015-02-13 14:39:42 -080040void kasan_poison_slab(struct page *page);
41void kasan_unpoison_object_data(struct kmem_cache *cache, void *object);
42void kasan_poison_object_data(struct kmem_cache *cache, void *object);
43
44void kasan_kmalloc_large(const void *ptr, size_t size);
45void kasan_kfree_large(const void *ptr);
46void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size);
47void kasan_krealloc(const void *object, size_t new_size);
48
49void kasan_slab_alloc(struct kmem_cache *s, void *object);
50void kasan_slab_free(struct kmem_cache *s, void *object);
51
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080052#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
53
54int kasan_module_alloc(void *addr, size_t size);
55void kasan_module_free(void *addr);
56
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080057#else /* CONFIG_KASAN */
58
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080059#define MODULE_ALIGN 1
60
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080061static inline void kasan_unpoison_shadow(const void *address, size_t size) {}
62
63static inline void kasan_enable_current(void) {}
64static inline void kasan_disable_current(void) {}
65
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080066static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
67static inline void kasan_free_pages(struct page *page, unsigned int order) {}
68
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080069static inline void kasan_poison_slab(struct page *page) {}
70static inline void kasan_unpoison_object_data(struct kmem_cache *cache,
71 void *object) {}
72static inline void kasan_poison_object_data(struct kmem_cache *cache,
73 void *object) {}
74
75static inline void kasan_kmalloc_large(void *ptr, size_t size) {}
76static inline void kasan_kfree_large(const void *ptr) {}
77static inline void kasan_kmalloc(struct kmem_cache *s, const void *object,
78 size_t size) {}
79static inline void kasan_krealloc(const void *object, size_t new_size) {}
80
81static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {}
82static inline void kasan_slab_free(struct kmem_cache *s, void *object) {}
83
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080084static inline int kasan_module_alloc(void *addr, size_t size) { return 0; }
85static inline void kasan_module_free(void *addr) {}
86
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080087#endif /* CONFIG_KASAN */
88
89#endif /* LINUX_KASAN_H */