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.8-pre 2009/05/08 |
* Version: 1.7.0 2009/10/01 |
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. |
64 |
#define mutex_lock(mutex) down(mutex) |
#define mutex_lock(mutex) down(mutex) |
65 |
#define mutex_unlock(mutex) up(mutex) |
#define mutex_unlock(mutex) up(mutex) |
66 |
#define mutex_lock_interruptible(mutex) down_interruptible(mutex) |
#define mutex_lock_interruptible(mutex) down_interruptible(mutex) |
67 |
|
#define mutex_trylock(mutex) !down_trylock(mutex) |
68 |
#define DEFINE_MUTEX(mutexname) DECLARE_MUTEX(mutexname) |
#define DEFINE_MUTEX(mutexname) DECLARE_MUTEX(mutexname) |
69 |
#endif |
#endif |
70 |
|
|
75 |
#endif |
#endif |
76 |
|
|
77 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) |
78 |
#define kzalloc(size, flags) ({ \ |
#define kzalloc(size, flags) ({ \ |
79 |
void *ret = kmalloc((size), (flags)); \ |
void *ret = kmalloc((size), (flags)); \ |
80 |
if (ret) \ |
if (ret) \ |
81 |
memset(ret, 0, (size)); \ |
memset(ret, 0, (size)); \ |
82 |
ret; }) |
ret; }) |
83 |
#endif |
#endif |
84 |
|
|
91 |
#endif |
#endif |
92 |
|
|
93 |
#ifndef rcu_dereference |
#ifndef rcu_dereference |
94 |
#define rcu_dereference(p) ({ \ |
#define rcu_dereference(p) ({ \ |
95 |
typeof(p) _________p1 = ACCESS_ONCE(p); \ |
typeof(p) _________p1 = ACCESS_ONCE(p); \ |
96 |
smp_read_barrier_depends(); /* see RCU */ \ |
smp_read_barrier_depends(); /* see RCU */ \ |
97 |
(_________p1); \ |
(_________p1); \ |
98 |
}) |
}) |
99 |
#endif |
#endif |
100 |
|
|
101 |
#ifndef rcu_assign_pointer |
#ifndef rcu_assign_pointer |
102 |
#define rcu_assign_pointer(p, v) \ |
#define rcu_assign_pointer(p, v) \ |
103 |
({ \ |
({ \ |
104 |
if (!__builtin_constant_p(v) || \ |
if (!__builtin_constant_p(v) || \ |
105 |
((v) != NULL)) \ |
((v) != NULL)) \ |
106 |
smp_wmb(); /* see RCU */ \ |
smp_wmb(); /* see RCU */ \ |
107 |
(p) = (v); \ |
(p) = (v); \ |
108 |
}) |
}) |
109 |
#endif |
#endif |
110 |
|
|
111 |
#ifndef list_for_each_rcu |
#ifndef list_for_each_rcu |
112 |
#define list_for_each_rcu(pos, head) \ |
#define list_for_each_rcu(pos, head) \ |
113 |
for (pos = rcu_dereference((head)->next); \ |
for (pos = rcu_dereference((head)->next); \ |
114 |
prefetch(pos->next), pos != (head); \ |
prefetch(pos->next), pos != (head); \ |
115 |
pos = rcu_dereference(pos->next)) |
pos = rcu_dereference(pos->next)) |
116 |
#endif |
#endif |
117 |
|
|
118 |
#ifndef list_for_each_entry_rcu |
#ifndef list_for_each_entry_rcu |
119 |
#define list_for_each_entry_rcu(pos, head, member) \ |
#define list_for_each_entry_rcu(pos, head, member) \ |
120 |
for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), \ |
for (pos = list_entry(rcu_dereference((head)->next), typeof(*pos), \ |
121 |
member); \ |
member); \ |
122 |
prefetch(pos->member.next), &pos->member != (head); \ |
prefetch(pos->member.next), &pos->member != (head); \ |
123 |
pos = list_entry(rcu_dereference(pos->member.next), \ |
pos = list_entry(rcu_dereference(pos->member.next), \ |
124 |
typeof(*pos), member)) |
typeof(*pos), member)) |
125 |
#endif |
#endif |
126 |
|
|
127 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
128 |
#define s_fs_info u.generic_sbp |
static inline void __list_add_rcu(struct list_head *new, |
129 |
#else |
struct list_head *prev, |
130 |
#include <linux/audit.h> |
struct list_head *next) |
131 |
#ifdef AUDIT_APPARMOR_AUDIT |
{ |
132 |
/* AppArmor patch adds "struct vfsmount" to VFS helper functions. */ |
new->next = next; |
133 |
#define HAVE_VFSMOUNT_IN_VFS_HELPER |
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 |
#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 |
#endif |
159 |
|
|
160 |
#if defined(RHEL_MAJOR) && RHEL_MAJOR == 5 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 30) |
161 |
#define HAVE_NO_I_BLKSIZE_IN_INODE |
#undef ssleep |
162 |
#elif defined(AX_MAJOR) && AX_MAJOR == 3 |
#define ssleep(secs) { \ |
163 |
#define HAVE_NO_I_BLKSIZE_IN_INODE |
set_current_state(TASK_UNINTERRUPTIBLE); \ |
164 |
|
schedule_timeout((HZ * secs) + 1); \ |
165 |
|
} |
166 |
|
#endif |
167 |
|
|
168 |
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
169 |
|
#define s_fs_info u.generic_sbp |
170 |
#endif |
#endif |
171 |
|
|
172 |
#ifndef list_for_each_entry_safe |
#ifndef list_for_each_entry_safe |
190 |
|
|
191 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30) |
192 |
#if defined(__LITTLE_ENDIAN) |
#if defined(__LITTLE_ENDIAN) |
193 |
#define HIPQUAD(addr) \ |
#define HIPQUAD(addr) \ |
194 |
((unsigned char *)&addr)[3], \ |
((unsigned char *)&addr)[3], \ |
195 |
((unsigned char *)&addr)[2], \ |
((unsigned char *)&addr)[2], \ |
196 |
((unsigned char *)&addr)[1], \ |
((unsigned char *)&addr)[1], \ |
197 |
((unsigned char *)&addr)[0] |
((unsigned char *)&addr)[0] |
198 |
#elif defined(__BIG_ENDIAN) |
#elif defined(__BIG_ENDIAN) |
199 |
#define HIPQUAD NIPQUAD |
#define HIPQUAD NIPQUAD |
200 |
#else |
#else |
201 |
#error "Please fix asm/byteorder.h" |
#error "Please fix asm/byteorder.h" |
202 |
#endif /* __LITTLE_ENDIAN */ |
#endif /* __LITTLE_ENDIAN */ |
203 |
#endif |
#endif |
204 |
|
|
205 |
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
206 |
|
|
207 |
|
struct path { |
208 |
|
struct vfsmount *mnt; |
209 |
|
struct dentry *dentry; |
210 |
|
}; |
211 |
|
|
212 |
|
#endif |
213 |
|
|
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 |