]>
Commit | Line | Data |
---|---|---|
7c50328b | 1 | #ifndef _SPLAT_INTERNAL_H |
2 | #define _SPLAT_INTERNAL_H | |
3 | ||
4 | #include <linux/kernel.h> | |
5 | #include <linux/module.h> | |
6 | #include <linux/string.h> | |
7 | #include <linux/errno.h> | |
8 | #include <linux/slab.h> | |
9 | #include <linux/sched.h> | |
10 | #include <linux/elf.h> | |
11 | #include <linux/limits.h> | |
12 | #include <linux/version.h> | |
13 | #include <linux/vmalloc.h> | |
14 | #include <linux/module.h> | |
15 | #include <linux/device.h> | |
16 | #include <linux/list.h> | |
17 | #include <asm/ioctls.h> | |
18 | #include <asm/uaccess.h> | |
19 | #include <stdarg.h> | |
20 | ||
23f28c4f | 21 | #include <sys/callb.h> |
22 | #include <sys/condvar.h> | |
23 | #include <sys/cred.h> | |
24 | #include <sys/sysmacros.h> | |
25 | #include <sys/kmem.h> | |
26 | #include <sys/kstat.h> | |
27 | #include <sys/mutex.h> | |
28 | #include <sys/random.h> | |
29 | #include <sys/rwlock.h> | |
30 | #include <sys/taskq.h> | |
31 | #include <sys/thread.h> | |
32 | #include <sys/time.h> | |
33 | #include <sys/timer.h> | |
34 | #include <sys/types.h> | |
9490c148 | 35 | #include <sys/kobj.h> |
23f28c4f | 36 | |
596e65b4 | 37 | #include "splat-ctl.h" |
7c50328b | 38 | |
39 | #define SPLAT_SUBSYSTEM_INIT(type) \ | |
40 | ({ splat_subsystem_t *_sub_; \ | |
41 | \ | |
42 | _sub_ = (splat_subsystem_t *)splat_##type##_init(); \ | |
43 | if (_sub_ == NULL) { \ | |
44 | printk(KERN_ERR "Error initializing: " #type "\n"); \ | |
45 | } else { \ | |
46 | spin_lock(&splat_module_lock); \ | |
47 | list_add_tail(&(_sub_->subsystem_list), \ | |
48 | &splat_module_list); \ | |
49 | spin_unlock(&splat_module_lock); \ | |
50 | } \ | |
51 | }) | |
52 | ||
53 | #define SPLAT_SUBSYSTEM_FINI(type) \ | |
54 | ({ splat_subsystem_t *_sub_, *_tmp_; \ | |
55 | int _id_, _flag_ = 0; \ | |
56 | \ | |
57 | _id_ = splat_##type##_id(); \ | |
58 | spin_lock(&splat_module_lock); \ | |
59 | list_for_each_entry_safe(_sub_, _tmp_, &splat_module_list, \ | |
60 | subsystem_list) { \ | |
61 | if (_sub_->desc.id == _id_) { \ | |
62 | list_del_init(&(_sub_->subsystem_list)); \ | |
63 | spin_unlock(&splat_module_lock); \ | |
64 | splat_##type##_fini(_sub_); \ | |
65 | spin_lock(&splat_module_lock); \ | |
66 | _flag_ = 1; \ | |
67 | } \ | |
68 | } \ | |
69 | spin_unlock(&splat_module_lock); \ | |
70 | \ | |
71 | if (!_flag_) \ | |
72 | printk(KERN_ERR "Error finalizing: " #type "\n"); \ | |
73 | }) | |
74 | ||
75 | #define SPLAT_TEST_INIT(sub, n, d, tid, func) \ | |
76 | ({ splat_test_t *_test_; \ | |
77 | \ | |
78 | _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \ | |
79 | if (_test_ == NULL) { \ | |
80 | printk(KERN_ERR "Error initializing: " n "/" #tid" \n");\ | |
81 | } else { \ | |
82 | memset(_test_, 0, sizeof(*_test_)); \ | |
83 | strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE); \ | |
84 | strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE); \ | |
85 | _test_->desc.id = tid; \ | |
86 | _test_->test = func; \ | |
87 | INIT_LIST_HEAD(&(_test_->test_list)); \ | |
88 | spin_lock(&((sub)->test_lock)); \ | |
89 | list_add_tail(&(_test_->test_list),&((sub)->test_list));\ | |
90 | spin_unlock(&((sub)->test_lock)); \ | |
91 | } \ | |
92 | }) | |
93 | ||
94 | #define SPLAT_TEST_FINI(sub, tid) \ | |
95 | ({ splat_test_t *_test_, *_tmp_; \ | |
96 | int _flag_ = 0; \ | |
97 | \ | |
98 | spin_lock(&((sub)->test_lock)); \ | |
99 | list_for_each_entry_safe(_test_, _tmp_, \ | |
100 | &((sub)->test_list), test_list) { \ | |
101 | if (_test_->desc.id == tid) { \ | |
102 | list_del_init(&(_test_->test_list)); \ | |
103 | _flag_ = 1; \ | |
104 | } \ | |
105 | } \ | |
106 | spin_unlock(&((sub)->test_lock)); \ | |
107 | \ | |
108 | if (!_flag_) \ | |
109 | printk(KERN_ERR "Error finalizing: " #tid "\n"); \ | |
110 | }) | |
111 | ||
112 | typedef int (*splat_test_func_t)(struct file *, void *); | |
113 | ||
114 | typedef struct splat_test { | |
115 | struct list_head test_list; | |
116 | splat_user_t desc; | |
117 | splat_test_func_t test; | |
118 | } splat_test_t; | |
119 | ||
120 | typedef struct splat_subsystem { | |
121 | struct list_head subsystem_list;/* List had to chain entries */ | |
122 | splat_user_t desc; | |
123 | spinlock_t test_lock; | |
124 | struct list_head test_list; | |
125 | } splat_subsystem_t; | |
126 | ||
127 | #define SPLAT_INFO_BUFFER_SIZE 65536 | |
128 | #define SPLAT_INFO_BUFFER_REDZONE 256 | |
129 | ||
130 | typedef struct splat_info { | |
131 | spinlock_t info_lock; | |
132 | int info_size; | |
133 | char *info_buffer; | |
134 | char *info_head; /* Internal kernel use only */ | |
135 | } splat_info_t; | |
136 | ||
137 | #define sym2str(sym) (char *)(#sym) | |
138 | ||
139 | #define splat_print(file, format, args...) \ | |
140 | ({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \ | |
141 | int _rc_; \ | |
142 | \ | |
143 | ASSERT(_info_); \ | |
144 | ASSERT(_info_->info_buffer); \ | |
145 | \ | |
146 | spin_lock(&_info_->info_lock); \ | |
147 | \ | |
148 | /* Don't allow the kernel to start a write in the red zone */ \ | |
149 | if ((int)(_info_->info_head - _info_->info_buffer) > \ | |
150 | (SPLAT_INFO_BUFFER_SIZE - SPLAT_INFO_BUFFER_REDZONE)) { \ | |
151 | _rc_ = -EOVERFLOW; \ | |
152 | } else { \ | |
153 | _rc_ = sprintf(_info_->info_head, format, args); \ | |
154 | if (_rc_ >= 0) \ | |
155 | _info_->info_head += _rc_; \ | |
156 | } \ | |
157 | \ | |
158 | spin_unlock(&_info_->info_lock); \ | |
159 | _rc_; \ | |
160 | }) | |
161 | ||
162 | #define splat_vprint(file, test, format, args...) \ | |
163 | splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args) | |
164 | ||
165 | splat_subsystem_t * splat_condvar_init(void); | |
166 | splat_subsystem_t * splat_kmem_init(void); | |
167 | splat_subsystem_t * splat_mutex_init(void); | |
168 | splat_subsystem_t * splat_krng_init(void); | |
169 | splat_subsystem_t * splat_rwlock_init(void); | |
170 | splat_subsystem_t * splat_taskq_init(void); | |
171 | splat_subsystem_t * splat_thread_init(void); | |
172 | splat_subsystem_t * splat_time_init(void); | |
4b171585 | 173 | splat_subsystem_t * splat_vnode_init(void); |
9490c148 | 174 | splat_subsystem_t * splat_kobj_init(void); |
7c50328b | 175 | |
176 | void splat_condvar_fini(splat_subsystem_t *); | |
177 | void splat_kmem_fini(splat_subsystem_t *); | |
178 | void splat_mutex_fini(splat_subsystem_t *); | |
179 | void splat_krng_fini(splat_subsystem_t *); | |
180 | void splat_rwlock_fini(splat_subsystem_t *); | |
181 | void splat_taskq_fini(splat_subsystem_t *); | |
182 | void splat_thread_fini(splat_subsystem_t *); | |
183 | void splat_time_fini(splat_subsystem_t *); | |
4b171585 | 184 | void splat_vnode_fini(splat_subsystem_t *); |
9490c148 | 185 | void splat_kobj_fini(splat_subsystem_t *); |
7c50328b | 186 | |
187 | int splat_condvar_id(void); | |
188 | int splat_kmem_id(void); | |
189 | int splat_mutex_id(void); | |
190 | int splat_krng_id(void); | |
191 | int splat_rwlock_id(void); | |
192 | int splat_taskq_id(void); | |
193 | int splat_thread_id(void); | |
194 | int splat_time_id(void); | |
4b171585 | 195 | int splat_vnode_id(void); |
9490c148 | 196 | int splat_kobj_id(void); |
7c50328b | 197 | |
198 | #endif /* _SPLAT_INTERNAL_H */ |