Merge branch 'docs-next' of git://git.lwn.net/linux-2.6
[linux-2.6/next.git] / include / linux / kmemcheck.h
blobe880d4cf9e223d1e4ca4b8e4ebe655f599a52b16
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,
14 size_t size);
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,
18 gfp_t gfpflags);
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);
37 bool kmemcheck_is_obj_initialized(unsigned long addr, size_t size);
39 #else
40 #define kmemcheck_enabled 0
42 static inline void
43 kmemcheck_alloc_shadow(struct page *page, int order, gfp_t flags, int node)
47 static inline void
48 kmemcheck_free_shadow(struct page *page, int order)
52 static inline void
53 kmemcheck_slab_alloc(struct kmem_cache *s, gfp_t gfpflags, void *object,
54 size_t size)
58 static inline void kmemcheck_slab_free(struct kmem_cache *s, void *object,
59 size_t size)
63 static inline void kmemcheck_pagealloc_alloc(struct page *p,
64 unsigned int order, gfp_t gfpflags)
68 static inline bool kmemcheck_page_is_tracked(struct page *p)
70 return false;
73 static inline void kmemcheck_mark_unallocated(void *address, unsigned int n)
77 static inline void kmemcheck_mark_uninitialized(void *address, unsigned int n)
81 static inline void kmemcheck_mark_initialized(void *address, unsigned int n)
85 static inline void kmemcheck_mark_freed(void *address, unsigned int n)
89 static inline void kmemcheck_mark_unallocated_pages(struct page *p,
90 unsigned int n)
94 static inline void kmemcheck_mark_uninitialized_pages(struct page *p,
95 unsigned int n)
99 static inline void kmemcheck_mark_initialized_pages(struct page *p,
100 unsigned int n)
104 static inline bool kmemcheck_is_obj_initialized(unsigned long addr, size_t size)
106 return true;
109 #endif /* CONFIG_KMEMCHECK */
112 * Bitfield annotations
114 * How to use: If you have a struct using bitfields, for example
116 * struct a {
117 * int x:8, y:8;
118 * };
120 * then this should be rewritten as
122 * struct a {
123 * kmemcheck_bitfield_begin(flags);
124 * int x:8, y:8;
125 * kmemcheck_bitfield_end(flags);
126 * };
128 * Now the "flags_begin" and "flags_end" members may be used to refer to the
129 * beginning and end, respectively, of the bitfield (and things like
130 * &x.flags_begin is allowed). As soon as the struct is allocated, the bit-
131 * fields should be annotated:
133 * struct a *a = kmalloc(sizeof(struct a), GFP_KERNEL);
134 * kmemcheck_annotate_bitfield(a, flags);
136 * Note: We provide the same definitions for both kmemcheck and non-
137 * kmemcheck kernels. This makes it harder to introduce accidental errors. It
138 * is also allowed to pass NULL pointers to kmemcheck_annotate_bitfield().
140 #define kmemcheck_bitfield_begin(name) \
141 int name##_begin[0];
143 #define kmemcheck_bitfield_end(name) \
144 int name##_end[0];
146 #define kmemcheck_annotate_bitfield(ptr, name) \
147 do { \
148 int _n; \
150 if (!ptr) \
151 break; \
153 _n = (long) &((ptr)->name##_end) \
154 - (long) &((ptr)->name##_begin); \
155 MAYBE_BUILD_BUG_ON(_n < 0); \
157 kmemcheck_mark_initialized(&((ptr)->name##_begin), _n); \
158 } while (0)
160 #define kmemcheck_annotate_variable(var) \
161 do { \
162 kmemcheck_mark_initialized(&(var), sizeof(var)); \
163 } while (0) \
165 #endif /* LINUX_KMEMCHECK_H */