amd64-linux-missing-syscall-nrs-20060916
[openafs.git] / src / afs / LINUX / osi_machdep.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Linux implementation.
12  *
13  */
14
15 #ifndef OSI_MACHDEP_H_
16 #define OSI_MACHDEP_H_
17
18 /* Only needed for xdr.h in glibc 2.1.x */
19 #ifndef quad_t
20 #define quad_t __quad_t
21 #define u_quad_t __u_quad_t
22 #endif
23
24 #undef getuerror
25
26 #define getpid() current->pid
27 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
28 #define getppid() current->real_parent->pid
29 #elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
30 #define getppid() current->parent->pid
31 #else
32 #define getppid() current->p_opptr->pid
33 #endif
34
35 #ifdef RECALC_SIGPENDING_TAKES_VOID
36 #define RECALC_SIGPENDING(X) recalc_sigpending()
37 #else
38 #define RECALC_SIGPENDING(X) recalc_sigpending(X)
39 #endif
40
41 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK)
42 #define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
43 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
44 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND)
45 #define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
46 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
47 #else
48 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
49 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
50 #endif
51
52 #if defined (STRUCT_TASK_STRUCT_HAS_RLIM)
53 #define TASK_STRUCT_RLIM rlim
54 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM)
55 #define TASK_STRUCT_RLIM signal->rlim
56 #else
57 #error Not sure what to do about rlim (should be in the Linux task struct somewhere....)
58 #endif
59
60
61 #define afs_hz HZ
62 #include "h/sched.h"
63 #define osi_Time() (xtime.tv_sec)
64 #ifdef AFS_LINUX_64BIT_KERNEL
65 #define osi_GetTime(V)                                 \
66     do {                                               \
67        struct timeval __afs_tv;                              \
68        do_gettimeofday(&__afs_tv);                           \
69        (V)->tv_sec = (afs_int32)__afs_tv.tv_sec;             \
70        (V)->tv_usec = (afs_int32)__afs_tv.tv_usec;           \
71     } while (0)
72 #else
73 #define osi_GetTime(V) do_gettimeofday((V))
74 #endif
75
76 #undef gop_lookupname
77 #define gop_lookupname osi_lookupname
78
79 #define osi_vnhold(V, N) do { VN_HOLD(AFSTOV(V)); } while (0)
80 #define VN_HOLD(V) osi_Assert(igrab((V)) == (V))
81 #define VN_RELE(V) iput((V))
82
83 #define afs_suser(x) capable(CAP_SYS_ADMIN)
84 #define wakeup afs_osi_Wakeup
85
86 #undef vType
87 #define vType(V) ((AFSTOV((V)))->i_mode & S_IFMT)
88 #undef vSetType
89 #define vSetType(V, type) AFSTOV((V))->i_mode = ((type) | (AFSTOV((V))->i_mode & ~S_IFMT))      /* preserve mode */
90
91 #undef IsAfsVnode
92 #define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS)      /* test superblock instead */
93 #undef SetAfsVnode
94 #define SetAfsVnode(V)                                  /* unnecessary */
95
96 /* We often need to pretend we're in user space to get memory transfers
97  * right for the kernel calls we use.
98  */
99 #include <asm/uaccess.h>
100
101 #ifdef KERNEL_SPACE_DECL
102 #undef KERNEL_SPACE_DECL
103 #undef TO_USER_SPACE
104 #undef TO_KERNEL_SPACE
105 #endif
106 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
107 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
108 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
109
110 #define copyin(F, T, C)  (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
111 static inline long copyinstr(char *from, char *to, int count, int *length) {
112     long tmp;
113     tmp = strncpy_from_user(to, from, count);
114     if (tmp < 0)
115             return EFAULT;
116     *length = tmp;
117     return 0;
118 }
119 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
120
121 /* kernel print statements */
122 #define printf printk
123 #define uprintf printk
124
125
126 #define PAGESIZE PAGE_SIZE
127 #ifndef NGROUPS
128 #define NGROUPS NGROUPS_SMALL
129 #endif
130
131 /* cred struct */
132 typedef struct cred {           /* maps to task field: */
133     int cr_ref;
134     uid_t cr_uid;               /* euid */
135     uid_t cr_ruid;              /* uid */
136     gid_t cr_gid;               /* egid */
137     gid_t cr_rgid;              /* gid */
138 #if defined(AFS_LINUX26_ENV)
139     struct group_info *cr_group_info;
140 #else
141     gid_t cr_groups[NGROUPS];   /* 32 groups - empty set to NOGROUP */
142     int cr_ngroups;
143 #endif
144     struct cred *cr_next;
145 } cred_t;
146 #define AFS_UCRED cred
147 #define AFS_PROC struct task_struct
148 #define crhold(c) (c)->cr_ref++
149
150 /* UIO manipulation */
151 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
152 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
153 typedef struct uio {
154     struct iovec *uio_iov;
155     int uio_iovcnt;
156     afs_offs_t uio_offset;
157     uio_seg_t uio_seg;
158     int uio_resid;
159     uio_flag_t uio_flag;
160 } uio_t;
161 #define afsio_iov       uio_iov
162 #define afsio_iovcnt    uio_iovcnt
163 #define afsio_offset    uio_offset
164 #define afsio_seg       uio_segflg
165 #define afsio_fmode     uio_fmode
166 #define afsio_resid     uio_resid
167
168 /* Get/set the inode in the osifile struct. */
169 #define FILE_INODE(F) (F)->f_dentry->d_inode
170
171 #ifdef AFS_LINUX26_ENV
172 #define OSIFILE_INODE(a) FILE_INODE((a)->filp)
173 #else
174 #define OSIFILE_INODE(a) FILE_INODE(&(a)->file)
175 #endif
176
177 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
178 #define NEED_IOCTL32
179 #endif
180
181 /* page offset is obtained and stored here during module initialization 
182  * We need a variable to do this because, the PAGE_OFFSET macro defined in
183  * include/asm/page.h can change from kernel to kernel and we cannot use
184  * the hardcoded version.
185  */
186 extern unsigned long afs_linux_page_offset;
187
188 /* function to help with the page offset stuff */
189 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
190
191 #if defined(__KERNEL__)
192 #include <linux/version.h>
193 #include <linux/sched.h>
194 #include <linux/wait.h>
195
196 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
197 extern struct mutex afs_global_lock;
198 #else
199 extern struct semaphore afs_global_lock;
200 #define mutex_lock(lock) down(lock)
201 #define mutex_unlock(lock) up(lock)
202 #endif
203 extern int afs_global_owner;
204
205 #define AFS_GLOCK() \
206 do { \
207          mutex_lock(&afs_global_lock); \
208          if (afs_global_owner) \
209              osi_Panic("afs_global_lock already held by pid %d", \
210                        afs_global_owner); \
211          afs_global_owner = current->pid; \
212 } while (0)
213
214 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
215
216 #define AFS_GUNLOCK() \
217 do { \
218     if (!ISAFS_GLOCK()) \
219         osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
220     afs_global_owner = 0; \
221     mutex_unlock(&afs_global_lock); \
222 } while (0)
223 #else
224 #define AFS_GLOCK()
225 #define AFS_GUNLOCK()
226 #define ISAFS_GLOCK() 1
227 #define AFS_ASSERT_GLOCK()
228 #endif
229
230 #ifdef AFS_AMD64_LINUX20_ENV
231 /* RHEL5 beta's kernel doesn't define these. They aren't gonna change, so... */
232
233 #ifndef __NR_ia32_afs_syscall
234 #define __NR_ia32_afs_syscall 137
235 #endif
236 #ifndef __NR_ia32_setgroups
237 #define __NR_ia32_setgroups 81
238 #endif
239 #ifndef __NR_ia32_setgroups32
240 #define __NR_ia32_setgroups32 206
241 #endif
242 #ifndef __NR_ia32_close
243 #define __NR_ia32_close 6
244 #endif
245 #ifndef __NR_ia32_chdir
246 #define __NR_ia32_chdir 12
247 #endif
248 #ifndef __NR_ia32_break
249 #define __NR_ia32_break 17
250 #endif
251 #ifndef __NR_ia32_stty
252 #define __NR_ia32_stty 31
253 #endif
254 #ifndef __NR_ia32_gtty
255 #define __NR_ia32_gtty 32
256 #endif
257 #ifndef __NR_ia32_ftime
258 #define __NR_ia32_ftime 35
259 #endif
260 #ifndef __NR_ia32_prof
261 #define __NR_ia32_prof 44
262 #endif
263 #ifndef __NR_ia32_lock
264 #define __NR_ia32_lock 53
265 #endif
266 #ifndef __NR_ia32_mpx
267 #define __NR_ia32_mpx 56
268 #endif
269 #ifndef __NR_ia32_exit
270 #define __NR_ia32_exit 1
271 #endif
272 #ifndef __NR_ia32_mount
273 #define __NR_ia32_mount 21
274 #endif
275 #ifndef __NR_ia32_read
276 #define __NR_ia32_read 3
277 #endif
278 #ifndef __NR_ia32_write
279 #define __NR_ia32_write 4
280 #endif
281 #ifndef __NR_ia32_open
282 #define __NR_ia32_open 5
283 #endif
284 #ifndef __NR_ia32_close
285 #define __NR_ia32_close 6
286 #endif
287 #ifndef __NR_ia32_unlink
288 #define __NR_ia32_unlink 10
289 #endif
290 #endif
291
292 #endif /* OSI_MACHDEP_H_ */