post_hook.h 7.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * post_hook.h
 *
 * #include this file after all #include's in a source
 * file. Do not #include this in a header.
 *
 * This overwrites macros, defs, etc. that the top-level
 * kernel puts in place that we want to change for the
 * isolated environment.
 */
11

12
#include <liblcd/liblcd.h>
13
14
15
16
17
18
19
20
21

/*
 * Misc macros, etc.
 */

#undef BUG
#define BUG() do {							\
		lcd_printk("BUG! in %s:%s:%d", __FILE__, __func__,	\
			__LINE__);					\
22
		lcd_dump_stack();					\
23
24
25
26
27
28
29
30
		lcd_exit(-1);						\
	} while (0)

#undef BUG_ON
#define BUG_ON(x) do {							\
	if (x) {							\
		lcd_printk("BUG! in %s:%s:%d", __FILE__, __func__,	\
			__LINE__);					\
31
		lcd_dump_stack();					\
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
		lcd_exit(-1);						\
	}								\
	} while (0)

#undef VM_BUG_ON
#define VM_BUG_ON(x) do {						\
	if (x) {							\
		lcd_printk("VM_BUG! in %s:%s:%d", __FILE__, __func__,	\
			__LINE__);					\
		lcd_exit(-1);						\
	}								\
	} while (0)

#undef WARN_ON_ONCE
#define WARN_ON_ONCE(x) ({ x; })

#undef EXPORT_SYMBOL
#define EXPORT_SYMBOL(x)

#undef EXPORT_SYMBOL_GPL
#define EXPORT_SYMBOL_GPL(x)

#undef EXPORT_TRACEPOINT_SYMBOL
#define EXPORT_TRACEPOINT_SYMBOL(x)

#undef panic
#define panic(fmt, args...) do {			\
59
	lcd_printk(fmt, ##args);				\
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
	lcd_exit(-1);					\
	} while(0)

#undef printk_ratelimit
#define printk_ratelimit() true

#undef kasprintf
#define kasprintf(x, fmt, args...) ({ lcd_printk(fmt, args); (char *)1; });

#undef unlikely
#define unlikely(x) x

#undef likely
#define likely(x) x

/*
 * NUMA / SMP / PERCPU
 */

#undef numa_mem_id
#define numa_mem_id() 0

#undef nr_cpus_node
#define nr_cpus_node(x) 1

#undef smp_processor_id
#define smp_processor_id() 0

#undef num_possible_nodes
#define num_possible_nodes() 1

#undef DEFINE_PER_CPU
#define DEFINE_PER_CPU(type, name) __typeof__(type) name

#undef percpu
#define percpu(name, cpu) name

#undef __initcall
#define __initcall(x)

#undef on_each_cpu
#define on_each_cpu(func, arg, wait) do { func(arg); } while(0)

/*
 * mm
 */
#undef gfp_pfmemalloc_allowed
#define gfp_pfmemalloc_allowed(x) true

#undef sk_memalloc_socks
#define sk_memalloc_socks() false

#undef register_cpu_notifier
#define register_cpu_notifier(x) do { } while(0)

#undef add_zone_page_state
#define add_zone_page_state(x, y, z) do { } while(0)

#undef sub_zone_page_state
#define sub_zone_page_state(x, y, z) do { } while(0)

#undef prefetchw
#define prefetchw(x) do { } while(0)

#undef totalram_pages
#define totalram_pages 0UL

#undef mm_populate
#define mm_populate(x, y) do { } while(0)

#undef gfp_allowed_mask
#define gfp_allowed_mask __GFP_BITS_MASK

#undef do_mmap_pgoff
#define do_mmap_pgoff(x1,x2,x3,x4,x5,x6,x7) 0UL

#undef KSTK_ESP
#define KSTK_ESP(x) 0UL

/*
 * Locking, interrupts, etc.
 *
 * All locking etc. is elided.
 */

#undef DEFINE_MUTEX
#define DEFINE_MUTEX(x) struct mutex x

#undef get_online_cpus
#define get_online_cpus() do { } while(0)

#undef put_online_cpus
#define put_online_cpus() do { } while(0)

#undef spin_lock_init
#define spin_lock_init(x) do { } while(0)

#undef spin_lock_irqsave
#define spin_lock_irqsave(x,flags) do { } while (0)

#undef spin_lock
#define spin_lock(x) do { } while (0)

#undef spin_lock_irq
#define spin_lock_irq(x) do { } while (0)

166
167
#undef spin_unlock_irqrestore
#define spin_unlock_irqrestore(x,flags) do { } while (0)
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

#undef spin_unlock
#define spin_unlock(x) do { } while(0)

#undef spin_unlock_irq
#define spin_unlock_irq(x) do { } while(0)

#undef rcu_barrier
#define rcu_barrier() do { smp_mb(); } while(0)

#undef call_rcu
#define call_rcu(arg, func) do { func(arg); } while(0)

#undef local_irq_enable
#define local_irq_enable() do { } while(0)

#undef local_irq_disable
#define local_irq_disable() do { } while(0)

#undef might_sleep_if
#define might_sleep_if(x) do { } while (0)

#undef _raw_spin_lock
#define _raw_spin_lock(x) do { } while (0)

#undef _raw_spin_unlock
#define _raw_spin_unlock(x) do { } while (0)

static inline void force_down_read(void *x)
{
}
static inline void force_down_write(void *x)
{
}

#undef down_read
#define down_read(x) force_down_read(x)

#undef down_write
#define down_write(x) force_down_write(x)

static inline void force_up_read(void *x)
{
}
static inline void force_up_write(void *x)
{
}

#undef up_read
#define up_read(x) force_up_read(x)

#undef up_write
#define up_write(x) force_up_write(x)

#undef might_fault
#define might_fault() do { } while(0)

/*
 * Copy to/from user
 */

#undef get_user_pages
#define get_user_pages(x1,x2,x3,x4,x5,x6,x7,x8) 0L

/*
 * Tracing
 */              
#undef filter_current_check_discard
#define filter_current_check_discard(x,y,z,u) 0

#undef ftrace_event_reg
#define ftrace_event_reg(x, y, z) 0

#undef ftrace_print_flags_seq
#define ftrace_print_flags_seq(x, y, z, u) NULL

#undef ftrace_raw_output_prep
#define ftrace_raw_output_prep(x, y) 0

#undef trace_buffer_unlock_commit
#define trace_buffer_unlock_commit(x, y, z, u) do { } while(0)

#undef trace_define_field
#define trace_define_field(x1,x2,x3,x4,x5,x6,x7) 0

#undef trace_event_buffer_lock_reserve
#define trace_event_buffer_lock_reserve(x1,x2,x3,x4,x5,x6) NULL

#undef trace_event_raw_init
#define trace_event_raw_init(x) 0

#undef trace_hardirqs_off
#define trace_hardirqs_off() do { } while (0)

#undef trace_hardirqs_on
#define trace_hardirqs_on() do { } while(0)

/*
 * Arch
 */
#undef cache_line_size
#define cache_line_size() 64

#undef jiffies
#define jiffies 0UL

/*
 * Security
 */

#undef security_mmap_file
#define security_mmap_file(x, y, z) 0

#undef has_capability_noaudit
#define has_capability_noaudit(x, y) 1

/*
 * Low-level page alloc hacks
 */
#undef virt_to_head_page
#define virt_to_head_page(addr) lcd_virt_to_head_page(addr)

#undef virt_to_page
#define virt_to_page(addr) lcd_virt_to_head_page(addr)

#undef alloc_pages_exact_node
#define alloc_pages_exact_node(x, y, z) lcd_alloc_pages_exact_node(x,y,z)

#undef free_memcg_kmem_pages
#define free_memcg_kmem_pages(x, y) lcd_free_memcg_kmem_pages(x, y)

#undef page_address
#define page_address(page) lcd_page_address(page)
301
302
303

#undef __pa
#define __pa(vaddr) gpa_val(lcd_gva2gpa(__gva((unsigned long)vaddr)))
304

305
306
307
308
309
310
#undef free_page
#define free_page(addr) __lcd_free_pages(addr, 0)

#undef __get_free_page
#define __get_free_page(gfp_mask) __lcd_get_free_pages(gfp_mask, 0)

311
312
313
314
/* The "real" get_current tries to read a percpu variable that using
 * the %gs segment register. */
#undef get_current
#define get_current() (current_task)
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342

/* XXX: For IXGBE device layer
 * Polluting this file is inappropriate. Ideally we should have a
 * common {pre,post}_hook and a project specific one
 */
#undef dev_warn
#define dev_warn(dev, fmt, ...) do { } while(0)

#undef dev_err
#define dev_err(dev, fmt, ...) do { } while(0)

#undef dev_info
#define dev_info(dev, fmt, ...) do { } while(0)

/* net layer locks
 */
#define rtnl_lock()     do { } while(0)
#define rtnl_unlock()   do { } while(0)
#define rtnl_is_locked()        (0)

#define netdev_warn(dev, msg...)        LIBLCD_WARN(msg)
#define netdev_err(dev, msg...)         LIBLCD_ERR(msg)
#define netdev_crit(dev, msg...)        LIBLCD_ERR(msg)
#define netdev_info(dev, msg...)        LIBLCD_MSG(msg)

#define  __dynamic_netdev_dbg(desc, dev, fmt...)        LIBLCD_MSG(fmt)

#define system_state    1