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