Print this page
new smatch
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/allocate.h
+++ new/usr/src/tools/smatch/src/allocate.h
1 1 #ifndef ALLOCATE_H
2 2 #define ALLOCATE_H
3 3
4 +#include "compat.h"
5 +
4 6 struct allocation_blob {
5 7 struct allocation_blob *next;
6 8 unsigned int left, offset;
7 9 unsigned char data[];
8 10 };
9 11
10 12 struct allocator_struct {
11 13 const char *name;
12 14 struct allocation_blob *blobs;
13 15 unsigned int alignment;
14 16 unsigned int chunking;
15 17 void *freelist;
16 18 /* statistics */
17 19 unsigned long allocations, total_bytes, useful_bytes;
18 20 };
19 21
20 22 struct allocator_stats {
21 23 const char *name;
22 24 unsigned int allocations;
23 25 unsigned long total_bytes, useful_bytes;
24 26 };
25 27
26 28 extern void protect_allocations(struct allocator_struct *desc);
27 29 extern void drop_all_allocations(struct allocator_struct *desc);
28 30 extern void *allocate(struct allocator_struct *desc, unsigned int size);
29 31 extern void free_one_entry(struct allocator_struct *desc, void *entry);
30 32 extern void show_allocations(struct allocator_struct *);
31 33 extern void get_allocator_stats(struct allocator_struct *, struct allocator_stats *);
32 34 extern void show_allocation_stats(void);
33 35
34 36 #define __DECLARE_ALLOCATOR(type, x) \
35 37 extern type *__alloc_##x(int); \
36 38 extern void __free_##x(type *); \
37 39 extern void show_##x##_alloc(void); \
38 40 extern void get_##x##_stats(struct allocator_stats *); \
39 41 extern void clear_##x##_alloc(void); \
40 42 extern void protect_##x##_alloc(void);
41 43 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
42 44
43 45 #define __DO_ALLOCATOR(type, objsize, objalign, objname, x) \
44 46 static struct allocator_struct x##_allocator = { \
45 47 .name = objname, \
46 48 .alignment = objalign, \
47 49 .chunking = CHUNK }; \
48 50 type *__alloc_##x(int extra) \
49 51 { \
50 52 return allocate(&x##_allocator, objsize+extra); \
51 53 } \
52 54 void __free_##x(type *entry) \
53 55 { \
54 56 free_one_entry(&x##_allocator, entry); \
55 57 } \
56 58 void show_##x##_alloc(void) \
57 59 { \
58 60 show_allocations(&x##_allocator); \
59 61 } \
60 62 void get_##x##_stats(struct allocator_stats *s) \
61 63 { \
62 64 get_allocator_stats(&x##_allocator, s); \
63 65 } \
64 66 void clear_##x##_alloc(void) \
65 67 { \
66 68 drop_all_allocations(&x##_allocator); \
67 69 } \
68 70 void protect_##x##_alloc(void) \
69 71 { \
70 72 protect_allocations(&x##_allocator); \
71 73 }
72 74
73 75 #define __ALLOCATOR(t, n, x) \
74 76 __DO_ALLOCATOR(t, sizeof(t), __alignof__(t), n, x)
75 77
76 78 #define ALLOCATOR(x, n) __ALLOCATOR(struct x, n, x)
77 79
78 80 DECLARE_ALLOCATOR(ident);
79 81 DECLARE_ALLOCATOR(token);
80 82 DECLARE_ALLOCATOR(context);
81 83 DECLARE_ALLOCATOR(symbol);
82 84 DECLARE_ALLOCATOR(expression);
83 85 DECLARE_ALLOCATOR(statement);
84 86 DECLARE_ALLOCATOR(string);
85 87 DECLARE_ALLOCATOR(scope);
86 88 __DECLARE_ALLOCATOR(void, bytes);
87 89 DECLARE_ALLOCATOR(basic_block);
88 90 DECLARE_ALLOCATOR(entrypoint);
89 91 DECLARE_ALLOCATOR(instruction);
90 92 DECLARE_ALLOCATOR(multijmp);
91 93 DECLARE_ALLOCATOR(pseudo);
92 94 DECLARE_ALLOCATOR(attribute);
93 95
94 96 #endif
↓ open down ↓ |
81 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX