amd64-update-20040202
[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_SPARC64_LINUX20_ENV
96 static unsigned int afs_ni_syscall32 = 0;
97 asmlinkage int (*sys32_setgroupsp) (int gidsetsize,
98                                     __kernel_gid_t32 * grouplist);
99 #if defined(__NR_setgroups32)
100 asmlinkage int (*sys32_setgroups32p) (int gidsetsize,
101                                       __kernel_gid_t32 * grouplist);
102 #endif /* __NR_setgroups32 */
103 #ifdef EXPORTED_SYS_CALL_TABLE
104 extern unsigned int sys_call_table32[];
105 #else /* EXPORTED_SYS_CALL_TABLE */
106 static unsigned int *sys_call_table32;
107 #endif /* EXPORTED_SYS_CALL_TABLE */
108
109 asmlinkage int
110 afs_syscall32(long syscall, long parm1, long parm2, long parm3, long parm4,
111               long parm5)
112 {
113     __asm__ __volatile__("srl %o4, 0, %o4\n\t" "mov %o7, %i7\n\t"
114                          "call afs_syscall\n\t" "srl %o5, 0, %o5\n\t"
115                          "ret\n\t" "nop");
116 }
117 #endif /* AFS_SPARC64_LINUX20_ENV */
118
119 #ifdef AFS_IA64_LINUX20_ENV
120
121 asmlinkage long
122 afs_syscall_stub(int r0, int r1, long r2, long r3, long r4, long gp)
123 {
124     __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" "mov r41 = b0\n\t"        /* save rp */
125                          "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 */
126                          ";;\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 */
127                          "br.ret.sptk.many b0\n" ".fptr_afs_syscall:\n\t"
128                          "data8 @fptr(afs_syscall)");
129 }
130
131 asmlinkage long
132 afs_xsetgroups_stub(int r0, int r1, long r2, long r3, long r4, long gp)
133 {
134     __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" "mov r41 = b0\n\t"        /* save rp */
135                          "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 */
136                          ";;\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 */
137                          "br.ret.sptk.many b0\n" ".fptr_afs_xsetgroups:\n\t"
138                          "data8 @fptr(afs_xsetgroups)");
139 }
140
141 struct fptr {
142     void *ip;
143     unsigned long gp;
144 };
145
146 #endif /* AFS_IA64_LINUX20_ENV */
147
148 #ifdef AFS_LINUX24_ENV
149 asmlinkage int (*sys_setgroups32p) (int gidsetsize,
150                                     __kernel_gid32_t * grouplist);
151 #endif /* AFS_LINUX24_ENV */
152
153 #ifdef AFS_SPARC64_LINUX20_ENV
154 #define POINTER2SYSCALL (unsigned int)(unsigned long)
155 #define SYSCALL2POINTER (void *)(long)
156 #else
157 #define POINTER2SYSCALL (void *)
158 #define SYSCALL2POINTER (void *)
159 #endif
160
161 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
162 int __init
163 afs_init(void)
164 #else
165 int
166 init_module(void)
167 #endif
168 {
169 #if defined(AFS_IA64_LINUX20_ENV)
170     unsigned long kernel_gp = 0;
171     static struct fptr sys_settimeofday, sys_setgroups;
172 #endif
173     extern int afs_syscall();
174     extern long afs_xsetgroups();
175 #if defined(__NR_setgroups32)
176     extern int afs_xsetgroups32();
177 #endif /* __NR_setgroups32 */
178 #if defined(AFS_SPARC64_LINUX20_ENV) || defined (AFS_AMD64_LINUX20_ENV)
179     extern int afs32_xsetgroups();
180 #if (defined(__NR_setgroups32) && defined(AFS_SPARC64_LINUX20_ENV))
181     extern int afs32_xsetgroups32();
182 #endif
183 #if (defined(__NR_ia32_setgroups32) && defined(AFS_AMD64_LINUX20_ENV))
184     extern int afs32_xsetgroups32();
185 #endif
186 #endif /* AFS_SPARC64_LINUX20_ENV || AFS_AMD64_LINUX20_ENV */
187
188 #if !defined(EXPORTED_SYS_CALL_TABLE) || (defined(AFS_AMD64_LINUX20_ENV) && !defined(EXPORTED_IA32_SYS_CALL_TABLE))
189     unsigned long *ptr;
190     unsigned long offset=0;
191     unsigned long datalen=0;
192     int ret;
193     unsigned long token=0;
194     char *mod_name;
195     unsigned long mod_start=0;
196     unsigned long mod_end=0;
197     char *sec_name;
198     unsigned long sec_start=0;
199     unsigned long sec_end=0;
200     char *sym_name;
201     unsigned long sym_start=0;
202     unsigned long sym_end=0;
203 #endif /* EXPORTED_SYS_CALL_TABLE */
204
205     RWLOCK_INIT(&afs_xosi, "afs_xosi");
206
207     /* obtain PAGE_OFFSET value */
208     afs_linux_page_offset = get_page_offset();
209
210 #ifndef AFS_S390_LINUX22_ENV
211     if (afs_linux_page_offset == 0) {
212         /* couldn't obtain page offset so can't continue */
213         printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
214         return -EIO;
215     }
216 #endif
217 #ifndef EXPORTED_SYS_CALL_TABLE
218     sys_call_table = 0;
219
220 #ifdef EXPORTED_KALLSYMS_SYMBOL
221     ret = 1;
222     token = 0;
223     while (ret) {
224         sym_start = 0;
225         ret =
226             kallsyms_symbol_to_address("sys_call_table", &token, &mod_name,
227                                        &mod_start, &mod_end, &sec_name,
228                                        &sec_start, &sec_end, &sym_name,
229                                        &sym_start, &sym_end);
230         if (ret && !strcmp(mod_name, "kernel"))
231             break;
232     }
233     if (ret && sym_start) {
234         sys_call_table = sym_start;
235     }
236 #else
237 #ifdef EXPORTED_KALLSYMS_ADDRESS
238     ret =
239         kallsyms_address_to_symbol((unsigned long)&init_mm, &mod_name,
240                                    &mod_start, &mod_end, &sec_name,
241                                    &sec_start, &sec_end, &sym_name,
242                                    &sym_start, &sym_end);
243     ptr = (unsigned long *)sec_start;
244     datalen = (sec_end - sec_start) / sizeof(unsigned long);
245 #else
246 #if defined(AFS_IA64_LINUX20_ENV)
247     ptr = (unsigned long *)(&sys_close - 0x180000);
248     datalen = 0x180000 / sizeof(ptr);
249 #else
250 #if defined(AFS_AMD64_LINUX20_ENV)
251     ptr = (unsigned long *)&init_mm;
252     datalen = 0x360000 / sizeof(ptr);
253 #else
254     ptr = (unsigned long *)&init_mm;
255     datalen = 16384;
256 #endif
257 #endif
258 #endif
259     for (offset = 0; offset < datalen; ptr++, offset++) {
260 #if defined(AFS_IA64_LINUX20_ENV)
261         unsigned long close_ip =
262             (unsigned long)((struct fptr *)&sys_close)->ip;
263         unsigned long chdir_ip =
264             (unsigned long)((struct fptr *)&sys_chdir)->ip;
265         unsigned long write_ip =
266             (unsigned long)((struct fptr *)&sys_write)->ip;
267         if (ptr[0] == close_ip && ptr[__NR_chdir - __NR_close] == chdir_ip
268             && ptr[__NR_write - __NR_close] == write_ip) {
269             sys_call_table = (void *)&(ptr[-1 * (__NR_close - 1024)]);
270             break;
271         }
272 #else
273 #if defined(EXPORTED_SYS_WAIT4) && defined(EXPORTED_SYS_CLOSE)
274         if (ptr[0] == (unsigned long)&sys_close
275             && ptr[__NR_wait4 - __NR_close] == (unsigned long)&sys_wait4) {
276             sys_call_table = ptr - __NR_close;
277             break;
278         }
279 #else
280 #if defined(EXPORTED_SYS_CHDIR) && defined(EXPORTED_SYS_CLOSE)
281         if (ptr[0] == (unsigned long)&sys_close
282             && ptr[__NR_chdir - __NR_close] == (unsigned long)&sys_chdir) {
283             sys_call_table = ptr - __NR_close;
284             break;
285         }
286 #else
287         if (ptr[0] == (unsigned long)&sys_exit
288             && ptr[__NR_open - __NR_exit] == (unsigned long)&sys_open) {
289             sys_call_table = ptr - __NR_exit;
290             break;
291         }
292 #endif
293 #endif
294 #endif
295     }
296 #ifdef EXPORTED_KALLSYMS_ADDRESS
297     ret =
298         kallsyms_address_to_symbol((unsigned long)sys_call_table, &mod_name,
299                                    &mod_start, &mod_end, &sec_name,
300                                    &sec_start, &sec_end, &sym_name,
301                                    &sym_start, &sym_end);
302     if (ret && strcmp(sym_name, "sys_call_table"))
303         sys_call_table = 0;
304 #endif
305 #endif
306     if (!sys_call_table) {
307         printf("Failed to find address of sys_call_table\n");
308         return -EIO;
309     }
310     printf("Found sys_call_table at %x\n", sys_call_table);
311 # ifdef AFS_SPARC64_LINUX20_ENV
312     error cant support this yet.
313 #endif
314 #endif                          /* EXPORTED_SYS_CALL_TABLE */
315 #ifdef AFS_AMD64_LINUX20_ENV
316 #ifndef EXPORTED_IA32_SYS_CALL_TABLE
317       ia32_sys_call_table = 0;
318 #ifdef EXPORTED_KALLSYMS_SYMBOL
319     ret = 1;
320     token = 0;
321     while (ret) {
322         sym_start = 0;
323         ret =
324             kallsyms_symbol_to_address("ia32_sys_call_table", &token,
325                                        &mod_name, &mod_start, &mod_end,
326                                        &sec_name, &sec_start, &sec_end,
327                                        &sym_name, &sym_start, &sym_end);
328         if (ret && !strcmp(mod_name, "kernel"))
329             break;
330     }
331     if (ret && sym_start) {
332         ia32_sys_call_table = sym_start;
333     }
334 #else /* EXPORTED_KALLSYMS_SYMBOL */
335 #ifdef EXPORTED_KALLSYMS_ADDRESS
336     ret =
337         kallsyms_address_to_symbol((unsigned long)&interruptible_sleep_on,
338                                    &mod_name, &mod_start, &mod_end, &sec_name,
339                                    &sec_start, &sec_end, &sym_name,
340                                    &sym_start, &sym_end);
341     ptr = (unsigned long *)sec_start;
342     datalen = (sec_end - sec_start) / sizeof(unsigned long);
343 #else /* EXPORTED_KALLSYMS_ADDRESS */
344 #if defined(AFS_AMD64_LINUX20_ENV)
345     ptr = (unsigned long *)&interruptible_sleep_on;
346     datalen = 0x180000 / sizeof(ptr);
347 #else /* AFS_AMD64_LINUX20_ENV */
348     ptr = (unsigned long *)&interruptible_sleep_on;
349     datalen = 16384;
350 #endif /* AFS_AMD64_LINUX20_ENV */
351 #endif /* EXPORTED_KALLSYMS_ADDRESS */
352     for (offset = 0; offset < datalen; ptr++, offset++) {
353         if (ptr[0] == (unsigned long)&sys_exit
354             && ptr[__NR_ia32_open - __NR_ia32_exit] ==
355             (unsigned long)&sys_open) {
356             ia32_sys_call_table = ptr - __NR_ia32_exit;
357             break;
358         }
359     }
360 #ifdef EXPORTED_KALLSYMS_ADDRESS
361     ret =
362         kallsyms_address_to_symbol((unsigned long)ia32_sys_call_table,
363                                    &mod_name, &mod_start, &mod_end, &sec_name,
364                                    &sec_start, &sec_end, &sym_name,
365                                    &sym_start, &sym_end);
366     if (ret && strcmp(sym_name, "ia32_sys_call_table"))
367         ia32_sys_call_table = 0;
368 #endif /* EXPORTED_KALLSYMS_ADDRESS */
369 #endif /* EXPORTED_KALLSYMS_SYMBOL */
370     if (!ia32_sys_call_table) {
371         printf("Warning: Failed to find address of ia32_sys_call_table\n");
372     } else {
373         printf("Found ia32_sys_call_table at %x\n", ia32_sys_call_table);
374     }
375 #else
376     printf("Found ia32_sys_call_table at %x\n", ia32_sys_call_table);
377 #endif /* IA32_SYS_CALL_TABLE */
378 #endif
379
380     /* Initialize pointers to kernel syscalls. */
381 #if defined(AFS_IA64_LINUX20_ENV)
382     kernel_gp = ((struct fptr *)printk)->gp;
383
384     sys_settimeofdayp = (void *)&sys_settimeofday;
385
386     ((struct fptr *)sys_settimeofdayp)->ip =
387         SYSCALL2POINTER sys_call_table[__NR_settimeofday - 1024];
388     ((struct fptr *)sys_settimeofdayp)->gp = kernel_gp;
389
390 #else /* !AFS_IA64_LINUX20_ENV */
391     sys_settimeofdayp = SYSCALL2POINTER sys_call_table[__NR_settimeofday];
392 #endif /* AFS_IA64_LINUX20_ENV */
393
394     /* setup AFS entry point. */
395     if (
396 #if defined(AFS_IA64_LINUX20_ENV)
397            SYSCALL2POINTER sys_call_table[__NR_afs_syscall - 1024]
398 #else
399            SYSCALL2POINTER sys_call_table[__NR_afs_syscall]
400 #endif
401            == afs_syscall) {
402         printf("AFS syscall entry point already in use!\n");
403         return -EBUSY;
404     }
405 #if defined(AFS_IA64_LINUX20_ENV)
406     afs_ni_syscall = sys_call_table[__NR_afs_syscall - 1024];
407     sys_call_table[__NR_afs_syscall - 1024] =
408         POINTER2SYSCALL((struct fptr *)afs_syscall_stub)->ip;
409 #else /* AFS_IA64_LINUX20_ENV */
410     afs_ni_syscall = sys_call_table[__NR_afs_syscall];
411     sys_call_table[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall;
412 # ifdef AFS_SPARC64_LINUX20_ENV
413     afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall];
414     sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
415 # endif
416 #endif /* AFS_IA64_LINUX20_ENV */
417 #ifdef AFS_AMD64_LINUX20_ENV
418     if (ia32_sys_call_table) {
419         ia32_ni_syscall = ia32_sys_call_table[__NR_ia32_afs_syscall];
420         ia32_sys_call_table[__NR_ia32_afs_syscall] =
421             POINTER2SYSCALL afs_syscall;
422     }
423 #endif /* AFS_S390_LINUX22_ENV */
424
425     osi_Init();
426     register_filesystem(&afs_file_system);
427
428     /* Intercept setgroups calls */
429 #if defined(AFS_IA64_LINUX20_ENV)
430     sys_setgroupsp = (void *)&sys_setgroups;
431
432     ((struct fptr *)sys_setgroupsp)->ip =
433         SYSCALL2POINTER sys_call_table[__NR_setgroups - 1024];
434     ((struct fptr *)sys_setgroupsp)->gp = kernel_gp;
435
436     sys_call_table[__NR_setgroups - 1024] =
437         POINTER2SYSCALL((struct fptr *)afs_xsetgroups_stub)->ip;
438 #else /* AFS_IA64_LINUX20_ENV */
439     sys_setgroupsp = SYSCALL2POINTER sys_call_table[__NR_setgroups];
440     sys_call_table[__NR_setgroups] = POINTER2SYSCALL afs_xsetgroups;
441 #ifdef AFS_SPARC64_LINUX20_ENV
442     sys32_setgroupsp = SYSCALL2POINTER sys_call_table32[__NR_setgroups];
443     sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs32_xsetgroups;
444 #endif /* AFS_SPARC64_LINUX20_ENV */
445 #if defined(__NR_setgroups32)
446     sys_setgroups32p = SYSCALL2POINTER sys_call_table[__NR_setgroups32];
447     sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32;
448 #ifdef AFS_SPARC64_LINUX20_ENV
449     sys32_setgroups32p = SYSCALL2POINTER sys_call_table32[__NR_setgroups32];
450     sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL afs32_xsetgroups32;
451 #endif /* AFS_SPARC64_LINUX20_ENV */
452 #endif /* __NR_setgroups32 */
453 #ifdef AFS_AMD64_LINUX20_ENV
454     if (ia32_sys_call_table) {
455         sys32_setgroupsp =
456             SYSCALL2POINTER ia32_sys_call_table[__NR_ia32_setgroups];
457         ia32_sys_call_table[__NR_ia32_setgroups] =
458             POINTER2SYSCALL afs32_xsetgroups;
459 #if defined(__NR_ia32_setgroups32)
460         sys32_setgroups32p =
461             SYSCALL2POINTER ia32_sys_call_table[__NR_ia32_setgroups32];
462         ia32_sys_call_table[__NR_ia32_setgroups32] =
463             POINTER2SYSCALL afs32_xsetgroups32;
464 #endif /* __NR_ia32_setgroups32 */
465     }
466 #endif /* AFS_AMD64_LINUX20_ENV */
467 #endif /* AFS_IA64_LINUX20_ENV */
468
469     osi_sysctl_init();
470
471     return 0;
472 }
473
474 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
475 void __exit
476 afs_cleanup(void)
477 #else
478 void
479 cleanup_module(void)
480 #endif
481 {
482     struct task_struct *t;
483
484     osi_sysctl_clean();
485
486 #if defined(AFS_IA64_LINUX20_ENV)
487     sys_call_table[__NR_setgroups - 1024] =
488         POINTER2SYSCALL((struct fptr *)sys_setgroupsp)->ip;
489     sys_call_table[__NR_afs_syscall - 1024] = afs_ni_syscall;
490 #else /* AFS_IA64_LINUX20_ENV */
491     sys_call_table[__NR_setgroups] = POINTER2SYSCALL sys_setgroupsp;
492     sys_call_table[__NR_afs_syscall] = afs_ni_syscall;
493 # ifdef AFS_SPARC64_LINUX20_ENV
494     sys_call_table32[__NR_setgroups] = POINTER2SYSCALL sys32_setgroupsp;
495     sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
496 # endif
497 # if defined(__NR_setgroups32)
498     sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p;
499 # ifdef AFS_SPARC64_LINUX20_ENV
500     sys_call_table32[__NR_setgroups32] = POINTER2SYSCALL sys32_setgroups32p;
501 # endif
502 # endif
503 #endif /* AFS_IA64_LINUX20_ENV */
504 #ifdef AFS_AMD64_LINUX20_ENV
505     if (ia32_sys_call_table) {
506         ia32_sys_call_table[__NR_ia32_setgroups] =
507             POINTER2SYSCALL sys32_setgroupsp;
508         ia32_sys_call_table[__NR_ia32_afs_syscall] =
509             POINTER2SYSCALL ia32_ni_syscall;
510 # if defined(__NR_setgroups32)
511         ia32_sys_call_table[__NR_ia32_setgroups32] =
512             POINTER2SYSCALL sys32_setgroups32p;
513 #endif
514     }
515 #endif
516     unregister_filesystem(&afs_file_system);
517
518     osi_linux_free_inode_pages();       /* Invalidate all pages using AFS inodes. */
519     osi_linux_free_afs_memory();
520
521     return;
522 }
523
524 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
525 module_init(afs_init);
526 module_exit(afs_cleanup);
527 #endif
528
529
530 static long
531 get_page_offset(void)
532 {
533 #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)
534     return PAGE_OFFSET;
535 #else
536     struct task_struct *p, *q;
537
538     /* search backward thru the circular list */
539 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
540     read_lock(&tasklist_lock);
541 #endif
542     /* search backward thru the circular list */
543 #ifdef DEFINED_PREV_TASK
544     for (q = current; p = q; q = prev_task(p)) {
545 #else
546     for (p = current; p; p = p->prev_task) {
547 #endif
548         if (p->pid == 1) {
549 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
550             read_unlock(&tasklist_lock);
551 #endif
552             return p->addr_limit.seg;
553         }
554     }
555
556 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
557     read_unlock(&tasklist_lock);
558 #endif
559     return 0;
560 #endif
561 }