1 |
kumaneko |
2037 |
/* |
2 |
kumaneko |
2864 |
* security/ccsecurity/compat.h |
3 |
kumaneko |
2037 |
* |
4 |
|
|
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
5 |
|
|
* |
6 |
kumaneko |
3167 |
* Version: 1.7.1 2009/11/11 |
7 |
kumaneko |
2037 |
* |
8 |
|
|
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
9 |
|
|
* See README.ccs for ChangeLog. |
10 |
|
|
* |
11 |
|
|
*/ |
12 |
|
|
|
13 |
|
|
#define false 0 |
14 |
|
|
#define true 1 |
15 |
|
|
|
16 |
|
|
#ifndef __user |
17 |
|
|
#define __user |
18 |
|
|
#endif |
19 |
|
|
|
20 |
|
|
#ifndef current_uid |
21 |
|
|
#define current_uid() (current->uid) |
22 |
|
|
#endif |
23 |
|
|
#ifndef current_gid |
24 |
|
|
#define current_gid() (current->gid) |
25 |
|
|
#endif |
26 |
|
|
#ifndef current_euid |
27 |
|
|
#define current_euid() (current->euid) |
28 |
|
|
#endif |
29 |
|
|
#ifndef current_egid |
30 |
|
|
#define current_egid() (current->egid) |
31 |
|
|
#endif |
32 |
|
|
#ifndef current_suid |
33 |
|
|
#define current_suid() (current->suid) |
34 |
|
|
#endif |
35 |
|
|
#ifndef current_sgid |
36 |
|
|
#define current_sgid() (current->sgid) |
37 |
|
|
#endif |
38 |
|
|
#ifndef current_fsuid |
39 |
|
|
#define current_fsuid() (current->fsuid) |
40 |
|
|
#endif |
41 |
|
|
#ifndef current_fsgid |
42 |
|
|
#define current_fsgid() (current->fsgid) |
43 |
|
|
#endif |
44 |
|
|
|
45 |
|
|
#ifndef WARN_ON |
46 |
|
|
#define WARN_ON(x) do { } while (0) |
47 |
|
|
#endif |
48 |
|
|
|
49 |
|
|
#ifndef DEFINE_SPINLOCK |
50 |
|
|
#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED |
51 |
|
|
#endif |
52 |
|
|
|
53 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) |
54 |
|
|
#define bool _Bool |
55 |
|
|
#endif |
56 |
|
|
|
57 |
|
|
#ifndef KERN_CONT |
58 |
|
|
#define KERN_CONT "" |
59 |
|
|
#endif |
60 |
|
|
|
61 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) |
62 |
|
|
#define mutex semaphore |
63 |
|
|
#define mutex_init(mutex) init_MUTEX(mutex) |
64 |
|
|
#define mutex_lock(mutex) down(mutex) |
65 |
|
|
#define mutex_unlock(mutex) up(mutex) |
66 |
|
|
#define mutex_lock_interruptible(mutex) down_interruptible(mutex) |
67 |
kumaneko |
2716 |
#define mutex_trylock(mutex) !down_trylock(mutex) |
68 |
kumaneko |
2037 |
#define DEFINE_MUTEX(mutexname) DECLARE_MUTEX(mutexname) |
69 |
|
|
#endif |
70 |
|
|
|
71 |
|
|
#ifndef container_of |
72 |
|
|
#define container_of(ptr, type, member) ({ \ |
73 |
|
|
const typeof(((type *)0)->member) *__mptr = (ptr); \ |
74 |
|
|
(type *)((char *)__mptr - offsetof(type, member)); }) |
75 |
|
|
#endif |
76 |
|
|
|
77 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) |
78 |
kumaneko |
2943 |
#define kzalloc(size, flags) ({ \ |
79 |
|
|
void *ret = kmalloc((size), (flags)); \ |
80 |
|
|
if (ret) \ |
81 |
|
|
memset(ret, 0, (size)); \ |
82 |
kumaneko |
2037 |
ret; }) |
83 |
|
|
#endif |
84 |
|
|
|
85 |
kumaneko |
2690 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) |
86 |
|
|
#define smp_read_barrier_depends smp_rmb |
87 |
kumaneko |
2037 |
#endif |
88 |
|
|
|
89 |
kumaneko |
2690 |
#ifndef ACCESS_ONCE |
90 |
|
|
#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) |
91 |
|
|
#endif |
92 |
|
|
|
93 |
|
|
#ifndef rcu_dereference |
94 |
kumaneko |
2943 |
#define rcu_dereference(p) ({ \ |
95 |
|
|
typeof(p) _________p1 = ACCESS_ONCE(p); \ |
96 |
|
|
smp_read_barrier_depends(); /* see RCU */ \ |
97 |
|
|
(_________p1); \ |
98 |
|
|
}) |
99 |
kumaneko |
2690 |
#endif |
100 |
|
|
|
101 |
|
|
#ifndef rcu_assign_pointer |
102 |
kumaneko |
2943 |
#define rcu_assign_pointer(p, v) \ |
103 |
|
|
({ \ |
104 |
|
|
if (!__builtin_constant_p(v) || \ |
105 |
|
|
((v) != NULL)) \ |
106 |
|
|
smp_wmb(); /* see RCU */ \ |
107 |
|
|
(p) = (v); \ |
108 |
kumaneko |
2690 |
}) |
109 |
|
|
#endif |
110 |
|
|
|
111 |
|
|
#ifndef list_for_each_rcu |
112 |
kumaneko |
2943 |
#define list_for_each_rcu(pos, head) \ |
113 |
|
|
for (pos = rcu_dereference((head)->next); \ |
114 |
|
|
prefetch(pos->next), pos != (head); \ |
115 |
|
|
pos = rcu_dereference(pos->next)) |
116 |
kumaneko |
2690 |
#endif |
117 |
|
|
|
118 |
|
|
#ifndef list_for_each_entry_rcu |
119 |
kumaneko |
2943 |
#define list_for_each_entry_rcu(pos, head, member) \ |
120 |
kumaneko |
2690 |
for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), \ |
121 |
kumaneko |
2943 |
member); \ |
122 |
|
|
prefetch(pos->member.next), &pos->member != (head); \ |
123 |
|
|
pos = list_entry(rcu_dereference(pos->member.next), \ |
124 |
|
|
typeof(*pos), member)) |
125 |
kumaneko |
2037 |
#endif |
126 |
|
|
|
127 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
128 |
kumaneko |
2718 |
static inline void __list_add_rcu(struct list_head *new, |
129 |
|
|
struct list_head *prev, |
130 |
|
|
struct list_head *next) |
131 |
|
|
{ |
132 |
|
|
new->next = next; |
133 |
|
|
new->prev = prev; |
134 |
|
|
rcu_assign_pointer(prev->next, new); |
135 |
|
|
next->prev = new; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
static inline void list_add_tail_rcu(struct list_head *new, |
139 |
|
|
struct list_head *head) |
140 |
|
|
{ |
141 |
|
|
__list_add_rcu(new, head->prev, head); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
static inline void list_add_rcu(struct list_head *new, struct list_head *head) |
145 |
|
|
{ |
146 |
|
|
__list_add_rcu(new, head, head->next); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
#ifndef LIST_POISON2 |
150 |
|
|
#define LIST_POISON2 ((void *) 0x00200200) |
151 |
|
|
#endif |
152 |
|
|
|
153 |
|
|
static inline void list_del_rcu(struct list_head *entry) |
154 |
|
|
{ |
155 |
|
|
__list_del(entry->prev, entry->next); |
156 |
|
|
entry->prev = LIST_POISON2; |
157 |
|
|
} |
158 |
|
|
#endif |
159 |
|
|
|
160 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 30) |
161 |
kumaneko |
2720 |
#undef ssleep |
162 |
kumaneko |
2943 |
#define ssleep(secs) { \ |
163 |
|
|
set_current_state(TASK_UNINTERRUPTIBLE); \ |
164 |
|
|
schedule_timeout((HZ * secs) + 1); \ |
165 |
|
|
} |
166 |
kumaneko |
2718 |
#endif |
167 |
|
|
|
168 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
169 |
kumaneko |
2037 |
#define s_fs_info u.generic_sbp |
170 |
|
|
#endif |
171 |
|
|
|
172 |
|
|
#ifndef list_for_each_entry_safe |
173 |
|
|
#define list_for_each_entry_safe(pos, n, head, member) \ |
174 |
|
|
for (pos = list_entry((head)->next, typeof(*pos), member), \ |
175 |
|
|
n = list_entry(pos->member.next, typeof(*pos), member); \ |
176 |
|
|
&pos->member != (head); \ |
177 |
|
|
pos = n, n = list_entry(n->member.next, typeof(*n), member)) |
178 |
|
|
#endif |
179 |
|
|
|
180 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
181 |
|
|
#define sk_family family |
182 |
|
|
#define sk_protocol protocol |
183 |
|
|
#define sk_type type |
184 |
|
|
#define sk_receive_queue receive_queue |
185 |
kumaneko |
2281 |
static inline struct socket *SOCKET_I(struct inode *inode) |
186 |
|
|
{ |
187 |
|
|
return inode->i_sock ? &inode->u.socket_i : NULL; |
188 |
|
|
} |
189 |
kumaneko |
2037 |
#endif |
190 |
kumaneko |
2402 |
|
191 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) |
192 |
|
|
#if defined(__LITTLE_ENDIAN) |
193 |
kumaneko |
2943 |
#define HIPQUAD(addr) \ |
194 |
|
|
((unsigned char *)&addr)[3], \ |
195 |
|
|
((unsigned char *)&addr)[2], \ |
196 |
|
|
((unsigned char *)&addr)[1], \ |
197 |
|
|
((unsigned char *)&addr)[0] |
198 |
kumaneko |
2402 |
#elif defined(__BIG_ENDIAN) |
199 |
|
|
#define HIPQUAD NIPQUAD |
200 |
|
|
#else |
201 |
|
|
#error "Please fix asm/byteorder.h" |
202 |
|
|
#endif /* __LITTLE_ENDIAN */ |
203 |
|
|
#endif |
204 |
kumaneko |
2716 |
|
205 |
kumaneko |
2911 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
206 |
kumaneko |
3464 |
#ifndef _STRUCT_PATH_DEFINED |
207 |
kumaneko |
2911 |
struct path { |
208 |
kumaneko |
2943 |
struct vfsmount *mnt; |
209 |
|
|
struct dentry *dentry; |
210 |
kumaneko |
2911 |
}; |
211 |
|
|
#endif |
212 |
kumaneko |
3464 |
#endif |
213 |
kumaneko |
2911 |
|
214 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) |
215 |
|
|
|
216 |
|
|
#include <linux/mount.h> |
217 |
|
|
|
218 |
|
|
static inline void path_get(struct path *path) |
219 |
|
|
{ |
220 |
|
|
dget(path->dentry); |
221 |
|
|
mntget(path->mnt); |
222 |
|
|
} |
223 |
|
|
|
224 |
|
|
static inline void path_put(struct path *path) |
225 |
|
|
{ |
226 |
|
|
dput(path->dentry); |
227 |
|
|
mntput(path->mnt); |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
#endif |