linux-ppc64-26-20050403
[openafs.git] / src / afs / LINUX / osi_syscall.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 #ifdef AFS_LINUX24_ENV
21 #include <linux/module.h> /* early to avoid printf->printk mapping */
22 #endif
23 #include "afs/sysincludes.h"
24 #include "afsincludes.h"
25 #include "h/unistd.h"           /* For syscall numbers. */
26 #include "h/mm.h"
27
28 #ifdef AFS_AMD64_LINUX20_ENV
29 #include "../asm/ia32_unistd.h"
30 #endif
31
32 #include <linux/proc_fs.h>
33 #include <linux/slab.h>
34 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
35 #include <linux/init.h>
36 #include <linux/sched.h>
37 #endif
38
39 #ifndef NR_syscalls
40 #define NR_syscalls 222
41 #endif
42
43 /* On SPARC64 and S390X, sys_call_table contains 32-bit entries
44  * even though pointers are 64 bit quantities.
45  * XXX unify this with osi_probe.c
46  */
47 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_S390X_LINUX24_ENV)
48 #define SYSCALLTYPE unsigned int
49 #define POINTER2SYSCALL (unsigned int)(unsigned long)
50 #define SYSCALL2POINTER (void *)(long)
51 #else
52 #define SYSCALLTYPE void *
53 #define POINTER2SYSCALL (void *)
54 #define SYSCALL2POINTER (void *)
55 #endif
56
57 #if defined(AFS_S390X_LINUX24_ENV) && !defined(AFS_LINUX26_ENV)
58 #define _S(x) ((x)<<1)
59 #elif defined(AFS_IA64_LINUX20_ENV)
60 #define _S(x) ((x)-1024)
61 #else
62 #define _S(x) x
63 #endif
64
65
66 /***** ALL PLATFORMS *****/
67 extern asmlinkage long
68 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4);
69
70 static SYSCALLTYPE *afs_sys_call_table;
71 static SYSCALLTYPE afs_ni_syscall = 0;
72
73 extern long afs_xsetgroups();
74 asmlinkage long (*sys_setgroupsp) (int gidsetsize, gid_t * grouplist);
75
76 #ifdef AFS_LINUX24_ENV
77 extern int afs_xsetgroups32();
78 asmlinkage int (*sys_setgroups32p) (int gidsetsize,
79                                     __kernel_gid32_t * grouplist);
80 #endif
81
82 #if !defined(AFS_LINUX24_ENV)
83 asmlinkage int (*sys_settimeofdayp) (struct timeval * tv, struct timezone * tz);
84 #endif
85
86
87 /***** AMD64 *****/
88 #ifdef AFS_AMD64_LINUX20_ENV
89 static SYSCALLTYPE *afs_ia32_sys_call_table;
90 static SYSCALLTYPE ia32_ni_syscall = 0;
91
92 extern int afs32_xsetgroups();
93 asmlinkage long (*sys32_setgroupsp) (int gidsetsize, u16 * grouplist);
94 #ifdef AFS_LINUX24_ENV
95 extern int afs32_xsetgroups32();
96 asmlinkage long (*sys32_setgroups32p) (int gidsetsize, gid_t * grouplist);
97 #endif /* __NR_ia32_setgroups32 */
98 #endif /* AFS_AMD64_LINUX20_ENV */
99
100
101 /***** PPC64 *****/
102 #ifdef AFS_PPC64_LINUX26_ENV
103 static SYSCALLTYPE *afs_sys_call_table32;
104 static SYSCALLTYPE afs_ni_syscall32 = 0;
105 static SYSCALLTYPE old_sys_setgroupsp = 0;
106 static SYSCALLTYPE old_sys32_setgroupsp = 0;
107
108 extern int afs32_xsetgroups();
109 asmlinkage long (*sys32_setgroupsp)(int gidsetsize, gid_t *grouplist);
110
111 asmlinkage long sys_close(unsigned int fd);
112 static void sys_setgroups_stub() 
113         __attribute__ ((pure,const,no_instrument_function));
114 static void sys_setgroups_stub() 
115
116         printf("*** error! sys_setgroups_stub called\n");
117 }
118
119 static void sys32_setgroups_stub() 
120         __attribute__ ((pure,const,no_instrument_function));
121 static void sys32_setgroups_stub() 
122
123         printf("*** error! sys32_setgroups_stub called\n");
124 }
125
126 #endif /* AFS_AMD64_LINUX20_ENV */
127
128
129 /***** SPARC64 *****/
130 #ifdef AFS_SPARC64_LINUX20_ENV
131 extern SYSCALLTYPE *afs_sys_call_table32;
132 static SYSCALLTYPE afs_ni_syscall32 = 0;
133
134 extern int afs32_xsetgroups();
135 asmlinkage int (*sys32_setgroupsp) (int gidsetsize,
136                                     __kernel_gid_t32 * grouplist);
137 #ifdef AFS_LINUX24_ENV
138 /* This number is not exported for some bizarre reason. */
139 #define __NR_setgroups32      82
140 extern int afs32_xsetgroups32();
141 asmlinkage int (*sys32_setgroups32p) (int gidsetsize,
142                                       __kernel_gid_t32 * grouplist);
143 #endif
144
145 asmlinkage int
146 afs_syscall32(long syscall, long parm1, long parm2, long parm3, long parm4,
147               long parm5)
148 {
149     __asm__ __volatile__("srl %o4, 0, %o4\n\t"
150                          "mov %o7, %i7\n\t"
151                          "call afs_syscall\n\t"
152                          "srl %o5, 0, %o5\n\t"
153                          "ret\n\t"
154                          "nop");
155 }
156 #endif /* AFS_SPARC64_LINUX20_ENV */
157
158
159 /***** IA64 *****/
160 #ifdef AFS_IA64_LINUX20_ENV
161
162 asmlinkage long
163 afs_syscall_stub(int r0, int r1, long r2, long r3, long r4, long gp)
164 {
165     __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t"
166                          "mov r41 = b0\n\t"     /* save rp */
167                          "mov out0 = in0\n\t"
168                          "mov out1 = in1\n\t"
169                          "mov out2 = in2\n\t"
170                          "mov out3 = in3\n\t"
171                          "mov out4 = in4\n\t"
172                          "mov out5 = gp\n\t"    /* save gp */
173                          ";;\n"
174                          ".L1:\n\t"
175                          "mov r3 = ip\n\t"
176                          ";;\n\t"
177                          "addl r15=.fptr_afs_syscall-.L1,r3\n\t"
178                          ";;\n\t"
179                          "ld8 r15=[r15]\n\t"
180                          ";;\n\t"
181                          "ld8 r16=[r15],8\n\t"
182                          ";;\n\t"
183                          "ld8 gp=[r15]\n\t"
184                          "mov b6=r16\n\t"
185                          "br.call.sptk.many b0 = b6\n\t"
186                          ";;\n\t"
187                          "mov ar.pfs = r42\n\t"
188                          "mov b0 = r41\n\t"
189                          "mov gp = r48\n\t"     /* restore gp */
190                          "br.ret.sptk.many b0\n"
191                          ".fptr_afs_syscall:\n\t"
192                          "data8 @fptr(afs_syscall)\n\t"
193                          ".skip 8");
194 }
195
196 asmlinkage long
197 afs_xsetgroups_stub(int r0, int r1, long r2, long r3, long r4, long gp)
198 {
199     __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t"
200                          "mov r41 = b0\n\t"     /* save rp */
201                          "mov out0 = in0\n\t"
202                          "mov out1 = in1\n\t"
203                          "mov out2 = in2\n\t"
204                          "mov out3 = in3\n\t"
205                          "mov out4 = in4\n\t"
206                          "mov out5 = gp\n\t"    /* save gp */
207                          ";;\n"
208                          ".L2:\n\t"
209                          "mov r3 = ip\n\t"
210                          ";;\n\t"
211                          "addl r15=.fptr_afs_xsetgroups - .L2,r3\n\t"
212                          ";;\n\t"
213                          "ld8 r15=[r15]\n\t"
214                          ";;\n\t"
215                          "ld8 r16=[r15],8\n\t"
216                          ";;\n\t"
217                          "ld8 gp=[r15]\n\t"
218                          "mov b6=r16\n\t"
219                          "br.call.sptk.many b0 = b6\n\t"
220                          ";;\n\t"
221                          "mov ar.pfs = r42\n\t"
222                          "mov b0 = r41\n\t"
223                          "mov gp = r48\n\t"     /* restore gp */
224                          "br.ret.sptk.many b0\n"
225                          ".fptr_afs_xsetgroups:\n\t"
226                          "data8 @fptr(afs_xsetgroups)\n\t"
227                          ".skip 8");
228 }
229
230 struct fptr {
231     void *ip;
232     unsigned long gp;
233 };
234
235 #endif /* AFS_IA64_LINUX20_ENV */
236
237 /***** PPC64 ***** 
238  * Spring 2005
239  * sys_call_table hook for PPC64 
240  * by Soewono Effendi <Soewono.Effendi@sysgo.de>
241  * for IBM Deutschland
242  * Thanks go to SYSGO's team for their support:
243  * Horst Birthelmer <Horst.Birthelmer@sysgo.de>
244  * Marius Groeger <Marius.Groeger@sysgo.de>
245  */
246 #if defined(AFS_PPC64_LINUX26_ENV)
247 extern void flush_cache(void *, unsigned long);
248 #define PPC_LO(v) ((v) & 0xffff)
249 #define PPC_HI(v) (((v) >> 16) & 0xffff)
250 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
251 #define PPC_HLO(v) ((short)(((v) >> 32) & 0xffff))
252 #define PPC_HHI(v) ((short)(((v) >> 48) & 0xffff))
253
254 struct ppc64_opd
255 {
256         unsigned long funcaddr;
257         unsigned long r2;
258 };
259
260 struct ppc64_stub
261 {
262         unsigned char jump[136];
263         unsigned long r2;
264         unsigned long lr;
265         struct ppc64_opd opd;
266 } __attribute__ ((packed));
267
268 /* a stub to fix up r2 (TOC ptr) and to jump to our sys_call hook
269    function.  We patch the new r2 value and function pointer into 
270    the stub. */
271 #define PPC64_STUB(stub) \
272 static struct ppc64_stub stub = \
273 { .jump = { \
274         0xf8, 0x41, 0x00, 0x28, /*     std     r2,40(r1) */ \
275         0xfb, 0xc1, 0xff, 0xf0, /*     std     r30,-16(r1) */ \
276         0xfb, 0xa1, 0xff, 0xe8, /*     std     r29,-24(r1) */ \
277         0x7c, 0x5d, 0x13, 0x78, /*     mr      r29,r2 */ \
278         0x3c, 0x40, 0x12, 0x34, /*16:  lis     r2,4660 */ \
279         0x60, 0x42, 0x56, 0x78, /*20:  ori     r2,r2,22136 */ \
280         0x78, 0x42, 0x07, 0xc6, /*     rldicr  r2,r2,32,31 */ \
281         0x64, 0x42, 0x90, 0xab, /*28:  oris    r2,r2,37035 */ \
282         0x60, 0x42, 0xcd, 0xef, /*32:  ori     r2,r2,52719 */ \
283         0x3f, 0xc2, 0x00, 0x00, /*36:  addis   r30,r2,0 */ \
284         0x3b, 0xde, 0x00, 0x00, /*40:  addi    r30,r30,0 */ \
285         0xfb, 0xbe, 0x00, 0x88, /*     std     r29,136(r30) */ \
286         0x7f, 0xa8, 0x02, 0xa6, /*     mflr    r29 */ \
287         0xfb, 0xbe, 0x00, 0x90, /*     std     r29,144(r30) */ \
288         0xeb, 0xde, 0x00, 0x98, /*     ld      r30,152(r30) */ \
289         0x7f, 0xc8, 0x03, 0xa6, /*     mtlr    r30 */ \
290         0xeb, 0xa1, 0xff, 0xe8, /*     ld      r29,-24(r1) */ \
291         0xeb, 0xc1, 0xff, 0xf0, /*     ld      r30,-16(r1) */ \
292         0x4e, 0x80, 0x00, 0x21, /*     blrl */ \
293         0x3c, 0x40, 0x12, 0x34, /*76:  lis     r2,4660 */ \
294         0x60, 0x42, 0x56, 0x78, /*80:  ori     r2,r2,22136 */ \
295         0x78, 0x42, 0x07, 0xc6, /*     rldicr  r2,r2,32,31 */ \
296         0x64, 0x42, 0x90, 0xab, /*88:  oris    r2,r2,37035 */ \
297         0x60, 0x42, 0xcd, 0xef, /*92:  ori     r2,r2,52719 */ \
298         0xfb, 0xc1, 0xff, 0xf0, /*     std     r30,-16(r1) */ \
299         0xfb, 0xa1, 0xff, 0xe8, /*     std     r29,-24(r1) */ \
300         0x3f, 0xc2, 0xab, 0xcd, /*104: addis   r30,r2,-21555 */ \
301         0x3b, 0xde, 0x78, 0x90, /*108: addi    r30,r30,30864 */ \
302         0xeb, 0xbe, 0x00, 0x90, /*     ld      r29,144(r30) */ \
303         0x7f, 0xa8, 0x03, 0xa6, /*     mtlr    r29 */ \
304         0xe8, 0x5e, 0x00, 0x88, /*     ld      r2,136(r30) */ \
305         0xeb, 0xa1, 0xff, 0xe8, /*     ld      r29,-24(r1) */ \
306         0xeb, 0xc1, 0xff, 0xf0, /*     ld      r30,-16(r1) */ \
307         0x4e, 0x80, 0x00, 0x20  /*     blr */ \
308 }} 
309
310 static void * create_stub(struct ppc64_stub *stub,
311                           struct ppc64_opd *opd)
312 {
313         unsigned short *p1, *p2, *p3, *p4;
314         unsigned long addr;
315
316         stub->opd.funcaddr = opd->funcaddr;
317         stub->opd.r2 = opd->r2;
318         addr = (unsigned long) opd->r2;
319         p1 = (unsigned short*) &stub->jump[18];
320         p2 = (unsigned short*) &stub->jump[22];
321         p3 = (unsigned short*) &stub->jump[30];
322         p4 = (unsigned short*) &stub->jump[34];
323
324         *p1 = PPC_HHI(addr);
325         *p2 = PPC_HLO(addr);
326         *p3 = PPC_HI(addr);
327         *p4 = PPC_LO(addr);
328
329         addr = (unsigned long) stub - opd->r2;
330         p1 = (unsigned short*) &stub->jump[38];
331         p2 = (unsigned short*) &stub->jump[42];
332         *p1 = PPC_HA(addr);
333         *p2 = PPC_LO(addr);
334         p1 = (unsigned short*) &stub->jump[106];
335         p2 = (unsigned short*) &stub->jump[110];
336         *p1 = PPC_HA(addr);
337         *p2 = PPC_LO(addr);
338
339         addr = (unsigned long) opd->r2;
340         p1 = (unsigned short*) &stub->jump[78];
341         p2 = (unsigned short*) &stub->jump[82];
342         p3 = (unsigned short*) &stub->jump[90];
343         p4 = (unsigned short*) &stub->jump[94];
344
345         *p1 = PPC_HHI(addr);
346         *p2 = PPC_HLO(addr);
347         *p3 = PPC_HI(addr);
348         *p4 = PPC_LO(addr);
349
350         flush_cache((void *)stub, sizeof(*stub));
351         return ((void*)(stub));
352 }
353
354 PPC64_STUB(afs_sys_call_stub);
355 PPC64_STUB(afs_xsetgroups_stub);
356 PPC64_STUB(afs_xsetgroups32_stub);
357 #endif /* AFS_PPC64_LINUX26_ENV */
358
359
360 /**********************************************************************/
361 /********************* System Call Initialization *********************/
362 /**********************************************************************/
363
364 int osi_syscall_init(void)
365 {
366 /***** IA64 *****/
367 #ifdef AFS_IA64_LINUX20_ENV
368     /* This needs to be first because we are declaring variables, and
369      * also because the handling of syscall pointers is bizarre enough
370      * that we want to special-case even the "common" part.
371      */
372     unsigned long kernel_gp = 0;
373     static struct fptr sys_setgroups;
374
375     afs_sys_call_table = osi_find_syscall_table(0);
376     if (afs_sys_call_table) {
377
378 #if !defined(AFS_LINUX24_ENV)
379         /* XXX no sys_settimeofday on IA64? */
380 #endif
381
382         /* check we aren't already loaded */
383         /* XXX this can't be right */
384         if (SYSCALL2POINTER afs_sys_call_table[_S(__NR_afs_syscall)]
385             == afs_syscall) {
386             printf("AFS syscall entry point already in use!\n");
387             return -EBUSY;
388         }
389
390         /* setup AFS entry point */
391         afs_ni_syscall = afs_sys_call_table[_S(__NR_afs_syscall)];
392         afs_sys_call_table[_S(__NR_afs_syscall)] =
393                 POINTER2SYSCALL((struct fptr *)afs_syscall_stub)->ip;
394
395         /* setup setgroups */
396         sys_setgroupsp = (void *)&sys_setgroups;
397
398         ((struct fptr *)sys_setgroupsp)->ip =
399             SYSCALL2POINTER afs_sys_call_table[_S(__NR_setgroups)];
400         ((struct fptr *)sys_setgroupsp)->gp = kernel_gp;
401
402         afs_sys_call_table[_S(__NR_setgroups)] =
403             POINTER2SYSCALL((struct fptr *)afs_xsetgroups_stub)->ip;
404     }
405
406     /* XXX no 32-bit syscalls on IA64? */
407
408
409 #elif defined(AFS_PPC64_LINUX26_ENV)
410
411     afs_sys_call_table = osi_find_syscall_table(0);
412     if (afs_sys_call_table) {
413         SYSCALLTYPE p;
414         struct ppc64_opd* opd = (struct ppc64_opd*) sys_close;
415         unsigned long r2 = opd->r2;
416         opd = (struct ppc64_opd*) afs_syscall;
417         afs_sys_call_table32 = (unsigned long)afs_sys_call_table - 
418                 NR_syscalls * sizeof(SYSCALLTYPE);
419         /* check we aren't already loaded */
420         p = SYSCALL2POINTER afs_sys_call_table[_S(__NR_afs_syscall)];
421         if ((unsigned long)p == opd->funcaddr) {
422             printf("AFS syscall entry point already in use!\n");
423             return -EBUSY;
424         }
425         /* setup AFS entry point */
426         p = create_stub(&afs_sys_call_stub, opd);
427         afs_ni_syscall = afs_sys_call_table[_S(__NR_afs_syscall)];
428         afs_sys_call_table[_S(__NR_afs_syscall)] = POINTER2SYSCALL p;
429
430         /* setup setgroups */
431         opd = (struct ppc64_opd*) afs_xsetgroups;
432         p = create_stub(&afs_xsetgroups_stub, opd);
433         old_sys_setgroupsp = SYSCALL2POINTER afs_sys_call_table[_S(__NR_setgroups)];
434         afs_sys_call_table[_S(__NR_setgroups)] = POINTER2SYSCALL p;
435         opd = (struct ppc64_opd*) sys_setgroups_stub;
436         opd->funcaddr = old_sys_setgroupsp;
437         opd->r2 = r2;
438
439         /* setup setgroups32 */
440         opd = (struct ppc64_opd*) afs32_xsetgroups;
441         p = create_stub(&afs_xsetgroups32_stub, opd);
442         old_sys32_setgroupsp = SYSCALL2POINTER afs_sys_call_table32[_S(__NR_setgroups)];
443         afs_sys_call_table32[_S(__NR_setgroups)] = POINTER2SYSCALL p;
444         opd = (struct ppc64_opd*) sys32_setgroups_stub;
445         opd->funcaddr = old_sys32_setgroupsp;
446         opd->r2 = r2;
447
448         flush_cache((void *)afs_sys_call_table, 2*NR_syscalls*sizeof(void*));
449
450         sys_setgroupsp = sys_setgroups_stub;
451         sys32_setgroupsp = sys32_setgroups_stub;
452     }
453 /***** COMMON (except IA64 or PPC64) *****/
454 #else /* !AFS_IA64_LINUX20_ENV */
455
456     afs_sys_call_table = osi_find_syscall_table(0);
457     if (afs_sys_call_table) {
458 #if !defined(AFS_LINUX24_ENV)
459         sys_settimeofdayp =
460             SYSCALL2POINTER afs_sys_call_table[_S(__NR_settimeofday)];
461 #endif /* AFS_LINUX24_ENV */
462
463         /* check we aren't already loaded */
464         if (SYSCALL2POINTER afs_sys_call_table[_S(__NR_afs_syscall)]
465             == afs_syscall) {
466             printf("AFS syscall entry point already in use!\n");
467             return -EBUSY;
468         }
469
470         /* setup AFS entry point */
471         afs_ni_syscall = afs_sys_call_table[_S(__NR_afs_syscall)];
472         afs_sys_call_table[_S(__NR_afs_syscall)] = POINTER2SYSCALL afs_syscall;
473
474         /* setup setgroups */
475         sys_setgroupsp = SYSCALL2POINTER afs_sys_call_table[_S(__NR_setgroups)];
476         afs_sys_call_table[_S(__NR_setgroups)] = POINTER2SYSCALL afs_xsetgroups;
477
478 #if defined(__NR_setgroups32)
479         /* setup setgroups32 */
480         sys_setgroups32p = SYSCALL2POINTER afs_sys_call_table[__NR_setgroups32];
481         afs_sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32;
482 #endif
483     }
484 #endif /* !AFS_IA64_LINUX20_ENV */
485
486
487 /***** AMD64 *****/
488 #ifdef AFS_AMD64_LINUX20_ENV
489     afs_ia32_sys_call_table = osi_find_syscall_table(1);
490     if (afs_ia32_sys_call_table) {
491         /* setup AFS entry point for IA32 */
492         ia32_ni_syscall = afs_ia32_sys_call_table[__NR_ia32_afs_syscall];
493         afs_ia32_sys_call_table[__NR_ia32_afs_syscall] =
494             POINTER2SYSCALL afs_syscall;
495
496         /* setup setgroups for IA32 */
497         sys32_setgroupsp =
498             SYSCALL2POINTER afs_ia32_sys_call_table[__NR_ia32_setgroups];
499         afs_ia32_sys_call_table[__NR_ia32_setgroups] =
500             POINTER2SYSCALL afs32_xsetgroups;
501
502 #if AFS_LINUX24_ENV
503         /* setup setgroups32 for IA32 */
504         sys32_setgroups32p =
505             SYSCALL2POINTER afs_ia32_sys_call_table[__NR_ia32_setgroups32];
506         afs_ia32_sys_call_table[__NR_ia32_setgroups32] =
507             POINTER2SYSCALL afs32_xsetgroups32;
508 #endif /* __NR_ia32_setgroups32 */
509     }
510 #endif /* AFS_AMD64_LINUX20_ENV */
511
512
513 /***** SPARC64 *****/
514 #ifdef AFS_SPARC64_LINUX20_ENV
515     afs_sys_call_table32 = osi_find_syscall_table(1);
516     if (afs_sys_call_table32) {
517         /* setup AFS entry point for 32-bit SPARC */
518         afs_ni_syscall32 = afs_sys_call_table32[__NR_afs_syscall];
519         afs_sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
520
521         /* setup setgroups for 32-bit SPARC */
522         sys32_setgroupsp = SYSCALL2POINTER afs_sys_call_table32[__NR_setgroups];
523         afs_sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs32_xsetgroups;
524
525 #ifdef AFS_LINUX24_ENV
526         /* setup setgroups32 for 32-bit SPARC */
527         sys32_setgroups32p =
528             SYSCALL2POINTER afs_sys_call_table32[__NR_setgroups32];
529         afs_sys_call_table32[__NR_setgroups32] =
530             POINTER2SYSCALL afs32_xsetgroups32;
531 #endif
532     }
533 #endif /* AFS_SPARC64_LINUX20_ENV */
534     return 0;
535 }
536
537
538
539 /**********************************************************************/
540 /************************ System Call Cleanup *************************/
541 /**********************************************************************/
542
543 void osi_syscall_clean(void)
544 {
545 /***** COMMON *****/
546     if (afs_sys_call_table) {
547         /* put back the AFS entry point */
548         afs_sys_call_table[_S(__NR_afs_syscall)] = afs_ni_syscall;
549
550         /* put back setgroups */
551 #if defined(AFS_IA64_LINUX20_ENV)
552         afs_sys_call_table[_S(__NR_setgroups)] =
553             POINTER2SYSCALL((struct fptr *)sys_setgroupsp)->ip;
554 #elif defined(AFS_PPC64_LINUX26_ENV)
555         afs_sys_call_table[_S(__NR_setgroups)] =
556             POINTER2SYSCALL old_sys_setgroupsp;
557         /* put back setgroups32 for PPC64 */
558         afs_sys_call_table32[__NR_setgroups] =
559             POINTER2SYSCALL old_sys32_setgroupsp;
560 #else /* AFS_IA64_LINUX20_ENV */
561         afs_sys_call_table[_S(__NR_setgroups)] =
562             POINTER2SYSCALL sys_setgroupsp;
563 #endif
564
565 #if defined(__NR_setgroups32) && !defined(AFS_IA64_LINUX20_ENV)
566         /* put back setgroups32 */
567         afs_sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p;
568 #endif
569     }
570
571
572 /***** IA64 *****/
573 #ifdef AFS_IA64_LINUX20_ENV
574     /* XXX no 32-bit syscalls on IA64? */
575 #endif
576
577
578 /***** AMD64 *****/
579 #ifdef AFS_AMD64_LINUX20_ENV
580     if (afs_ia32_sys_call_table) {
581         /* put back AFS entry point for IA32 */
582         afs_ia32_sys_call_table[__NR_ia32_afs_syscall] =
583             POINTER2SYSCALL ia32_ni_syscall;
584
585         /* put back setgroups for IA32 */
586         afs_ia32_sys_call_table[__NR_ia32_setgroups] =
587             POINTER2SYSCALL sys32_setgroupsp;
588
589 #ifdef AFS_LINUX24_ENV
590         /* put back setgroups32 for IA32 */
591         afs_ia32_sys_call_table[__NR_ia32_setgroups32] =
592             POINTER2SYSCALL sys32_setgroups32p;
593 #endif
594     }
595 #endif
596
597
598 /***** SPARC64 *****/
599 #ifdef AFS_SPARC64_LINUX20_ENV
600     if (afs_sys_call_table32) {
601         /* put back AFS entry point for 32-bit SPARC */
602         afs_sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
603
604         /* put back setgroups for IA32 */
605         afs_sys_call_table32[__NR_setgroups] =
606             POINTER2SYSCALL sys32_setgroupsp;
607
608 #ifdef AFS_LINUX24_ENV
609         /* put back setgroups32 for IA32 */
610         afs_sys_call_table32[__NR_setgroups32] =
611             POINTER2SYSCALL sys32_setgroups32p;
612 #endif
613     }
614 #endif
615 }