77abefd74be9b7188ee704fc35938de075ad2654
[openafs.git] / src / afs / LINUX / osi_module.c
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 module support routines.
12  *
13  */
14 #include <afsconfig.h>
15 #include "afs/param.h"
16
17 RCSID
18     ("$Header$");
19
20 #include "afs/sysincludes.h"
21 #include "afsincludes.h"
22 #include "h/unistd.h"           /* For syscall numbers. */
23 #include "h/mm.h"
24
25 #ifdef AFS_AMD64_LINUX20_ENV
26 #include "../asm/ia32_unistd.h"
27 #endif
28
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
32 #include <linux/init.h>
33 #include <linux/sched.h>
34 #endif
35 #if !defined(EXPORTED_SYS_CALL_TABLE) && defined(HAVE_KERNEL_LINUX_SYSCALL_H)
36 #include <linux/syscall.h>
37 #endif
38
39 #ifdef AFS_SPARC64_LINUX24_ENV
40 #define __NR_setgroups32      82        /* This number is not exported for some bizarre reason. */
41 #endif
42
43 asmlinkage int (*sys_settimeofdayp) (struct timeval * tv,
44                                      struct timezone * tz);
45 asmlinkage long (*sys_setgroupsp) (int gidsetsize, gid_t * grouplist);
46
47 #ifdef EXPORTED_SYS_CALL_TABLE
48 #ifdef AFS_SPARC64_LINUX20_ENV
49 extern unsigned int sys_call_table[];   /* changed to uint because SPARC64 has syscaltable of 32bit items */
50 #else
51 extern void *sys_call_table[];  /* safer for other linuces */
52 #endif
53 #else /* EXPORTED_SYS_CALL_TABLE */
54 #ifdef AFS_SPARC64_LINUX20_ENV
55 static unsigned int *sys_call_table;    /* changed to uint because SPARC64 has syscaltable of 32bit items */
56 #else
57 static void **sys_call_table;   /* safer for other linuces */
58 #endif
59 #endif
60 extern struct file_system_type afs_file_system;
61
62 static long get_page_offset(void);
63
64 #if defined(AFS_LINUX24_ENV)
65 DECLARE_MUTEX(afs_global_lock);
66 #else
67 struct semaphore afs_global_lock = MUTEX;
68 #endif
69 int afs_global_owner = 0;
70 unsigned long afs_linux_page_offset = 0;        /* contains the PAGE_OFFSET value */
71
72 /* Since sys_ni_syscall is not exported, I need to cache it in order to restore
73  * it.
74  */
75 #ifdef AFS_SPARC64_LINUX20_ENV
76 static unsigned int afs_ni_syscall = 0;
77 #else
78 static void *afs_ni_syscall = 0;
79 #endif
80
81 #ifdef AFS_AMD64_LINUX20_ENV
82 #ifdef EXPORTED_IA32_SYS_CALL_TABLE
83 extern void *ia32_sys_call_table[];
84 #else
85 static void **ia32_sys_call_table;
86 #endif
87
88 static void *ia32_ni_syscall = 0;
89 asmlinkage long (*sys32_setgroupsp) (int gidsetsize, u16 * grouplist);
90 #if defined(__NR_ia32_setgroups32)
91 asmlinkage long (*sys32_setgroups32p) (int gidsetsize, gid_t * grouplist);
92 #endif /* __NR_ia32_setgroups32 */
93 #endif /* AFS_AMD64_LINUX20_ENV */
94
95 #ifdef AFS_PPC64_LINUX20_ENV
96 asmlinkage long (*sys32_setgroupsp)(int gidsetsize, gid_t *grouplist);
97 #endif /* AFS_AMD64_LINUX20_ENV */
98
99 #ifdef AFS_SPARC64_LINUX20_ENV
100 static unsigned int afs_ni_syscall32 = 0;
101 asmlinkage int (*sys32_setgroupsp) (int gidsetsize,
102                                     __kernel_gid_t32 * grouplist);
103 #if defined(__NR_setgroups32)
104 asmlinkage int (*sys32_setgroups32p) (int gidsetsize,
105                                       __kernel_gid_t32 * grouplist);
106 #endif /* __NR_setgroups32 */
107 #ifdef EXPORTED_SYS_CALL_TABLE
108 extern unsigned int sys_call_table32[];
109 #else /* EXPORTED_SYS_CALL_TABLE */
110 static unsigned int *sys_call_table32;
111 #endif /* EXPORTED_SYS_CALL_TABLE */
112
113 asmlinkage int
114 afs_syscall32(long syscall, long parm1, long parm2, long parm3, long parm4,
115               long parm5)
116 {
117     __asm__ __volatile__("srl %o4, 0, %o4\n\t" "mov %o7, %i7\n\t"
118                          "call afs_syscall\n\t" "srl %o5, 0, %o5\n\t"
119                          "ret\n\t" "nop");
120 }
121 #endif /* AFS_SPARC64_LINUX20_ENV */
122
123 #ifdef AFS_IA64_LINUX20_ENV
124
125 asmlinkage long
126 afs_syscall_stub(int r0, int r1, long r2, long r3, long r4, long gp)
127 {
128     __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" "mov r41 = b0\n\t"        /* save rp */
129                          "mov out0 = in0\n\t" "mov out1 = in1\n\t" "mov out2 = in2\n\t" "mov out3 = in3\n\t" "mov out4 = in4\n\t" "mov out5 = gp\n\t"   /* save gp */
130                          ";;\n" ".L1:    mov r3 = ip\n\t" ";;\n\t" "addl r15=.fptr_afs_syscall-.L1,r3\n\t" ";;\n\t" "ld8 r15=[r15]\n\t" ";;\n\t" "ld8 r16=[r15],8\n\t" ";;\n\t" "ld8 gp=[r15]\n\t" "mov b6=r16\n\t" "br.call.sptk.many b0 = b6\n\t" ";;\n\t" "mov ar.pfs = r42\n\t" "mov b0 = r41\n\t" "mov gp = r48\n\t"       /* restore gp */
131                          "br.ret.sptk.many b0\n" ".fptr_afs_syscall:\n\t"
132                          "data8 @fptr(afs_syscall)");
133 }
134
135 asmlinkage long
136 afs_xsetgroups_stub(int r0, int r1, long r2, long r3, long r4, long gp)
137 {
138     __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" "mov r41 = b0\n\t"        /* save rp */
139                          "mov out0 = in0\n\t" "mov out1 = in1\n\t" "mov out2 = in2\n\t" "mov out3 = in3\n\t" "mov out4 = in4\n\t" "mov out5 = gp\n\t"   /* save gp */
140                          ";;\n" ".L2:    mov r3 = ip\n\t" ";;\n\t" "addl r15=.fptr_afs_xsetgroups - .L2,r3\n\t" ";;\n\t" "ld8 r15=[r15]\n\t" ";;\n\t" "ld8 r16=[r15],8\n\t" ";;\n\t" "ld8 gp=[r15]\n\t" "mov b6=r16\n\t" "br.call.sptk.many b0 = b6\n\t" ";;\n\t" "mov ar.pfs = r42\n\t" "mov b0 = r41\n\t" "mov gp = r48\n\t"  /* restore gp */
141                          "br.ret.sptk.many b0\n" ".fptr_afs_xsetgroups:\n\t"
142                          "data8 @fptr(afs_xsetgroups)");
143 }
144
145 struct fptr {
146     void *ip;
147     unsigned long gp;
148 };
149
150 #endif /* AFS_IA64_LINUX20_ENV */
151
152 #ifdef AFS_LINUX24_ENV
153 asmlinkage int (*sys_setgroups32p) (int gidsetsize,
154                                     __kernel_gid32_t * grouplist);
155 #endif /* AFS_LINUX24_ENV */
156
157 #ifdef AFS_SPARC64_LINUX20_ENV
158 #define POINTER2SYSCALL (unsigned int)(unsigned long)
159 #define SYSCALL2POINTER (void *)(long)
160 #else
161 #define POINTER2SYSCALL (void *)
162 #define SYSCALL2POINTER (void *)
163 #endif
164
165 #ifdef AFS_PPC64_LINUX20_ENV
166 extern void *set_afs_syscall(void*);
167 extern void *set_afs_xsetgroups_syscall(void*);
168 extern void *set_afs_xsetgroups_syscall32(void*);
169 #endif
170
171 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
172 int __init
173 afs_init(void)
174 #else
175 int
176 init_module(void)
177 #endif
178 {
179 #if defined(AFS_IA64_LINUX20_ENV)
180     unsigned long kernel_gp = 0;
181     static struct fptr sys_settimeofday, sys_setgroups;
182 #endif
183     extern int afs_syscall();
184     extern long afs_xsetgroups();
185 #if defined(__NR_setgroups32)
186     extern int afs_xsetgroups32();
187 #endif /* __NR_setgroups32 */
188 #if defined(AFS_SPARC64_LINUX20_ENV) || defined (AFS_AMD64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
189     extern int afs32_xsetgroups();
190 #if (defined(__NR_setgroups32) && defined(AFS_SPARC64_LINUX20_ENV))
191     extern int afs32_xsetgroups32();
192 #endif
193 #if (defined(__NR_ia32_setgroups32) && defined(AFS_AMD64_LINUX20_ENV))
194     extern int afs32_xsetgroups32();
195 #endif
196 #endif /* AFS_SPARC64_LINUX20_ENV || AFS_AMD64_LINUX20_ENV */
197
198 #if !defined(EXPORTED_SYS_CALL_TABLE) || (defined(AFS_AMD64_LINUX20_ENV) && !defined(EXPORTED_IA32_SYS_CALL_TABLE))
199     unsigned long *ptr;
200     unsigned long offset=0;
201     unsigned long datalen=0;
202     int ret;
203     unsigned long token=0;
204     char *mod_name;
205     unsigned long mod_start=0;
206     unsigned long mod_end=0;
207     char *sec_name;
208     unsigned long sec_start=0;
209     unsigned long sec_end=0;
210     char *sym_name;
211     unsigned long sym_start=0;
212     unsigned long sym_end=0;
213 #endif /* EXPORTED_SYS_CALL_TABLE */
214
215     RWLOCK_INIT(&afs_xosi, "afs_xosi");
216
217     /* obtain PAGE_OFFSET value */
218     afs_linux_page_offset = get_page_offset();
219
220 #ifndef AFS_S390_LINUX22_ENV
221     if (afs_linux_page_offset == 0) {
222         /* couldn't obtain page offset so can't continue */
223         printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
224         return -EIO;
225     }
226 #endif
227 #ifndef EXPORTED_SYS_CALL_TABLE
228     sys_call_table = 0;
229
230 #ifdef EXPORTED_KALLSYMS_SYMBOL
231     ret = 1;
232     token = 0;
233     while (ret) {
234         sym_start = 0;
235         ret =
236             kallsyms_symbol_to_address("sys_call_table", &token, &mod_name,
237                                        &mod_start, &mod_end, &sec_name,
238                                        &sec_start, &sec_end, &sym_name,
239                                        &sym_start, &sym_end);
240         if (ret && !strcmp(mod_name, "kernel"))
241             break;
242     }
243     if (ret && sym_start) {
244         sys_call_table = sym_start;
245     }
246 #else
247 #ifdef EXPORTED_KALLSYMS_ADDRESS
248     ret =
249         kallsyms_address_to_symbol((unsigned long)&init_mm, &mod_name,
250                                    &mod_start, &mod_end, &sec_name,
251                                    &sec_start, &sec_end, &sym_name,
252                                    &sym_start, &sym_end);
253     ptr = (unsigned long *)sec_start;
254     datalen = (sec_end - sec_start) / sizeof(unsigned long);
255 #else
256 #if defined(AFS_IA64_LINUX20_ENV)
257     ptr = (unsigned long *)(&sys_close - 0x180000);
258     datalen = 0x180000 / sizeof(ptr);
259 #else
260 #if defined(AFS_AMD64_LINUX20_ENV)
261     ptr = (unsigned long *)&init_mm;
262     datalen = 0x360000 / sizeof(ptr);
263 #else
264     ptr = (unsigned long *)&init_mm;
265     datalen = 16384;
266 #endif
267 #endif
268 #endif
269     for (offset = 0; offset < datalen; ptr++, offset++) {
270 #if defined(AFS_IA64_LINUX20_ENV)
271         unsigned long close_ip =
272             (unsigned long)((struct fptr *)&sys_close)->ip;
273         unsigned long chdir_ip =
274             (unsigned long)((struct fptr *)&sys_chdir)->ip;
275         unsigned long write_ip =
276             (unsigned long)((struct fptr *)&sys_write)->ip;
277         if (ptr[0] == close_ip && ptr[__NR_chdir - __NR_close] == chdir_ip
278             && ptr[__NR_write - __NR_close] == write_ip) {
279             sys_call_table = (void *)&(ptr[-1 * (__NR_close - 1024)]);
280             break;
281         }
282 #else
283 #if defined(EXPORTED_SYS_WAIT4) && defined(EXPORTED_SYS_CLOSE)
284         if (ptr[0] == (unsigned long)&sys_close
285             && ptr[__NR_wait4 - __NR_close] == (unsigned long)&sys_wait4) {
286             sys_call_table = ptr - __NR_close;
287             break;
288         }
289 #else
290 #if defined(EXPORTED_SYS_CHDIR) && defined(EXPORTED_SYS_CLOSE)
291         if (ptr[0] == (unsigned long)&sys_close
292             && ptr[__NR_chdir - __NR_close] == (unsigned long)&sys_chdir) {
293             sys_call_table = ptr - __NR_close;
294             break;
295         }
296 #else
297         if (ptr[0] == (unsigned long)&sys_exit
298             && ptr[__NR_open - __NR_exit] == (unsigned long)&sys_open) {
299             sys_call_table = ptr - __NR_exit;
300             break;
301         }
302 #endif
303 #endif
304 #endif
305     }
306 #ifdef EXPORTED_KALLSYMS_ADDRESS
307     ret =
308         kallsyms_address_to_symbol((unsigned long)sys_call_table, &mod_name,
309                                    &mod_start, &mod_end, &sec_name,
310                                    &sec_start, &sec_end, &sym_name,
311                                    &sym_start, &sym_end);
312     if (ret && strcmp(sym_name, "sys_call_table"))
313         sys_call_table = 0;
314 #endif
315 #endif
316     if (!sys_call_table) {
317         printf("Failed to find address of sys_call_table\n");
318         return -EIO;
319     }
320     printf("Found sys_call_table at %x\n", sys_call_table);
321 # ifdef AFS_SPARC64_LINUX20_ENV
322     error cant support this yet.
323 #endif
324 #endif                          /* EXPORTED_SYS_CALL_TABLE */
325 #ifdef AFS_AMD64_LINUX20_ENV
326 #ifndef EXPORTED_IA32_SYS_CALL_TABLE
327       ia32_sys_call_table = 0;
328 #ifdef EXPORTED_KALLSYMS_SYMBOL
329     ret = 1;
330     token = 0;
331     while (ret) {
332         sym_start = 0;
333         ret =
334             kallsyms_symbol_to_address("ia32_sys_call_table", &token,
335                                        &mod_name, &mod_start, &mod_end,
336                                        &sec_name, &sec_start, &sec_end,
337                                        &sym_name, &sym_start, &sym_end);
338         if (ret && !strcmp(mod_name, "kernel"))
339             break;
340     }
341     if (ret && sym_start) {
342         ia32_sys_call_table = sym_start;
343     }
344 #else /* EXPORTED_KALLSYMS_SYMBOL */
345 #ifdef EXPORTED_KALLSYMS_ADDRESS
346     ret =
347         kallsyms_address_to_symbol((unsigned long)&interruptible_sleep_on,
348                                    &mod_name, &mod_start, &mod_end, &sec_name,
349                                    &sec_start, &sec_end, &sym_name,
350                                    &sym_start, &sym_end);
351     ptr = (unsigned long *)sec_start;
352     datalen = (sec_end - sec_start) / sizeof(unsigned long);
353 #else /* EXPORTED_KALLSYMS_ADDRESS */
354 #if defined(AFS_AMD64_LINUX20_ENV)
355     ptr = (unsigned long *)&interruptible_sleep_on;
356     datalen = 0x180000 / sizeof(ptr);
357 #else /* AFS_AMD64_LINUX20_ENV */
358     ptr = (unsigned long *)&interruptible_sleep_on;
359     datalen = 16384;
360 #endif /* AFS_AMD64_LINUX20_ENV */
361 #endif /* EXPORTED_KALLSYMS_ADDRESS */
362     for (offset = 0; offset < datalen; ptr++, offset++) {
363         if (ptr[0] == (unsigned long)&sys_exit
364             && ptr[__NR_ia32_open - __NR_ia32_exit] ==
365             (unsigned long)&sys_open) {
366             ia32_sys_call_table = ptr - __NR_ia32_exit;
367             break;
368         }
369     }
370 #ifdef EXPORTED_KALLSYMS_ADDRESS
371     ret =
372         kallsyms_address_to_symbol((unsigned long)ia32_sys_call_table,
373                                    &mod_name, &mod_start, &mod_end, &sec_name,
374                                    &sec_start, &sec_end, &sym_name,
375                                    &sym_start, &sym_end);
376     if (ret && strcmp(sym_name, "ia32_sys_call_table"))
377         ia32_sys_call_table = 0;
378 #endif /* EXPORTED_KALLSYMS_ADDRESS */
379 #endif /* EXPORTED_KALLSYMS_SYMBOL */
380     if (!ia32_sys_call_table) {
381         printf("Warning: Failed to find address of ia32_sys_call_table\n");
382     } else {
383         printf("Found ia32_sys_call_table at %x\n", ia32_sys_call_table);
384     }
385 #else
386     printf("Found ia32_sys_call_table at %x\n", ia32_sys_call_table);
387 #endif /* IA32_SYS_CALL_TABLE */
388 #endif
389
390     /* Initialize pointers to kernel syscalls. */
391 #if defined(AFS_IA64_LINUX20_ENV)
392     kernel_gp = ((struct fptr *)printk)->gp;
393
394     sys_settimeofdayp = (void *)&sys_settimeofday;
395
396     ((struct fptr *)sys_settimeofdayp)->ip =
397         SYSCALL2POINTER sys_call_table[__NR_settimeofday - 1024];
398     ((struct fptr *)sys_settimeofdayp)->gp = kernel_gp;
399
400 #else /* !AFS_IA64_LINUX20_ENV */
401     sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday];
402 #endif /* AFS_IA64_LINUX20_ENV */
403
404     /* setup AFS entry point. */
405     if (
406 #if defined(AFS_IA64_LINUX20_ENV)
407            SYSCALL2POINTER sys_call_table[__NR_afs_syscall - 1024]
408 #else
409            SYSCALL2POINTER sys_call_table[__NR_afs_syscall]
410 #endif
411            == afs_syscall) {
412         printf("AFS syscall entry point already in use!\n");
413         return -EBUSY;
414     }
415 #if defined(AFS_IA64_LINUX20_ENV)
416     afs_ni_syscall = sys_call_table[__NR_afs_syscall - 1024];
417     sys_call_table[__NR_afs_syscall - 1024] =
418         POINTER2SYSCALL((struct fptr *)afs_syscall_stub)->ip;
419 #else /* AFS_IA64_LINUX20_ENV */
420     afs_ni_syscall = sys_call_table[__NR_afs_syscall];
421     sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall;
422 # ifdef AFS_SPARC64_LINUX20_ENV
423     afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall];
424     sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
425 # endif
426 #endif /* AFS_IA64_LINUX20_ENV */
427 #ifdef AFS_AMD64_LINUX20_ENV
428     if (ia32_sys_call_table) {
429         ia32_ni_syscall = ia32_sys_call_table[__NR_ia32_afs_syscall];
430         ia32_sys_call_table[__NR_ia32_afs_syscall] =
431             POINTER2SYSCALL afs_syscall;
432     }
433 #endif /* AFS_S390_LINUX22_ENV */
434
435     osi_Init();
436     register_filesystem(&afs_file_system);
437
438     /* Intercept setgroups calls */
439 #if defined(AFS_IA64_LINUX20_ENV)
440     sys_setgroupsp = (void *)&sys_setgroups;
441
442     ((struct fptr *)sys_setgroupsp)->ip =
443         SYSCALL2POINTER sys_call_table[__NR_setgroups - 1024];
444     ((struct fptr *)sys_setgroupsp)->gp = kernel_gp;
445
446     sys_call_table[__NR_setgroups - 1024] =
447         POINTER2SYSCALL((struct fptr *)afs_xsetgroups_stub)->ip;
448 #else /* AFS_IA64_LINUX20_ENV */
449     sys_setgroupsp = SYSCALL2POINTER sys_call_table[__NR_setgroups];
450     sys_call_table[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups;
451 #ifdef AFS_SPARC64_LINUX20_ENV
452     sys32_setgroupsp = SYSCALL2POINTER sys_call_table32[__NR_setgroups];
453     sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs32_xsetgroups;
454 #endif /* AFS_SPARC64_LINUX20_ENV */
455 #if defined(__NR_setgroups32)
456     sys_setgroups32p = SYSCALL2POINTER sys_call_table[__NR_setgroups32];
457     sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32;
458 #ifdef AFS_SPARC64_LINUX20_ENV
459     sys32_setgroups32p = SYSCALL2POINTER sys_call_table32[__NR_setgroups32];
460     sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL afs32_xsetgroups32;
461 #endif /* AFS_SPARC64_LINUX20_ENV */
462 #endif /* __NR_setgroups32 */
463 #ifdef AFS_AMD64_LINUX20_ENV
464     if (ia32_sys_call_table) {
465         sys32_setgroupsp =
466             SYSCALL2POINTER ia32_sys_call_table[__NR_ia32_setgroups];
467         ia32_sys_call_table[__NR_ia32_setgroups] =
468             POINTER2SYSCALL afs32_xsetgroups;
469 #if defined(__NR_ia32_setgroups32)
470         sys32_setgroups32p =
471             SYSCALL2POINTER ia32_sys_call_table[__NR_ia32_setgroups32];
472         ia32_sys_call_table[__NR_ia32_setgroups32] =
473             POINTER2SYSCALL afs32_xsetgroups32;
474 #endif /* __NR_ia32_setgroups32 */
475     }
476 #endif /* AFS_AMD64_LINUX20_ENV */
477 #endif /* AFS_IA64_LINUX20_ENV */
478
479 #ifdef AFS_PPC64_LINUX20_ENV
480     afs_ni_syscall = set_afs_syscall(afs_syscall);
481     sys_setgroupsp = set_afs_xsetgroups_syscall(afs_xsetgroups);
482     sys32_setgroupsp = set_afs_xsetgroups_syscall32(afs32_xsetgroups);
483 #endif
484
485     osi_sysctl_init();
486
487     return 0;
488 }
489
490 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
491 void __exit
492 afs_cleanup(void)
493 #else
494 void
495 cleanup_module(void)
496 #endif
497 {
498     struct task_struct *t;
499
500     osi_sysctl_clean();
501
502 #if defined(AFS_IA64_LINUX20_ENV)
503     sys_call_table[__NR_setgroups - 1024] =
504         POINTER2SYSCALL((struct fptr *)sys_setgroupsp)->ip;
505     sys_call_table[__NR_afs_syscall - 1024] = afs_ni_syscall;
506 #else /* AFS_IA64_LINUX20_ENV */
507     sys_call_table[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp;
508     sys_call_table[__NR_afs_syscall] = afs_ni_syscall;
509 # ifdef AFS_SPARC64_LINUX20_ENV
510     sys_call_table32[__NR_setgroups] = POINTER2SYSCALL sys32_setgroupsp;
511     sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
512 # endif
513 # if defined(__NR_setgroups32)
514     sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p;
515 # ifdef AFS_SPARC64_LINUX20_ENV
516     sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL sys32_setgroups32p;
517 # endif
518 # endif
519 #endif /* AFS_IA64_LINUX20_ENV */
520 #ifdef AFS_AMD64_LINUX20_ENV
521     if (ia32_sys_call_table) {
522         ia32_sys_call_table[__NR_ia32_setgroups] =
523             POINTER2SYSCALL sys32_setgroupsp;
524         ia32_sys_call_table[__NR_ia32_afs_syscall] =
525             POINTER2SYSCALL ia32_ni_syscall;
526 # if defined(__NR_setgroups32)
527         ia32_sys_call_table[__NR_ia32_setgroups32] =
528             POINTER2SYSCALL sys32_setgroups32p;
529 #endif
530     }
531 #endif
532 #ifdef AFS_PPC64_LINUX20_ENV
533     set_afs_syscall(afs_ni_syscall);
534     set_afs_xsetgroups_syscall(sys_setgroupsp);
535     set_afs_xsetgroups_syscall32(sys32_setgroupsp);
536 #endif
537     unregister_filesystem(&afs_file_system);
538
539     osi_linux_free_inode_pages();       /* Invalidate all pages using AFS inodes. */
540     osi_linux_free_afs_memory();
541
542     return;
543 }
544
545 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
546 module_init(afs_init);
547 module_exit(afs_cleanup);
548 #endif
549
550
551 static long
552 get_page_offset(void)
553 {
554 #if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV) || defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PARISC_LINUX24_ENV) || defined(AFS_AMD64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
555     return PAGE_OFFSET;
556 #else
557     struct task_struct *p, *q;
558
559     /* search backward thru the circular list */
560 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
561     read_lock(&tasklist_lock);
562 #endif
563     /* search backward thru the circular list */
564 #ifdef DEFINED_PREV_TASK
565     for (q = current; p = q; q = prev_task(p)) {
566 #else
567     for (p = current; p; p = p->prev_task) {
568 #endif
569         if (p->pid == 1) {
570 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
571             read_unlock(&tasklist_lock);
572 #endif
573             return p->addr_limit.seg;
574         }
575     }
576
577 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
578     read_unlock(&tasklist_lock);
579 #endif
580     return 0;
581 #endif
582 }