summaryrefslogtreecommitdiff
path: root/compatibility.h
blob: 3bfde511a12cc7dd2f8ecf78e5ed7aaaae64b535 (plain)
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
74
75
76
77
/*
 * Samsung Electronics
 * TTV SBB project
 *
 * macros and API missing or incompatible in kernel 3.8
 */
#include <linux/version.h>

// message.c patch
#if LINUX_VERSION_CODE <= KERNEL_VERSION(3,10,0)
int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
            char *buf, size_t buflen);
#endif

// bus.c
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
#undef hlist_for_each_entry
#undef hash_for_each_possible

#define hlist_entry_safe(ptr, type, member) \
         ({ typeof(ptr) ____ptr = (ptr); \
            ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
         })

#define hlist_for_each_entry(pos, head, member)                         \
         for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
              pos;                                                       \
              pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))

#define hash_for_each_possible(name, obj, member, key)                  \
         hlist_for_each_entry(obj, &name[hash_min(key, HASH_BITS(name))], member)

// connection.c
#undef hash_for_each

#define hash_for_each(name, bkt, obj, member)                           \
         for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\
                         (bkt)++)\
                 hlist_for_each_entry(obj, &name[bkt], member)
#endif

//memfd.c
// inspiration:
// https://groups.google.com/forum/#!searchin/linux.kernel/file_inode/linux.kernel/o6_raT6IOrs/9JHAg66rmngJ
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
static inline struct inode *file_inode(struct file *f)
{
        return f->f_mapping->host;
}
#endif

//endpoint.c and namespace.c
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
int idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp_mask);
#endif

// main.c
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
int subsys_virtual_register(struct bus_type *subsys,
			    const struct attribute_group **groups);
#endif

// names.c
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
#undef hash_for_each_safe
#undef hlist_for_each_entry_safe

#define hlist_for_each_entry_safe(pos, n, head, member)                 \
         for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
              pos && ({ n = pos->member.next; 1; });                     \
              pos = hlist_entry_safe(n, typeof(*pos), member))

#define hash_for_each_safe(name, bkt, tmp, obj, member)                 \
         for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\
                         (bkt)++)\
                 hlist_for_each_entry_safe(obj, tmp, &name[bkt], member)
#endif