Linux: Refactor test for 32bit compat
[openafs.git] / src / afs / afs_syscall.c
index c14c84e..9414f38 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include "afs/param.h"
 
+#ifdef IGNORE_SOME_GCC_WARNINGS
+# pragma GCC diagnostic warning "-Wold-style-definition"
+# pragma GCC diagnostic warning "-Wstrict-prototypes"
+#endif
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afsincludes.h"       /* Afs-based standard headers */
 #ifdef AFS_SGI62_ENV
 #include "h/hashing.h"
 #endif
-#if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
+#if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN_ENV)
 #include "netinet/in_var.h"
 #endif
 #endif /* !defined(UKERNEL) */
-#ifdef AFS_LINUX22_ENV
-#include "h/smp_lock.h"
-#endif
 
-#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)
+#if (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) || defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN5_64BIT_ENV) || (defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)) || defined(NEED_IOCTL32)
 static void
 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
 {
+#ifdef AFS_DARWIN100_ENV
+    dst->in = CAST_USER_ADDR_T(src->in);
+    dst->out = CAST_USER_ADDR_T(src->out);
+#else
     dst->in = (char *)(unsigned long)src->in;
     dst->out = (char *)(unsigned long)src->out;
+#endif
     dst->in_size = src->in_size;
     dst->out_size = src->out_size;
 }
@@ -45,12 +51,16 @@ afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
  */
 
 int
+#ifdef AFS_DARWIN100_ENV
+copyin_afs_ioctl(user_addr_t cmarg, struct afs_ioctl *dst)
+#else
 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
+#endif
 {
     int code;
 #if defined(AFS_DARWIN100_ENV)
     struct afs_ioctl32 dst32;
-    
+
     if (!proc_is64bit(current_proc())) {
        AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
        if (!code)
@@ -81,7 +91,7 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
     }
 #endif /* defined(AFS_HPUX_64BIT_ENV) */
 
-#if defined(AFS_SUN57_64BIT_ENV)
+#if defined(AFS_SUN5_64BIT_ENV)
     struct afs_ioctl32 dst32;
 
     if (get_udatamodel() == DATAMODEL_ILP32) {
@@ -90,7 +100,7 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
            afs_ioctl32_to_afs_ioctl(&dst32, dst);
        return code;
     }
-#endif /* defined(AFS_SUN57_64BIT_ENV) */
+#endif /* defined(AFS_SUN5_64BIT_ENV) */
 
 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
     struct afs_ioctl32 dst32;
@@ -104,38 +114,9 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
 
 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
-    struct afs_ioctl32 dst32;
+    if (afs_in_compat_syscall()) {
+       struct afs_ioctl32 dst32;
 
-#ifdef AFS_SPARC64_LINUX26_ENV
-    if (test_thread_flag(TIF_32BIT))
-#elif defined(AFS_SPARC64_LINUX24_ENV)
-    if (current->thread.flags & SPARC_FLAG_32BIT)
-#elif defined(AFS_SPARC64_LINUX20_ENV)
-    if (current->tss.flags & SPARC_FLAG_32BIT)
-
-#elif defined(AFS_AMD64_LINUX26_ENV)
-    if (test_thread_flag(TIF_IA32))
-#elif defined(AFS_AMD64_LINUX20_ENV)
-    if (current->thread.flags & THREAD_IA32)
-
-#elif defined(AFS_PPC64_LINUX26_ENV)
-#if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
-    if (current->thread_info->flags & _TIF_32BIT) 
-#else
-    if (task_thread_info(current)->flags & _TIF_32BIT) 
-#endif      
-#elif defined(AFS_PPC64_LINUX20_ENV)
-    if (current->thread.flags & PPC_FLAG_32BIT)
-
-#elif defined(AFS_S390X_LINUX26_ENV)
-    if (test_thread_flag(TIF_31BIT))
-#elif defined(AFS_S390X_LINUX20_ENV)
-    if (current->thread.flags & S390_FLAG_31BIT)
-
-#else
-#error pioctl32 not done for this linux
-#endif
-    {
        AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
        if (!code)
            afs_ioctl32_to_afs_ioctl(&dst32, dst);
@@ -161,8 +142,8 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
  */
 syscall(syscall, p1, p2, p3, p4, p5, p6)
 {
-    register rval1 = 0, code;
-    register monster;
+    int rval1 = 0, code;
+    int monster;
     int retval = 0;
 #ifndef AFS_AIX41_ENV
     extern lock_t kernel_lock;
@@ -318,10 +299,10 @@ Afs_syscall(struct afsargs *uap, rval_t * rvp)
 #else /* AFS_SGI_ENV */
 
 struct iparam {
-    long param1;
-    long param2;
-    long param3;
-    long param4;
+    iparmtype param1;
+    iparmtype param2;
+    iparmtype param3;
+    iparmtype param4;
 };
 
 struct iparam32 {
@@ -332,20 +313,23 @@ struct iparam32 {
 };
 
 
-#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)
+#if defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN5_64BIT_ENV) || (defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)) || defined(NEED_IOCTL32)
 static void
 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
 {
-    dst->param1 = src->param1;
-    dst->param2 = src->param2;
-    dst->param3 = src->param3;
-    dst->param4 = src->param4;
+    dst->param1 = (iparmtype)(uintptrsz)src->param1;
+    dst->param2 = (iparmtype)(uintptrsz)src->param2;
+    dst->param3 = (iparmtype)(uintptrsz)src->param3;
+    dst->param4 = (iparmtype)(uintptrsz)src->param4;
 }
 #endif
 
 /*
  * If you need to change copyin_iparam(), you may also need to change
  * copyin_afs_ioctl().
+ *
+ * This function is needed only for icreate, meaning, only on platforms
+ * providing the inode fileserver.
  */
 
 static int
@@ -353,16 +337,6 @@ copyin_iparam(caddr_t cmarg, struct iparam *dst)
 {
     int code;
 
-#if defined(AFS_DARWIN100_ENV)
-    struct iparam32 dst32;
-    
-    if (!proc_is64bit(current_proc())) {
-       AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
-       if (!code)
-           iparam32_to_iparam(&dst32, dst);
-       return code;
-    }
-#endif
 #if defined(AFS_HPUX_64BIT_ENV)
     struct iparam32 dst32;
 
@@ -374,7 +348,7 @@ copyin_iparam(caddr_t cmarg, struct iparam *dst)
     }
 #endif /* AFS_HPUX_64BIT_ENV */
 
-#if defined(AFS_SUN57_64BIT_ENV)
+#if defined(AFS_SUN5_64BIT_ENV)
     struct iparam32 dst32;
 
     if (get_udatamodel() == DATAMODEL_ILP32) {
@@ -383,41 +357,12 @@ copyin_iparam(caddr_t cmarg, struct iparam *dst)
            iparam32_to_iparam(&dst32, dst);
        return code;
     }
-#endif /* AFS_SUN57_64BIT_ENV */
+#endif /* AFS_SUN5_64BIT_ENV */
 
 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
-    struct iparam32 dst32;
+    if (afs_in_compat_syscall()) {
+       struct iparam32 dst32;
 
-#ifdef AFS_SPARC64_LINUX26_ENV
-    if (test_thread_flag(TIF_32BIT))
-#elif defined(AFS_SPARC64_LINUX24_ENV)
-    if (current->thread.flags & SPARC_FLAG_32BIT)
-#elif defined(AFS_SPARC64_LINUX20_ENV)
-    if (current->tss.flags & SPARC_FLAG_32BIT)
-
-#elif defined(AFS_AMD64_LINUX26_ENV)
-    if (test_thread_flag(TIF_IA32))
-#elif defined(AFS_AMD64_LINUX20_ENV)
-    if (current->thread.flags & THREAD_IA32)
-
-#elif defined(AFS_PPC64_LINUX26_ENV)
-#if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
-    if (current->thread_info->flags & _TIF_32BIT) 
-#else
-    if (task_thread_info(current)->flags & _TIF_32BIT) 
-#endif      
-#elif defined(AFS_PPC64_LINUX20_ENV)
-    if (current->thread.flags & PPC_FLAG_32BIT) 
-
-#elif defined(AFS_S390X_LINUX26_ENV)
-    if (test_thread_flag(TIF_31BIT))
-#elif defined(AFS_S390X_LINUX20_ENV)
-    if (current->thread.flags & S390_FLAG_31BIT) 
-
-#else
-#error iparam32 not done for this linux platform
-#endif
-    {
        AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
        if (!code)
            iparam32_to_iparam(&dst32, dst);
@@ -433,22 +378,10 @@ copyin_iparam(caddr_t cmarg, struct iparam *dst)
 #ifdef AFS_SUN5_ENV
 extern int afs_sinited;
 
-/** The 32 bit OS expects the members of this structure to be 32 bit
- * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
- * to accomodate both, *long* is used instead of afs_int32
- */
-
-#ifdef AFS_SUN57_ENV
-struct afssysa {
-    long syscall;
-    long parm1;
-    long parm2;
-    long parm3;
-    long parm4;
-    long parm5;
-    long parm6;
-};
-#else
+Afs_syscall(struct afssysa *uap, rval_t * rvp)
+{
+    int *retval = &rvp->r_val1;
+#elif defined(AFS_DARWIN100_ENV)
 struct afssysa {
     afs_int32 syscall;
     afs_int32 parm1;
@@ -458,24 +391,25 @@ struct afssysa {
     afs_int32 parm5;
     afs_int32 parm6;
 };
-#endif
-
-Afs_syscall(register struct afssysa *uap, rval_t * rvp)
+struct afssysa64 {
+    afs_int64 parm1;
+    afs_int64 parm2;
+    afs_int64 parm3;
+    afs_int64 parm4;
+    afs_int64 parm5;
+    afs_int64 parm6;
+    afs_int32 syscall;
+};
+int
+afs3_syscall(afs_proc_t *p, void *args, unsigned int *retval)
 {
-    int *retval = &rvp->r_val1;
-#else /* AFS_SUN5_ENV */
-#if    defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+    struct afssysa64 *uap64 = NULL;
+    struct afssysa *uap = NULL;
+#elif defined(AFS_FBSD_ENV)
 int
-afs3_syscall(p, args, retval)
-#ifdef AFS_FBSD50_ENV
-     struct thread *p;
-#else
-     struct proc *p;
-#endif
-     void *args;
-     long *retval;
+afs3_syscall(struct thread *p, void *args)
 {
-    register struct a {
+    struct a {
        long syscall;
        long parm1;
        long parm2;
@@ -484,8 +418,28 @@ afs3_syscall(p, args, retval)
        long parm5;
        long parm6;
     } *uap = (struct a *)args;
-#else /* AFS_OSF_ENV */
-#ifdef AFS_LINUX20_ENV
+    long fbsd_ret = 0;
+    long *retval = &fbsd_ret;
+#elif defined(AFS_NBSD40_ENV)
+int
+afs3_syscall(struct lwp *p, const void *args, register_t *retval)
+{
+    /* see osi_machdep.h */
+    struct afs_sysargs *uap = (struct afs_sysargs *) args;
+#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+int
+afs3_syscall(afs_proc_t *p, void *args, long *retval)
+{
+    struct a {
+       long syscall;
+       long parm1;
+       long parm2;
+       long parm3;
+       long parm4;
+       long parm5;
+       long parm6;
+    } *uap = (struct a *)args;
+#elif defined(AFS_LINUX20_ENV)
 struct afssysargs {
     long syscall;
     long parm1;
@@ -503,16 +457,16 @@ afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4)
     long linux_ret = 0;
     long *retval = &linux_ret;
     long eparm[4];             /* matches AFSCALL_ICL in fstrace.c */
-#ifdef AFS_SPARC64_LINUX24_ENV
+# ifdef AFS_SPARC64_LINUX24_ENV
     afs_int32 eparm32[4];
-#endif
+# endif
     /* eparm is also used by AFSCALL_CALL in afsd.c */
 #else
-#if defined(UKERNEL)
+# if defined(UKERNEL)
 int
-Afs_syscall()
+Afs_syscall(void)
 {
-    register struct a {
+    struct a {
        long syscall;
        long parm1;
        long parm2;
@@ -520,12 +474,12 @@ Afs_syscall()
        long parm4;
        long parm5;
        long parm6;
-    } *uap = (struct a *)u.u_ap;
-#else /* UKERNEL */
+    } *uap = (struct a *)get_user_struct()->u_ap;
+# else /* UKERNEL */
 int
 Afs_syscall()
 {
-    register struct a {
+    struct a {
        long syscall;
        long parm1;
        long parm2;
@@ -534,16 +488,16 @@ Afs_syscall()
        long parm5;
        long parm6;
     } *uap = (struct a *)u.u_ap;
-#endif /* UKERNEL */
-#if defined(AFS_HPUX_ENV)
+# endif /* UKERNEL */
+# if defined(AFS_HPUX_ENV)
     long *retval = &u.u_rval1;
-#else
+# elif defined(UKERNEL)
+    int *retval = &(get_user_struct()->u_rval1);
+# else
     int *retval = &u.u_rval1;
+# endif
 #endif
-#endif /* AFS_LINUX20_ENV */
-#endif /* AFS_OSF_ENV */
-#endif /* AFS_SUN5_ENV */
-    register int code = 0;
+    int code = 0;
 
     AFS_STATCNT(afs_syscall);
 #ifdef        AFS_SUN5_ENV
@@ -553,7 +507,6 @@ Afs_syscall()
     }
 #endif
 #ifdef AFS_LINUX20_ENV
-    lock_kernel();
     /* setup uap for use below - pull out the magic decoder ring to know
      * which syscalls have folded argument lists.
      */
@@ -599,6 +552,42 @@ Afs_syscall()
 #if defined(AFS_DARWIN80_ENV)
     get_vfs_context();
     osi_Assert(*retval == 0);
+#ifdef AFS_DARWIN100_ENV
+    if (proc_is64bit(p)) {
+       uap64 = (struct afssysa64 *)args;
+       if (uap64->syscall == AFSCALL_CALL) {
+           code =
+               afs_syscall64_call(uap64->parm1, uap64->parm2, uap64->parm3,
+                                  uap64->parm4, uap64->parm5, uap64->parm6);
+           /* pass back the code as syscall retval */
+           if (code < 0) {
+               *retval = code;
+               code = 0;
+           }
+       } else if (uap64->syscall == AFSCALL_SETPAG) {
+           AFS_GLOCK();
+           code = afs_setpag(p, args, retval);
+           AFS_GUNLOCK();
+       } else if (uap64->syscall == AFSCALL_PIOCTL) {
+           AFS_GLOCK();
+           code =
+               afs_syscall64_pioctl(uap64->parm1, (unsigned int)uap64->parm2,
+                                    uap64->parm3, (int)uap64->parm4,
+                                    kauth_cred_get());
+           AFS_GUNLOCK();
+       } else if (uap64->syscall == AFSCALL_ICL) {
+           AFS_GLOCK();
+           code =
+               Afscall64_icl(uap64->parm1, uap64->parm2, uap64->parm3,
+                           uap64->parm4, uap64->parm5, retval);
+           AFS_GUNLOCK();
+       } else
+           code = EINVAL;
+       if (uap64->syscall != AFSCALL_CALL)
+           put_vfs_context();
+    } else { /* and the default case for 32 bit procs */
+#endif
+       uap = (struct afssysa *)args;
 #endif
 #if defined(AFS_HPUX_ENV)
     /*
@@ -607,140 +596,222 @@ Afs_syscall()
      * duplication to handle the case of a dynamically loaded kernel
      * module?
      */
-    osi_InitGlock();
+       osi_InitGlock();
+#endif
+
+#if defined(AFS_NBSD40_ENV)
+       if (SCARG(uap, syscall) == AFSCALL_CALL) {
+           code =
+               afs_syscall_call(SCARG(uap, parm1), SCARG(uap, parm2),
+                                 SCARG(uap, parm3), SCARG(uap, parm4),
+                                 SCARG(uap, parm5), SCARG(uap, parm6));
+       } else if (SCARG(uap, syscall) == AFSCALL_SETPAG) {
+#else
+       if (uap->syscall == AFSCALL_CALL) {
+           code =
+               afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
+                                uap->parm4, uap->parm5, uap->parm6);
+#ifdef AFS_DARWIN_ENV
+           /* pass back the code as syscall retval */
+           if (code < 0) {
+               *retval = code;
+               code = 0;
+           }
+#endif
+       } else if (uap->syscall == AFSCALL_SETPAG) {
 #endif
-    if (uap->syscall == AFSCALL_CALL) {
-       code =
-           afs_syscall_call(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
-                            uap->parm5, uap->parm6);
-    } else if (uap->syscall == AFSCALL_SETPAG) {
 #ifdef AFS_SUN5_ENV
-       register proc_t *procp;
+           proc_t *procp;
 
-       procp = ttoproc(curthread);
-       AFS_GLOCK();
-       code = afs_setpag(&procp->p_cred);
-       AFS_GUNLOCK();
+           procp = ttoproc(curthread);
+           AFS_GLOCK();
+           code = afs_setpag(&procp->p_cred);
+           AFS_GUNLOCK();
 #else
-       AFS_GLOCK();
-#if    defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
-       code = afs_setpag(p, args, retval);
-#else /* AFS_OSF_ENV */
-       code = afs_setpag();
+           AFS_GLOCK();
+#if    defined(AFS_FBSD_ENV)
+           code = afs_setpag(p, args);
+#elif  defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+           code = afs_setpag(p, args, retval);
+#else /* AFS_DARWIN_ENV || AFS_XBSD_ENV */
+           code = afs_setpag();
 #endif
-       AFS_GUNLOCK();
+           AFS_GUNLOCK();
 #endif
-    } else if (uap->syscall == AFSCALL_PIOCTL) {
-       AFS_GLOCK();
+       } else if
+#if defined(AFS_NBSD40_ENV)
+               (SCARG(uap, syscall) == AFSCALL_PIOCTL) {
+#else
+           (uap->syscall == AFSCALL_PIOCTL) {
+#endif
+           AFS_GLOCK();
 #if defined(AFS_SUN5_ENV)
-       code =
-           afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
-                              rvp, CRED());
-#elif defined(AFS_FBSD50_ENV)
-       code =
-           afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
-                              p->td_ucred);
+           code =
+               afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
+                                  uap->parm4, rvp, CRED());
+#elif defined(AFS_FBSD_ENV)
+           code =
+               afs_syscall_pioctl((void *)uap->parm1, uap->parm2, (void *)uap->parm3,
+                                  uap->parm4, p->td_ucred);
 #elif defined(AFS_DARWIN80_ENV)
-       code =
-           afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
-                              kauth_cred_get());
+           code =
+               afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
+                                  uap->parm4, kauth_cred_get());
+#elif defined(AFS_NBSD40_ENV)
+           code =
+               afs_syscall_pioctl((char *)SCARG(uap, parm1), SCARG(uap, parm2),
+                                  (void *)SCARG(uap, parm3), SCARG(uap, parm4),
+                                  kauth_cred_get());
 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
-       code =
-           afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
-                              p->p_cred->pc_ucred);
+           code =
+               afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
+                                  uap->parm4, p->p_cred->pc_ucred);
 #else
-       code =
-           afs_syscall_pioctl((char *)uap->parm1, (unsigned int)uap->parm2, (caddr_t)uap->parm3,
-                              (int) uap->parm4);
+           code =
+               afs_syscall_pioctl((char *)uap->parm1,
+                                  (unsigned int)uap->parm2,
+                                  (caddr_t)uap->parm3,
+                                  (int) uap->parm4);
 #endif
-       AFS_GUNLOCK();
-    } else if (uap->syscall == AFSCALL_ICREATE) {
-       struct iparam iparams;
+           AFS_GUNLOCK();
+
+#ifdef AFS_NBSD40_ENV
+           } else if (SCARG(uap, syscall) == AFSCALL_ICREATE) {
+               struct iparam iparams;
+               code = copyin_iparam((char *) SCARG(uap, parm3), &iparams);
+#else
+       } else if (uap->syscall == AFSCALL_ICREATE) {
+           struct iparam iparams;
 
-       code = copyin_iparam((char *)uap->parm3, &iparams);
-       if (code) {
+           code = copyin_iparam((char *)uap->parm3, &iparams);
+#endif
+           if (code) {
 #if defined(KERNEL_HAVE_UERROR)
-           setuerror(code);
+               setuerror(code);
 #endif
-       } else
-#ifdef AFS_SUN5_ENV
-           code =
-               afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
-                                   iparams.param2, iparams.param3,
-                                   iparams.param4, rvp, CRED());
+           } else {
+#if defined(AFS_SUN5_ENV)
+               code =
+                   afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
+                                       iparams.param2, iparams.param3,
+                                       iparams.param4, rvp, CRED());
+#elif defined(AFS_NBSD40_ENV)
+               code =
+                       afs_syscall_icreate(SCARG(uap, parm1), SCARG(uap, parm2),
+                               iparams.param1, iparams.param2, iparams.param3,
+                               iparams.param4, retval
+                       );
 #else
+               code =
+                   afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
+                                       iparams.param2, iparams.param3,
+                                       iparams.param4
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+                                       , retval
+#endif
+                       );
+#endif /* AFS_SUN5_ENV */
+           }
+#if defined(AFS_NBSD40_ENV)
+           } else if (SCARG(uap, syscall) == AFSCALL_IOPEN) {
+#else
+           } else if (uap->syscall == AFSCALL_IOPEN) {
+#endif /* !AFS_NBSD40_ENV */
+#if defined(AFS_SUN5_ENV)
            code =
-               afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
-                                   iparams.param2,
-#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
-                                   iparams.param3, iparams.param4, retval);
+               afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp,
+                                 CRED());
+#elif defined(AFS_NBSD40_ENV)
+           code = afs_syscall_iopen(SCARG(uap, parm1), SCARG(uap, parm2),
+                                    SCARG(uap, parm3), retval);
 #else
-                                   iparams.param3, iparams.param4);
+           code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+                                    , retval
 #endif
+               );
 #endif /* AFS_SUN5_ENV */
-    } else if (uap->syscall == AFSCALL_IOPEN) {
-#ifdef AFS_SUN5_ENV
-       code =
-           afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp,
-                             CRED());
+#if defined(AFS_NBSD40_ENV)
+        } else if (SCARG(uap, syscall) == AFSCALL_IDEC) {
 #else
-#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
-       code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, retval);
+       } else if (uap->syscall == AFSCALL_IDEC) {
+#endif
+#if defined(AFS_NBSD40_ENV)
+           code = afs_syscall_iincdec(SCARG(uap, parm1), SCARG(uap, parm2),
+                                        SCARG(uap, parm3), -1);
 #else
-       code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3);
+
+
+           code =
+               afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1
+#if defined(AFS_SUN5_ENV)
+                                   , rvp, CRED()
 #endif
-#endif /* AFS_SUN5_ENV */
-    } else if (uap->syscall == AFSCALL_IDEC) {
-#ifdef AFS_SUN5_ENV
-       code =
-           afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1, rvp,
-                               CRED());
+                   );
+
+#endif /* !AFS_NBSD40_ENV */
+#if defined(AFS_NBSD40_ENV)
+           } else if (SCARG(uap, syscall) == AFSCALL_IINC) {
 #else
-       code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1);
-#endif /* AFS_SUN5_ENV */
-    } else if (uap->syscall == AFSCALL_IINC) {
+           } else if (uap->syscall == AFSCALL_IINC) {
+#endif
+#if defined(AFS_NBSD40_ENV)
+             code = afs_syscall_iincdec(SCARG(uap, parm1), SCARG(uap, parm2),
+                                        SCARG(uap, parm3), 1);
+#else
+           code =
+               afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1
 #ifdef AFS_SUN5_ENV
-       code =
-           afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1, rvp,
-                               CRED());
+                                   , rvp, CRED()
+#endif
+                   );
+#endif /* !AFS_NBSD40_ENV */
+#if defined(AFS_NBSD40_ENV)
+           } else if (SCARG(uap, syscall) == AFSCALL_ICL) {
 #else
-       code = afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1);
-#endif /* AFS_SUN5_ENV */
-    } else if (uap->syscall == AFSCALL_ICL) {
-       AFS_GLOCK();
-       code =
-           Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
-                       uap->parm5, retval);
-       AFS_GUNLOCK();
+           } else if (uap->syscall == AFSCALL_ICL) {
+#endif
+           AFS_GLOCK();
+           code =
+#if defined(AFS_NBSD40_ENV)
+             Afscall_icl(SCARG(uap, parm1), SCARG(uap, parm2),
+                         SCARG(uap, parm3), SCARG(uap, parm4),
+                         SCARG(uap, parm5), retval);
+#else
+               Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
+                           uap->parm5, (long *)retval);
+#endif /* !AFS_NBSD40_ENV */
+           AFS_GUNLOCK();
 #ifdef AFS_LINUX20_ENV
-       if (!code) {
-           /* ICL commands can return values. */
-           code = -linux_ret;  /* Gets negated again at exit below */
-       }
+           if (!code) {
+               /* ICL commands can return values. */
+               code = -linux_ret;      /* Gets negated again at exit below */
+           }
 #else
-       if (code) {
+           if (code) {
 #if defined(KERNEL_HAVE_UERROR)
-           setuerror(code);
+               setuerror(code);
 #endif
-       }
+           }
 #endif /* !AFS_LINUX20_ENV */
-    } else {
+       } else {
 #if defined(KERNEL_HAVE_UERROR)
-       setuerror(EINVAL);
+           setuerror(EINVAL);
 #else
-       code = EINVAL;
+           code = EINVAL;
 #endif
-    }
-
+       }
 #if defined(AFS_DARWIN80_ENV)
-    if (uap->syscall != AFSCALL_CALL)
-       put_vfs_context();
+       if (uap->syscall != AFSCALL_CALL)
+           put_vfs_context();
+#ifdef AFS_DARWIN100_ENV
+    } /* 32 bit procs */
+#endif
 #endif
 #ifdef AFS_LINUX20_ENV
     code = -code;
-    unlock_kernel();
 #endif
     return code;
 }
 #endif /* AFS_SGI_ENV */
-#endif /* !AFS_AIX32_ENV       */
+#endif /* !AFS_AIX32_ENV */