Add support for arm64_linux26
[openafs.git] / src / afs / afs_syscall.c
index f5dcf56..ce6afdf 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 "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)
 {
@@ -63,7 +60,7 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
     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)
@@ -94,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) {
@@ -103,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;
@@ -133,10 +130,10 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
 
 #elif defined(AFS_PPC64_LINUX26_ENV)
 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
-    if (current->thread_info->flags & _TIF_32BIT) 
+    if (current->thread_info->flags & _TIF_32BIT)
 #else
-    if (task_thread_info(current)->flags & _TIF_32BIT) 
-#endif      
+    if (task_thread_info(current)->flags & _TIF_32BIT)
+#endif
 #elif defined(AFS_PPC64_LINUX20_ENV)
     if (current->thread.flags & PPC_FLAG_32BIT)
 
@@ -144,6 +141,8 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
     if (test_thread_flag(TIF_31BIT))
 #elif defined(AFS_S390X_LINUX20_ENV)
     if (current->thread.flags & S390_FLAG_31BIT)
+#elif defined(AFS_ARM64_LINUX26_ENV)
+    if (is_compat_task())
 
 #else
 #error pioctl32 not done for this linux
@@ -174,8 +173,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;
@@ -345,16 +344,7 @@ 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 SIZEOF_VOID_P == SIZEOF_UNSIGNED_INT
-# define uintptrsz unsigned int
-#elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG
-# define uintptrsz unsigned long
-#elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG_LONG
-# define uintptrsz unsigned long long
-#else
-# error "Unable to determine casting for pointers"
-#endif
+#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)
 {
@@ -389,7 +379,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) {
@@ -398,7 +388,7 @@ 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;
@@ -417,17 +407,19 @@ copyin_iparam(caddr_t cmarg, struct iparam *dst)
 
 #elif defined(AFS_PPC64_LINUX26_ENV)
 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
-    if (current->thread_info->flags & _TIF_32BIT) 
+    if (current->thread_info->flags & _TIF_32BIT)
 #else
-    if (task_thread_info(current)->flags & _TIF_32BIT) 
-#endif      
+    if (task_thread_info(current)->flags & _TIF_32BIT)
+#endif
 #elif defined(AFS_PPC64_LINUX20_ENV)
-    if (current->thread.flags & PPC_FLAG_32BIT) 
+    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) 
+    if (current->thread.flags & S390_FLAG_31BIT)
+#elif defined(AFS_ARM64_LINUX26_ENV)
+    if (is_compat_task())
 
 #else
 #error iparam32 not done for this linux platform
@@ -448,34 +440,7 @@ 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
-struct afssysa {
-    afs_int32 syscall;
-    afs_int32 parm1;
-    afs_int32 parm2;
-    afs_int32 parm3;
-    afs_int32 parm4;
-    afs_int32 parm5;
-    afs_int32 parm6;
-};
-# endif
-
-Afs_syscall(register struct afssysa *uap, rval_t * rvp)
+Afs_syscall(struct afssysa *uap, rval_t * rvp)
 {
     int *retval = &rvp->r_val1;
 #elif defined(AFS_DARWIN100_ENV)
@@ -506,7 +471,7 @@ afs3_syscall(afs_proc_t *p, void *args, unsigned int *retval)
 int
 afs3_syscall(struct thread *p, void *args)
 {
-    register struct a {
+    struct a {
        long syscall;
        long parm1;
        long parm2;
@@ -515,12 +480,19 @@ afs3_syscall(struct thread *p, void *args)
        long parm5;
        long parm6;
     } *uap = (struct a *)args;
-    long *retval;
+    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)
 {
-    register struct a {
+    struct a {
        long syscall;
        long parm1;
        long parm2;
@@ -554,9 +526,9 @@ afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4)
 #else
 # if defined(UKERNEL)
 int
-Afs_syscall()
+Afs_syscall(void)
 {
-    register struct a {
+    struct a {
        long syscall;
        long parm1;
        long parm2;
@@ -569,7 +541,7 @@ Afs_syscall()
 int
 Afs_syscall()
 {
-    register struct a {
+    struct a {
        long syscall;
        long parm1;
        long parm2;
@@ -587,7 +559,7 @@ Afs_syscall()
     int *retval = &u.u_rval1;
 # endif
 #endif
-    register int code = 0;
+    int code = 0;
 
     AFS_STATCNT(afs_syscall);
 #ifdef        AFS_SUN5_ENV
@@ -597,7 +569,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.
      */
@@ -689,6 +660,15 @@ Afs_syscall()
      */
        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,
@@ -701,8 +681,9 @@ Afs_syscall()
            }
 #endif
        } else if (uap->syscall == AFSCALL_SETPAG) {
+#endif
 #ifdef AFS_SUN5_ENV
-           register proc_t *procp;
+           proc_t *procp;
 
            procp = ttoproc(curthread);
            AFS_GLOCK();
@@ -719,20 +700,30 @@ Afs_syscall()
 #endif
            AFS_GUNLOCK();
 #endif
-       } else if (uap->syscall == AFSCALL_PIOCTL) {
+       } 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)
+#elif defined(AFS_FBSD_ENV)
            code =
-               afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
+               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());
+#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,
@@ -745,20 +736,33 @@ Afs_syscall()
                                   (int) uap->parm4);
 #endif
            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);
+#endif
            if (code) {
 #if defined(KERNEL_HAVE_UERROR)
                setuerror(code);
 #endif
            } else {
-#ifdef AFS_SUN5_ENV
+#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,
@@ -770,11 +774,18 @@ Afs_syscall()
                        );
 #endif /* AFS_SUN5_ENV */
            }
-       } else if (uap->syscall == AFSCALL_IOPEN) {
-#ifdef 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_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
            code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3
 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
@@ -782,25 +793,56 @@ Afs_syscall()
 #endif
                );
 #endif /* AFS_SUN5_ENV */
+#if defined(AFS_NBSD40_ENV)
+        } else if (SCARG(uap, syscall) == AFSCALL_IDEC) {
+#else
        } 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_iincdec(uap->parm1, uap->parm2, uap->parm3, -1
-#ifdef AFS_SUN5_ENV
+#if defined(AFS_SUN5_ENV)
                                    , rvp, CRED()
 #endif
                    );
-       } else if (uap->syscall == AFSCALL_IINC) {
+
+#endif /* !AFS_NBSD40_ENV */
+#if defined(AFS_NBSD40_ENV)
+           } else if (SCARG(uap, syscall) == AFSCALL_IINC) {
+#else
+           } 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
                                    , rvp, CRED()
 #endif
                    );
-       } else if (uap->syscall == AFSCALL_ICL) {
+#endif /* !AFS_NBSD40_ENV */
+#if defined(AFS_NBSD40_ENV)
+           } else if (SCARG(uap, syscall) == AFSCALL_ICL) {
+#else
+           } 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) {
@@ -830,7 +872,6 @@ Afs_syscall()
 #endif
 #ifdef AFS_LINUX20_ENV
     code = -code;
-    unlock_kernel();
 #endif
     return code;
 }