linux kernel lacks uintptr
[openafs.git] / src / afs / afs_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 #include <afsconfig.h>
11 #include "afs/param.h"
12
13 #ifdef IGNORE_SOME_GCC_WARNINGS
14 # pragma GCC diagnostic warning "-Wold-style-definition"
15 # pragma GCC diagnostic warning "-Wstrict-prototypes"
16 #endif
17
18 #include "afs/sysincludes.h"    /* Standard vendor system headers */
19 #include "afsincludes.h"        /* Afs-based standard headers */
20 #include "afs/afs_stats.h"
21 #include "rx/rx_globals.h"
22 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
23 #include "net/if.h"
24 #ifdef AFS_SGI62_ENV
25 #include "h/hashing.h"
26 #endif
27 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
28 #include "netinet/in_var.h"
29 #endif
30 #endif /* !defined(UKERNEL) */
31 #ifdef AFS_LINUX22_ENV
32 #include "h/smp_lock.h"
33 #endif
34
35 #if (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) || defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)) || defined(NEED_IOCTL32)
36 static void
37 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
38 {
39     dst->in = (char *)(unsigned long)src->in;
40     dst->out = (char *)(unsigned long)src->out;
41     dst->in_size = src->in_size;
42     dst->out_size = src->out_size;
43 }
44 #endif
45
46 /*
47  * If you need to change copyin_afs_ioctl(), you may also need to change
48  * copyin_iparam().
49  */
50
51 int
52 #ifdef AFS_DARWIN100_ENV
53 copyin_afs_ioctl(user_addr_t cmarg, struct afs_ioctl *dst)
54 #else
55 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
56 #endif
57 {
58     int code;
59 #if defined(AFS_DARWIN100_ENV)
60     struct afs_ioctl32 dst32;
61     
62     if (!proc_is64bit(current_proc())) {
63         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
64         if (!code)
65             afs_ioctl32_to_afs_ioctl(&dst32, dst);
66         return code;
67     }
68 #endif
69 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
70     struct afs_ioctl32 dst32;
71
72     if (!(IS64U)) {
73         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
74         if (!code)
75             afs_ioctl32_to_afs_ioctl(&dst32, dst);
76         return code;
77     }
78 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
79
80
81 #if defined(AFS_HPUX_64BIT_ENV)
82     struct afs_ioctl32 dst32;
83
84     if (is_32bit(u.u_procp)) {  /* is_32bit() in proc_iface.h */
85         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
86         if (!code)
87             afs_ioctl32_to_afs_ioctl(&dst32, dst);
88         return code;
89     }
90 #endif /* defined(AFS_HPUX_64BIT_ENV) */
91
92 #if defined(AFS_SUN57_64BIT_ENV)
93     struct afs_ioctl32 dst32;
94
95     if (get_udatamodel() == DATAMODEL_ILP32) {
96         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
97         if (!code)
98             afs_ioctl32_to_afs_ioctl(&dst32, dst);
99         return code;
100     }
101 #endif /* defined(AFS_SUN57_64BIT_ENV) */
102
103 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
104     struct afs_ioctl32 dst32;
105
106     if (!ABI_IS_64BIT(get_current_abi())) {
107         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
108         if (!code)
109             afs_ioctl32_to_afs_ioctl(&dst32, dst);
110         return code;
111     }
112 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
113
114 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
115     struct afs_ioctl32 dst32;
116
117 #ifdef AFS_SPARC64_LINUX26_ENV
118     if (test_thread_flag(TIF_32BIT))
119 #elif defined(AFS_SPARC64_LINUX24_ENV)
120     if (current->thread.flags & SPARC_FLAG_32BIT)
121 #elif defined(AFS_SPARC64_LINUX20_ENV)
122     if (current->tss.flags & SPARC_FLAG_32BIT)
123
124 #elif defined(AFS_AMD64_LINUX26_ENV)
125     if (test_thread_flag(TIF_IA32))
126 #elif defined(AFS_AMD64_LINUX20_ENV)
127     if (current->thread.flags & THREAD_IA32)
128
129 #elif defined(AFS_PPC64_LINUX26_ENV)
130 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
131     if (current->thread_info->flags & _TIF_32BIT) 
132 #else
133     if (task_thread_info(current)->flags & _TIF_32BIT) 
134 #endif      
135 #elif defined(AFS_PPC64_LINUX20_ENV)
136     if (current->thread.flags & PPC_FLAG_32BIT)
137
138 #elif defined(AFS_S390X_LINUX26_ENV)
139     if (test_thread_flag(TIF_31BIT))
140 #elif defined(AFS_S390X_LINUX20_ENV)
141     if (current->thread.flags & S390_FLAG_31BIT)
142
143 #else
144 #error pioctl32 not done for this linux
145 #endif
146     {
147         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
148         if (!code)
149             afs_ioctl32_to_afs_ioctl(&dst32, dst);
150         return code;
151     }
152 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
153
154     AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
155     return code;
156 }
157
158
159 #ifdef AFS_AIX32_ENV
160
161 #include "sys/lockl.h"
162
163 /*
164  * syscall -    this is the VRMIX system call entry point.
165  *
166  * NOTE:
167  *      THIS SHOULD BE CHANGED TO afs_syscall(), but requires
168  *      all the user-level calls to `syscall' to change.
169  */
170 syscall(syscall, p1, p2, p3, p4, p5, p6)
171 {
172     register rval1 = 0, code;
173     register monster;
174     int retval = 0;
175 #ifndef AFS_AIX41_ENV
176     extern lock_t kernel_lock;
177     monster = lockl(&kernel_lock, LOCK_SHORT);
178 #endif /* !AFS_AIX41_ENV */
179
180     AFS_STATCNT(syscall);
181     setuerror(0);
182     switch (syscall) {
183     case AFSCALL_CALL:
184         rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
185         break;
186
187     case AFSCALL_SETPAG:
188         AFS_GLOCK();
189         rval1 = afs_setpag();
190         AFS_GUNLOCK();
191         break;
192
193     case AFSCALL_PIOCTL:
194         AFS_GLOCK();
195         rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
196         AFS_GUNLOCK();
197         break;
198
199     case AFSCALL_ICREATE:
200         rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
201         break;
202
203     case AFSCALL_IOPEN:
204         rval1 = afs_syscall_iopen(p1, p2, p3);
205         break;
206
207     case AFSCALL_IDEC:
208         rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
209         break;
210
211     case AFSCALL_IINC:
212         rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
213         break;
214
215     case AFSCALL_ICL:
216         AFS_GLOCK();
217         code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
218         AFS_GUNLOCK();
219         if (!code)
220             rval1 = retval;
221         if (!rval1)
222             rval1 = code;
223         break;
224
225     default:
226         rval1 = EINVAL;
227         setuerror(EINVAL);
228         break;
229     }
230
231   out:
232 #ifndef AFS_AIX41_ENV
233     if (monster != LOCK_NEST)
234         unlockl(&kernel_lock);
235 #endif /* !AFS_AIX41_ENV */
236     return getuerror()? -1 : rval1;
237 }
238
239 /*
240  * lsetpag -    interface to afs_setpag().
241  */
242 int
243 lsetpag(void)
244 {
245
246     AFS_STATCNT(lsetpag);
247     return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
248 }
249
250 /*
251  * lpioctl -    interface to pioctl()
252  */
253 int
254 lpioctl(char *path, int cmd, void *cmarg, int follow)
255 {
256
257     AFS_STATCNT(lpioctl);
258     return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
259 }
260
261 #else /* !AFS_AIX32_ENV       */
262
263 #if defined(AFS_SGI_ENV)
264 struct afsargs {
265     sysarg_t syscall;
266     sysarg_t parm1;
267     sysarg_t parm2;
268     sysarg_t parm3;
269     sysarg_t parm4;
270     sysarg_t parm5;
271 };
272
273
274 int
275 Afs_syscall(struct afsargs *uap, rval_t * rvp)
276 {
277     int error;
278     long retval;
279
280     AFS_STATCNT(afs_syscall);
281     switch (uap->syscall) {
282     case AFSCALL_ICL:
283         retval = 0;
284         AFS_GLOCK();
285         error =
286             Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
287                         uap->parm5, &retval);
288         AFS_GUNLOCK();
289         rvp->r_val1 = retval;
290         break;
291 #ifdef AFS_SGI_XFS_IOPS_ENV
292     case AFSCALL_IDEC64:
293         error =
294             afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
295                                uap->parm5);
296         break;
297     case AFSCALL_IINC64:
298         error =
299             afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
300                                uap->parm5);
301         break;
302     case AFSCALL_ILISTINODE64:
303         error =
304             afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
305                                      uap->parm4, uap->parm5);
306         break;
307     case AFSCALL_ICREATENAME64:
308         error =
309             afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
310                                       uap->parm4, uap->parm5);
311         break;
312 #endif
313 #ifdef AFS_SGI_VNODE_GLUE
314     case AFSCALL_INIT_KERNEL_CONFIG:
315         error = afs_init_kernel_config(uap->parm1);
316         break;
317 #endif
318     default:
319         error =
320             afs_syscall_call(uap->syscall, uap->parm1, uap->parm2, uap->parm3,
321                              uap->parm4, uap->parm5);
322     }
323     return error;
324 }
325
326 #else /* AFS_SGI_ENV */
327
328 struct iparam {
329     iparmtype param1;
330     iparmtype param2;
331     iparmtype param3;
332     iparmtype param4;
333 };
334
335 struct iparam32 {
336     int param1;
337     int param2;
338     int param3;
339     int param4;
340 };
341
342
343 #if defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)) || defined(NEED_IOCTL32)
344 #if SIZEOF_VOID_P == SIZEOF_UNSIGNED_INT
345 # define uintptrsz unsigned int
346 #elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG
347 # define uintptrsz unsigned long
348 #elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG_LONG
349 # define uintptrsz unsigned long long
350 #else
351 # error "Unable to determine casting for pointers"
352 #endif
353 static void
354 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
355 {
356     dst->param1 = (iparmtype)(uintptrsz)src->param1;
357     dst->param2 = (iparmtype)(uintptrsz)src->param2;
358     dst->param3 = (iparmtype)(uintptrsz)src->param3;
359     dst->param4 = (iparmtype)(uintptrsz)src->param4;
360 }
361 #endif
362
363 /*
364  * If you need to change copyin_iparam(), you may also need to change
365  * copyin_afs_ioctl().
366  *
367  * This function is needed only for icreate, meaning, only on platforms
368  * providing the inode fileserver.
369  */
370
371 static int
372 copyin_iparam(caddr_t cmarg, struct iparam *dst)
373 {
374     int code;
375
376 #if defined(AFS_HPUX_64BIT_ENV)
377     struct iparam32 dst32;
378
379     if (is_32bit(u.u_procp)) {  /* is_32bit() in proc_iface.h */
380         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
381         if (!code)
382             iparam32_to_iparam(&dst32, dst);
383         return code;
384     }
385 #endif /* AFS_HPUX_64BIT_ENV */
386
387 #if defined(AFS_SUN57_64BIT_ENV)
388     struct iparam32 dst32;
389
390     if (get_udatamodel() == DATAMODEL_ILP32) {
391         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
392         if (!code)
393             iparam32_to_iparam(&dst32, dst);
394         return code;
395     }
396 #endif /* AFS_SUN57_64BIT_ENV */
397
398 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
399     struct iparam32 dst32;
400
401 #ifdef AFS_SPARC64_LINUX26_ENV
402     if (test_thread_flag(TIF_32BIT))
403 #elif defined(AFS_SPARC64_LINUX24_ENV)
404     if (current->thread.flags & SPARC_FLAG_32BIT)
405 #elif defined(AFS_SPARC64_LINUX20_ENV)
406     if (current->tss.flags & SPARC_FLAG_32BIT)
407
408 #elif defined(AFS_AMD64_LINUX26_ENV)
409     if (test_thread_flag(TIF_IA32))
410 #elif defined(AFS_AMD64_LINUX20_ENV)
411     if (current->thread.flags & THREAD_IA32)
412
413 #elif defined(AFS_PPC64_LINUX26_ENV)
414 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
415     if (current->thread_info->flags & _TIF_32BIT) 
416 #else
417     if (task_thread_info(current)->flags & _TIF_32BIT) 
418 #endif      
419 #elif defined(AFS_PPC64_LINUX20_ENV)
420     if (current->thread.flags & PPC_FLAG_32BIT) 
421
422 #elif defined(AFS_S390X_LINUX26_ENV)
423     if (test_thread_flag(TIF_31BIT))
424 #elif defined(AFS_S390X_LINUX20_ENV)
425     if (current->thread.flags & S390_FLAG_31BIT) 
426
427 #else
428 #error iparam32 not done for this linux platform
429 #endif
430     {
431         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
432         if (!code)
433             iparam32_to_iparam(&dst32, dst);
434         return code;
435     }
436 #endif /* AFS_LINUX_64BIT_KERNEL */
437
438     AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
439     return code;
440 }
441
442 /* Main entry of all afs system calls */
443 #ifdef  AFS_SUN5_ENV
444 extern int afs_sinited;
445
446 /** The 32 bit OS expects the members of this structure to be 32 bit
447  * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
448  * to accomodate both, *long* is used instead of afs_int32
449  */
450
451 # ifdef AFS_SUN57_ENV
452 struct afssysa {
453     long syscall;
454     long parm1;
455     long parm2;
456     long parm3;
457     long parm4;
458     long parm5;
459     long parm6;
460 };
461 # else
462 struct afssysa {
463     afs_int32 syscall;
464     afs_int32 parm1;
465     afs_int32 parm2;
466     afs_int32 parm3;
467     afs_int32 parm4;
468     afs_int32 parm5;
469     afs_int32 parm6;
470 };
471 # endif
472
473 Afs_syscall(register struct afssysa *uap, rval_t * rvp)
474 {
475     int *retval = &rvp->r_val1;
476 #elif defined(AFS_DARWIN100_ENV)
477 struct afssysa {
478     afs_int32 syscall;
479     afs_int32 parm1;
480     afs_int32 parm2;
481     afs_int32 parm3;
482     afs_int32 parm4;
483     afs_int32 parm5;
484     afs_int32 parm6;
485 };
486 struct afssysa64 {
487     afs_int64 parm1;
488     afs_int64 parm2;
489     afs_int64 parm3;
490     afs_int64 parm4;
491     afs_int64 parm5;
492     afs_int64 parm6;
493     afs_int32 syscall;
494 };
495 int
496 afs3_syscall(afs_proc_t *p, void *args, unsigned int *retval)
497 {
498     struct afssysa64 *uap64 = NULL;
499     struct afssysa *uap = NULL;
500 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
501 int
502 afs3_syscall(p, args, retval)
503 # ifdef AFS_FBSD50_ENV
504      struct thread *p;
505 # else
506      afs_proc_t *p;
507 # endif
508      void *args;
509      long *retval;
510 {
511     register struct a {
512         long syscall;
513         long parm1;
514         long parm2;
515         long parm3;
516         long parm4;
517         long parm5;
518         long parm6;
519     } *uap = (struct a *)args;
520 #elif defined(AFS_LINUX20_ENV)
521 struct afssysargs {
522     long syscall;
523     long parm1;
524     long parm2;
525     long parm3;
526     long parm4;
527     long parm5;
528     long parm6;                 /* not actually used - should be removed */
529 };
530 /* Linux system calls only set up for 5 arguments. */
531 asmlinkage long
532 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4)
533 {
534     struct afssysargs args, *uap = &args;
535     long linux_ret = 0;
536     long *retval = &linux_ret;
537     long eparm[4];              /* matches AFSCALL_ICL in fstrace.c */
538 # ifdef AFS_SPARC64_LINUX24_ENV
539     afs_int32 eparm32[4];
540 # endif
541     /* eparm is also used by AFSCALL_CALL in afsd.c */
542 #else
543 # if defined(UKERNEL)
544 int
545 Afs_syscall()
546 {
547     register struct a {
548         long syscall;
549         long parm1;
550         long parm2;
551         long parm3;
552         long parm4;
553         long parm5;
554         long parm6;
555     } *uap = (struct a *)u.u_ap;
556 # else /* UKERNEL */
557 int
558 Afs_syscall()
559 {
560     register struct a {
561         long syscall;
562         long parm1;
563         long parm2;
564         long parm3;
565         long parm4;
566         long parm5;
567         long parm6;
568     } *uap = (struct a *)u.u_ap;
569 # endif /* UKERNEL */
570 # if defined(AFS_HPUX_ENV)
571     long *retval = &u.u_rval1;
572 # else
573     int *retval = &u.u_rval1;
574 # endif
575 #endif
576     register int code = 0;
577
578     AFS_STATCNT(afs_syscall);
579 #ifdef        AFS_SUN5_ENV
580     rvp->r_vals = 0;
581     if (!afs_sinited) {
582         return (ENODEV);
583     }
584 #endif
585 #ifdef AFS_LINUX20_ENV
586     lock_kernel();
587     /* setup uap for use below - pull out the magic decoder ring to know
588      * which syscalls have folded argument lists.
589      */
590     uap->syscall = syscall;
591     uap->parm1 = parm1;
592     uap->parm2 = parm2;
593     uap->parm3 = parm3;
594     if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
595 #ifdef AFS_SPARC64_LINUX24_ENV
596 /* from arch/sparc64/kernel/sys_sparc32.c */
597 #define AA(__x)                                \
598 ({     unsigned long __ret;            \
599        __asm__ ("srl   %0, 0, %0"      \
600                 : "=r" (__ret)         \
601                 : "0" (__x));          \
602        __ret;                          \
603 })
604
605
606 #ifdef AFS_SPARC64_LINUX26_ENV
607         if (test_thread_flag(TIF_32BIT))
608 #else
609         if (current->thread.flags & SPARC_FLAG_32BIT)
610 #endif
611         {
612             AFS_COPYIN((char *)parm4, (char *)eparm32, sizeof(eparm32), code);
613             eparm[0] = AA(eparm32[0]);
614             eparm[1] = AA(eparm32[1]);
615             eparm[2] = AA(eparm32[2]);
616 #undef AA
617         } else
618 #endif
619             AFS_COPYIN((char *)parm4, (char *)eparm, sizeof(eparm), code);
620         uap->parm4 = eparm[0];
621         uap->parm5 = eparm[1];
622         uap->parm6 = eparm[2];
623     } else {
624         uap->parm4 = parm4;
625         uap->parm5 = 0;
626         uap->parm6 = 0;
627     }
628 #endif
629 #if defined(AFS_DARWIN80_ENV)
630     get_vfs_context();
631     osi_Assert(*retval == 0);
632 #ifdef AFS_DARWIN100_ENV
633     if (proc_is64bit(p)) {
634         uap64 = (struct afssysa64 *)args;
635         if (uap64->syscall == AFSCALL_CALL) {
636             code =
637                 afs_syscall64_call(uap64->parm1, uap64->parm2, uap64->parm3,
638                                    uap64->parm4, uap64->parm5, uap64->parm6);
639         } else if (uap64->syscall == AFSCALL_SETPAG) {
640             AFS_GLOCK();
641             code = afs_setpag(p, args, retval);
642             AFS_GUNLOCK();
643         } else if (uap64->syscall == AFSCALL_PIOCTL) {
644             AFS_GLOCK();
645             code =
646                 afs_syscall64_pioctl(uap64->parm1, (unsigned int)uap64->parm2,
647                                      uap64->parm3, (int)uap64->parm4,
648                                      kauth_cred_get());
649             AFS_GUNLOCK();
650         } else if (uap64->syscall == AFSCALL_ICL) {
651             AFS_GLOCK();
652             code =
653                 Afscall64_icl(uap64->parm1, uap64->parm2, uap64->parm3,
654                             uap64->parm4, uap64->parm5, retval);
655             AFS_GUNLOCK();
656         } else
657             code = EINVAL;
658         if (uap64->syscall != AFSCALL_CALL)
659             put_vfs_context();
660     } else { /* and the default case for 32 bit procs */
661 #endif
662         uap = (struct afssysa *)args;
663 #endif
664 #if defined(AFS_HPUX_ENV)
665     /*
666      * There used to be code here (duplicated from osi_Init()) for
667      * initializing the semaphore used by AFS_GLOCK().  Was the
668      * duplication to handle the case of a dynamically loaded kernel
669      * module?
670      */
671         osi_InitGlock();
672 #endif
673         if (uap->syscall == AFSCALL_CALL) {
674             code =
675                 afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
676                                  uap->parm4, uap->parm5, uap->parm6);
677         } else if (uap->syscall == AFSCALL_SETPAG) {
678 #ifdef  AFS_SUN5_ENV
679             register proc_t *procp;
680
681             procp = ttoproc(curthread);
682             AFS_GLOCK();
683             code = afs_setpag(&procp->p_cred);
684             AFS_GUNLOCK();
685 #else
686             AFS_GLOCK();
687 #if     defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
688             code = afs_setpag(p, args, retval);
689 #else /* AFS_DARWIN_ENV || AFS_XBSD_ENV */
690             code = afs_setpag();
691 #endif
692             AFS_GUNLOCK();
693 #endif
694         } else if (uap->syscall == AFSCALL_PIOCTL) {
695             AFS_GLOCK();
696 #if defined(AFS_SUN5_ENV)
697             code =
698                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
699                                    uap->parm4, rvp, CRED());
700 #elif defined(AFS_FBSD50_ENV)
701             code =
702                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
703                                    uap->parm4, p->td_ucred);
704 #elif defined(AFS_DARWIN80_ENV)
705             code =
706                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
707                                    uap->parm4, kauth_cred_get());
708 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
709             code =
710                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
711                                    uap->parm4, p->p_cred->pc_ucred);
712 #else
713             code =
714                 afs_syscall_pioctl((char *)uap->parm1,
715                                    (unsigned int)uap->parm2,
716                                    (caddr_t)uap->parm3,
717                                    (int) uap->parm4);
718 #endif
719             AFS_GUNLOCK();
720         } else if (uap->syscall == AFSCALL_ICREATE) {
721             struct iparam iparams;
722
723             code = copyin_iparam((char *)uap->parm3, &iparams);
724             if (code) {
725 #if defined(KERNEL_HAVE_UERROR)
726                 setuerror(code);
727 #endif
728             } else {
729 #ifdef  AFS_SUN5_ENV
730                 code =
731                     afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
732                                         iparams.param2, iparams.param3,
733                                         iparams.param4, rvp, CRED());
734 #else
735                 code =
736                     afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
737                                         iparams.param2, iparams.param3,
738                                         iparams.param4
739 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
740                                         , retval
741 #endif
742                         );
743 #endif /* AFS_SUN5_ENV */
744             }
745         } else if (uap->syscall == AFSCALL_IOPEN) {
746 #ifdef  AFS_SUN5_ENV
747             code =
748                 afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp,
749                                   CRED());
750 #else
751             code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3
752 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
753                                      , retval
754 #endif
755                 );
756 #endif /* AFS_SUN5_ENV */
757         } else if (uap->syscall == AFSCALL_IDEC) {
758             code =
759                 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1
760 #ifdef  AFS_SUN5_ENV
761                                     , rvp, CRED()
762 #endif
763                     );
764         } else if (uap->syscall == AFSCALL_IINC) {
765             code =
766                 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1
767 #ifdef  AFS_SUN5_ENV
768                                     , rvp, CRED()
769 #endif
770                     );
771         } else if (uap->syscall == AFSCALL_ICL) {
772             AFS_GLOCK();
773             code =
774                 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
775                             uap->parm5, (long *)retval);
776             AFS_GUNLOCK();
777 #ifdef AFS_LINUX20_ENV
778             if (!code) {
779                 /* ICL commands can return values. */
780                 code = -linux_ret;      /* Gets negated again at exit below */
781             }
782 #else
783             if (code) {
784 #if defined(KERNEL_HAVE_UERROR)
785                 setuerror(code);
786 #endif
787             }
788 #endif /* !AFS_LINUX20_ENV */
789         } else {
790 #if defined(KERNEL_HAVE_UERROR)
791             setuerror(EINVAL);
792 #else
793             code = EINVAL;
794 #endif
795         }
796 #if defined(AFS_DARWIN80_ENV)
797         if (uap->syscall != AFSCALL_CALL)
798             put_vfs_context();
799 #ifdef AFS_DARWIN100_ENV
800     } /* 32 bit procs */
801 #endif
802 #endif
803 #ifdef AFS_LINUX20_ENV
804     code = -code;
805     unlock_kernel();
806 #endif
807     return code;
808 }
809 #endif /* AFS_SGI_ENV */
810 #endif /* !AFS_AIX32_ENV */