1 |
/* |
/* |
2 |
* include/linux/ccs_compat.h |
* security/ccsecurity/compat.h |
|
* |
|
|
* For compatibility for older kernels. |
|
3 |
* |
* |
4 |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.6.6-pre 2009/01/05 |
* Version: 1.7.0-pre 2009/08/24 |
7 |
* |
* |
8 |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
9 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
58 |
#define KERN_CONT "" |
#define KERN_CONT "" |
59 |
#endif |
#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) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) |
67 |
#define mutex semaphore |
#define mutex semaphore |
68 |
#define mutex_init(mutex) init_MUTEX(mutex) |
#define mutex_init(mutex) init_MUTEX(mutex) |
69 |
#define mutex_lock(mutex) down(mutex) |
#define mutex_lock(mutex) down(mutex) |
70 |
#define mutex_unlock(mutex) up(mutex) |
#define mutex_unlock(mutex) up(mutex) |
71 |
#define mutex_lock_interruptible(mutex) down_interruptible(mutex) |
#define mutex_lock_interruptible(mutex) down_interruptible(mutex) |
72 |
|
#define mutex_trylock(mutex) !down_trylock(mutex) |
73 |
#define DEFINE_MUTEX(mutexname) DECLARE_MUTEX(mutexname) |
#define DEFINE_MUTEX(mutexname) DECLARE_MUTEX(mutexname) |
74 |
#endif |
#endif |
75 |
|
|
80 |
#endif |
#endif |
81 |
|
|
82 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) |
83 |
#define kzalloc(size, flags) ({ \ |
#define kzalloc(size, flags) ({ \ |
84 |
void *ret = kmalloc((size), (flags)); \ |
void *ret = kmalloc((size), (flags)); \ |
85 |
if (ret) \ |
if (ret) \ |
86 |
memset(ret, 0, (size)); \ |
memset(ret, 0, (size)); \ |
87 |
ret; }) |
ret; }) |
88 |
#endif |
#endif |
89 |
|
|
96 |
#endif |
#endif |
97 |
|
|
98 |
#ifndef rcu_dereference |
#ifndef rcu_dereference |
99 |
#define rcu_dereference(p) ({ \ |
#define rcu_dereference(p) ({ \ |
100 |
typeof(p) _________p1 = ACCESS_ONCE(p); \ |
typeof(p) _________p1 = ACCESS_ONCE(p); \ |
101 |
smp_read_barrier_depends(); /* see RCU */ \ |
smp_read_barrier_depends(); /* see RCU */ \ |
102 |
(_________p1); \ |
(_________p1); \ |
103 |
}) |
}) |
104 |
#endif |
#endif |
105 |
|
|
106 |
#ifndef rcu_assign_pointer |
#ifndef rcu_assign_pointer |
107 |
#define rcu_assign_pointer(p, v) \ |
#define rcu_assign_pointer(p, v) \ |
108 |
({ \ |
({ \ |
109 |
if (!__builtin_constant_p(v) || \ |
if (!__builtin_constant_p(v) || \ |
110 |
((v) != NULL)) \ |
((v) != NULL)) \ |
111 |
smp_wmb(); /* see RCU */ \ |
smp_wmb(); /* see RCU */ \ |
112 |
(p) = (v); \ |
(p) = (v); \ |
113 |
}) |
}) |
114 |
#endif |
#endif |
115 |
|
|
116 |
#ifndef list_for_each_rcu |
#ifndef list_for_each_rcu |
117 |
#define list_for_each_rcu(pos, head) \ |
#define list_for_each_rcu(pos, head) \ |
118 |
for (pos = rcu_dereference((head)->next); \ |
for (pos = rcu_dereference((head)->next); \ |
119 |
prefetch(pos->next), pos != (head); \ |
prefetch(pos->next), pos != (head); \ |
120 |
pos = rcu_dereference(pos->next)) |
pos = rcu_dereference(pos->next)) |
121 |
#endif |
#endif |
122 |
|
|
123 |
#ifndef list_for_each_entry_rcu |
#ifndef list_for_each_entry_rcu |
124 |
#define list_for_each_entry_rcu(pos, head, member) \ |
#define list_for_each_entry_rcu(pos, head, member) \ |
125 |
for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), \ |
for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), \ |
126 |
member); \ |
member); \ |
127 |
prefetch(pos->member.next), &pos->member != (head); \ |
prefetch(pos->member.next), &pos->member != (head); \ |
128 |
pos = list_entry(rcu_dereference(pos->member.next), \ |
pos = list_entry(rcu_dereference(pos->member.next), \ |
129 |
typeof(*pos), member)) |
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 |
#endif |
172 |
|
|
173 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
199 |
#define sk_protocol protocol |
#define sk_protocol protocol |
200 |
#define sk_type type |
#define sk_type type |
201 |
#define sk_receive_queue receive_queue |
#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 |
239 |
|
|
240 |
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
241 |
|
|
242 |
|
struct path { |
243 |
|
struct vfsmount *mnt; |
244 |
|
struct dentry *dentry; |
245 |
|
}; |
246 |
|
|
247 |
|
#endif |
248 |
|
|
249 |
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) |
250 |
|
|
251 |
|
#include <linux/mount.h> |
252 |
|
|
253 |
|
static inline void path_get(struct path *path) |
254 |
|
{ |
255 |
|
dget(path->dentry); |
256 |
|
mntget(path->mnt); |
257 |
|
} |
258 |
|
|
259 |
|
static inline void path_put(struct path *path) |
260 |
|
{ |
261 |
|
dput(path->dentry); |
262 |
|
mntput(path->mnt); |
263 |
|
} |
264 |
|
|
265 |
#endif |
#endif |