1 |
/* |
2 |
* fs/ccsecurity/compat.h |
3 |
* |
4 |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
5 |
* |
6 |
* Version: 1.7.0-pre 2009/07/03 |
7 |
* |
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 |
/* To support PID namespace. */ |
62 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
63 |
#define find_task_by_pid find_task_by_vpid |
64 |
#endif |
65 |
|
66 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) |
67 |
#define mutex semaphore |
68 |
#define mutex_init(mutex) init_MUTEX(mutex) |
69 |
#define mutex_lock(mutex) down(mutex) |
70 |
#define mutex_unlock(mutex) up(mutex) |
71 |
#define mutex_lock_interruptible(mutex) down_interruptible(mutex) |
72 |
#define mutex_trylock(mutex) !down_trylock(mutex) |
73 |
#define DEFINE_MUTEX(mutexname) DECLARE_MUTEX(mutexname) |
74 |
#endif |
75 |
|
76 |
#ifndef container_of |
77 |
#define container_of(ptr, type, member) ({ \ |
78 |
const typeof(((type *)0)->member) *__mptr = (ptr); \ |
79 |
(type *)((char *)__mptr - offsetof(type, member)); }) |
80 |
#endif |
81 |
|
82 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) |
83 |
#define kzalloc(size, flags) ({ \ |
84 |
void *ret = kmalloc((size), (flags)); \ |
85 |
if (ret) \ |
86 |
memset(ret, 0, (size)); \ |
87 |
ret; }) |
88 |
#endif |
89 |
|
90 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) |
91 |
#define smp_read_barrier_depends smp_rmb |
92 |
#endif |
93 |
|
94 |
#ifndef ACCESS_ONCE |
95 |
#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) |
96 |
#endif |
97 |
|
98 |
#ifndef rcu_dereference |
99 |
#define rcu_dereference(p) ({ \ |
100 |
typeof(p) _________p1 = ACCESS_ONCE(p); \ |
101 |
smp_read_barrier_depends(); /* see RCU */ \ |
102 |
(_________p1); \ |
103 |
}) |
104 |
#endif |
105 |
|
106 |
#ifndef rcu_assign_pointer |
107 |
#define rcu_assign_pointer(p, v) \ |
108 |
({ \ |
109 |
if (!__builtin_constant_p(v) || \ |
110 |
((v) != NULL)) \ |
111 |
smp_wmb(); /* see RCU */ \ |
112 |
(p) = (v); \ |
113 |
}) |
114 |
#endif |
115 |
|
116 |
#ifndef list_for_each_rcu |
117 |
#define list_for_each_rcu(pos, head) \ |
118 |
for (pos = rcu_dereference((head)->next); \ |
119 |
prefetch(pos->next), pos != (head); \ |
120 |
pos = rcu_dereference(pos->next)) |
121 |
#endif |
122 |
|
123 |
#ifndef list_for_each_entry_rcu |
124 |
#define list_for_each_entry_rcu(pos, head, member) \ |
125 |
for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), \ |
126 |
member); \ |
127 |
prefetch(pos->member.next), &pos->member != (head); \ |
128 |
pos = list_entry(rcu_dereference(pos->member.next), \ |
129 |
typeof(*pos), member)) |
130 |
#endif |
131 |
|
132 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
133 |
static inline void __list_add_rcu(struct list_head *new, |
134 |
struct list_head *prev, |
135 |
struct list_head *next) |
136 |
{ |
137 |
new->next = next; |
138 |
new->prev = prev; |
139 |
rcu_assign_pointer(prev->next, new); |
140 |
next->prev = new; |
141 |
} |
142 |
|
143 |
static inline void list_add_tail_rcu(struct list_head *new, |
144 |
struct list_head *head) |
145 |
{ |
146 |
__list_add_rcu(new, head->prev, head); |
147 |
} |
148 |
|
149 |
static inline void list_add_rcu(struct list_head *new, struct list_head *head) |
150 |
{ |
151 |
__list_add_rcu(new, head, head->next); |
152 |
} |
153 |
|
154 |
#ifndef LIST_POISON2 |
155 |
#define LIST_POISON2 ((void *) 0x00200200) |
156 |
#endif |
157 |
|
158 |
static inline void list_del_rcu(struct list_head *entry) |
159 |
{ |
160 |
__list_del(entry->prev, entry->next); |
161 |
entry->prev = LIST_POISON2; |
162 |
} |
163 |
#endif |
164 |
|
165 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 30) |
166 |
#undef ssleep |
167 |
#define ssleep(secs) { \ |
168 |
set_current_state(TASK_UNINTERRUPTIBLE); \ |
169 |
schedule_timeout((HZ * secs) + 1); \ |
170 |
} |
171 |
#endif |
172 |
|
173 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
174 |
#define s_fs_info u.generic_sbp |
175 |
#else |
176 |
#include <linux/audit.h> |
177 |
#ifdef AUDIT_APPARMOR_AUDIT |
178 |
/* AppArmor patch adds "struct vfsmount" to VFS helper functions. */ |
179 |
#define HAVE_VFSMOUNT_IN_VFS_HELPER |
180 |
#endif |
181 |
#endif |
182 |
|
183 |
#if defined(RHEL_MAJOR) && RHEL_MAJOR == 5 |
184 |
#define HAVE_NO_I_BLKSIZE_IN_INODE |
185 |
#elif defined(AX_MAJOR) && AX_MAJOR == 3 |
186 |
#define HAVE_NO_I_BLKSIZE_IN_INODE |
187 |
#endif |
188 |
|
189 |
#ifndef list_for_each_entry_safe |
190 |
#define list_for_each_entry_safe(pos, n, head, member) \ |
191 |
for (pos = list_entry((head)->next, typeof(*pos), member), \ |
192 |
n = list_entry(pos->member.next, typeof(*pos), member); \ |
193 |
&pos->member != (head); \ |
194 |
pos = n, n = list_entry(n->member.next, typeof(*n), member)) |
195 |
#endif |
196 |
|
197 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
198 |
#define sk_family family |
199 |
#define sk_protocol protocol |
200 |
#define sk_type type |
201 |
#define sk_receive_queue receive_queue |
202 |
static inline struct socket *SOCKET_I(struct inode *inode) |
203 |
{ |
204 |
return inode->i_sock ? &inode->u.socket_i : NULL; |
205 |
} |
206 |
#endif |
207 |
|
208 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) |
209 |
#if defined(__LITTLE_ENDIAN) |
210 |
#define HIPQUAD(addr) \ |
211 |
((unsigned char *)&addr)[3], \ |
212 |
((unsigned char *)&addr)[2], \ |
213 |
((unsigned char *)&addr)[1], \ |
214 |
((unsigned char *)&addr)[0] |
215 |
#elif defined(__BIG_ENDIAN) |
216 |
#define HIPQUAD NIPQUAD |
217 |
#else |
218 |
#error "Please fix asm/byteorder.h" |
219 |
#endif /* __LITTLE_ENDIAN */ |
220 |
#endif |
221 |
|
222 |
#ifndef _LINUX_SRCU_H |
223 |
|
224 |
struct srcu_struct { |
225 |
int counter_idx; |
226 |
int counter[2]; |
227 |
}; |
228 |
|
229 |
static inline int init_srcu_struct(struct srcu_struct *sp) |
230 |
{ |
231 |
return 0; |
232 |
} |
233 |
|
234 |
int srcu_read_lock(struct srcu_struct *sp); |
235 |
void srcu_read_unlock(struct srcu_struct *sp, const int idx); |
236 |
void synchronize_srcu(struct srcu_struct *sp); |
237 |
|
238 |
#endif |