1 #ifndef LINUX_KMEMCHECK_H
2 #define LINUX_KMEMCHECK_H
4 #include <linux/mm_types.h>
5 #include <linux/types.h>
7 #ifdef CONFIG_KMEMCHECK
8 extern int kmemcheck_enabled;
10 /* The slab-related functions. */
11 void kmemcheck_alloc_shadow(struct page *page, int order, gfp_t flags, int node);
12 void kmemcheck_free_shadow(struct page *page, int order);
13 void kmemcheck_slab_alloc(struct kmem_cache *s, gfp_t gfpflags, void *object,
15 void kmemcheck_slab_free(struct kmem_cache *s, void *object, size_t size);
17 void kmemcheck_pagealloc_alloc(struct page *p, unsigned int order,
20 void kmemcheck_show_pages(struct page *p, unsigned int n);
21 void kmemcheck_hide_pages(struct page *p, unsigned int n);
23 bool kmemcheck_page_is_tracked(struct page *p);
25 void kmemcheck_mark_unallocated(void *address, unsigned int n);
26 void kmemcheck_mark_uninitialized(void *address, unsigned int n);
27 void kmemcheck_mark_initialized(void *address, unsigned int n);
28 void kmemcheck_mark_freed(void *address, unsigned int n);
30 void kmemcheck_mark_unallocated_pages(struct page *p, unsigned int n);
31 void kmemcheck_mark_uninitialized_pages(struct page *p, unsigned int n);
32 void kmemcheck_mark_initialized_pages(struct page *p, unsigned int n);
34 int kmemcheck_show_addr(unsigned long address);
35 int kmemcheck_hide_addr(unsigned long address);
38 #define kmemcheck_enabled 0
41 kmemcheck_alloc_shadow(struct page *page, int order, gfp_t flags, int node)
46 kmemcheck_free_shadow(struct page *page, int order)
51 kmemcheck_slab_alloc(struct kmem_cache *s, gfp_t gfpflags, void *object,
56 static inline void kmemcheck_slab_free(struct kmem_cache *s, void *object,
61 static inline void kmemcheck_pagealloc_alloc(struct page *p,
62 unsigned int order, gfp_t gfpflags)
66 static inline bool kmemcheck_page_is_tracked(struct page *p)
71 static inline void kmemcheck_mark_unallocated(void *address, unsigned int n)
75 static inline void kmemcheck_mark_uninitialized(void *address, unsigned int n)
79 static inline void kmemcheck_mark_initialized(void *address, unsigned int n)
83 static inline void kmemcheck_mark_freed(void *address, unsigned int n)
87 static inline void kmemcheck_mark_unallocated_pages(struct page *p,
92 static inline void kmemcheck_mark_uninitialized_pages(struct page *p,
97 static inline void kmemcheck_mark_initialized_pages(struct page *p,
102 #endif /* CONFIG_KMEMCHECK */
105 * Bitfield annotations
107 * How to use: If you have a struct using bitfields, for example
113 * then this should be rewritten as
116 * kmemcheck_bitfield_begin(flags);
118 * kmemcheck_bitfield_end(flags);
121 * Now the "flags_begin" and "flags_end" members may be used to refer to the
122 * beginning and end, respectively, of the bitfield (and things like
123 * &x.flags_begin is allowed). As soon as the struct is allocated, the bit-
124 * fields should be annotated:
126 * struct a *a = kmalloc(sizeof(struct a), GFP_KERNEL);
127 * kmemcheck_annotate_bitfield(a, flags);
129 * Note: We provide the same definitions for both kmemcheck and non-
130 * kmemcheck kernels. This makes it harder to introduce accidental errors. It
131 * is also allowed to pass NULL pointers to kmemcheck_annotate_bitfield().
133 #define kmemcheck_bitfield_begin(name) \
136 #define kmemcheck_bitfield_end(name) \
139 #define kmemcheck_annotate_bitfield(ptr, name) \
141 int _n = (long) &((ptr)->name##_end) \
142 - (long) &((ptr)->name##_begin); \
143 BUILD_BUG_ON(_n < 0); \
145 kmemcheck_mark_initialized(&((ptr)->name##_begin), _n); \
148 #define kmemcheck_annotate_variable(var) \
150 kmemcheck_mark_initialized(&(var), sizeof(var)); \
153 #endif /* LINUX_KMEMCHECK_H */