-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
73 lines (55 loc) · 1.78 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef __COMMON_H__
#define __COMMON_H__
// make this is not conflict with that defined in include/uapi/linux/if_tun.h
#define TUNGET_PAGE_SIZE _IOR('T', 230, unsigned int)
#define TUN_IOC_SEM_WAIT _IOW('T', 231, unsigned int)
#define TUNSET_RBF _IOW('T', 232, unsigned int)
#define TUNSET_MULTI_PKT _IOW('T', 233, unsigned int)
#ifdef __KERNEL__
#include <linux/kernel.h>
#include <linux/module.h>
#define print printk
#define KUMAP_LOG_LEVEL 2
#define KUMAP_LOG(level, fmt, ...) do { \
if ((level) <= KUMAP_LOG_LEVEL) { \
printk("*KUMAP* " fmt "\n", ##__VA_ARGS__); \
} \
} while (0)
#define KUMAP_LOG_IF(level, cond, fmt, ...) do { \
if ((level) <= KUMAP_LOG_LEVEL) { \
if (cond) { \
printk("*KUMAP* " fmt "\n", ##__VA_ARGS__); \
} \
} \
} while (0)
#define KUMAP_ASSERT(cond) BUG_ON(!(cond))
#define KUMAP_ASSERT_MSG(cond, fmt, ...) do { \
if (unlikely(!(cond))) { \
printk(fmt "\n", ##__VA_ARGS__); \
BUG(); \
} \
} while (0)
#define KUMAP_ERROR(...) KUMAP_LOG(0, ##__VA_ARGS__)
#define KUMAP_ERROR_IF(cond, ...) KUMAP_LOG_IF(0, cond, ##__VA_ARGS__)
#define KUMAP_WARN(...) KUMAP_LOG(1, ##__VA_ARGS__)
#define KUMAP_WARN_IF(cond, ...) KUMAP_LOG_IF(1, cond, ##__VA_ARGS__)
#define KUMAP_INFO(...) KUMAP_LOG(2, ##__VA_ARGS__)
#define KUMAP_INFO_IF(cond, ...) KUMAP_LOG_IF(2, cond, ##__VA_ARGS__)
#define KUMAP_DEBUG(...) KUMAP_LOG(3, ##__VA_ARGS__)
#define KUMAP_DEBUG_IF(cond, ...) KUMAP_LOG_IF(3, cond, ##__VA_ARGS__)
#else /* end kernel */
#define _GNU_SOURCE
#include <sched.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#define print printf
#endif /* __KERNEL__ */
#endif /* __COMMON_H__ */