[BACK]Return to linux_misc.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / compat / linux / common

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/compat/linux/common/linux_misc.c between version 1.149.2.1 and 1.150

version 1.149.2.1, 2006/09/09 02:45:52 version 1.150, 2006/02/09 19:18:56
Line 66 
Line 66 
 #include <sys/cdefs.h>  #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD$");  __KERNEL_RCSID(0, "$NetBSD$");
   
 #if defined(_KERNEL_OPT)  
 #include "opt_ptrace.h"  
 #endif  
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/systm.h>  #include <sys/systm.h>
 #include <sys/namei.h>  #include <sys/namei.h>
Line 99  __KERNEL_RCSID(0, "$NetBSD$");
Line 95  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/unistd.h>  #include <sys/unistd.h>
 #include <sys/swap.h>           /* for SWAP_ON */  #include <sys/swap.h>           /* for SWAP_ON */
 #include <sys/sysctl.h>         /* for KERN_DOMAINNAME */  #include <sys/sysctl.h>         /* for KERN_DOMAINNAME */
 #include <sys/kauth.h>  
   
 #include <sys/ptrace.h>  #include <sys/ptrace.h>
 #include <machine/ptrace.h>  #include <machine/ptrace.h>
   
 #include <sys/sa.h>  #include <sys/sa.h>
 #include <sys/syscall.h>  
 #include <sys/syscallargs.h>  #include <sys/syscallargs.h>
   
 #include <compat/linux/common/linux_machdep.h>  #include <compat/linux/common/linux_machdep.h>
Line 379  linux_sys_statfs(l, v, retval)
Line 373  linux_sys_statfs(l, v, retval)
                 syscallarg(struct linux_statfs *) sp;                  syscallarg(struct linux_statfs *) sp;
         } */ *uap = v;          } */ *uap = v;
         struct proc *p = l->l_proc;          struct proc *p = l->l_proc;
         struct statvfs *btmp, *bsp;          struct statvfs btmp, *bsp;
         struct linux_statfs ltmp;          struct linux_statfs ltmp;
         struct sys_statvfs1_args bsa;          struct sys_statvfs1_args bsa;
         caddr_t sg;          caddr_t sg;
         int error;          int error;
   
         sg = stackgap_init(p, 0);          sg = stackgap_init(p, 0);
         bsp = stackgap_alloc(p, &sg, sizeof (struct statvfs));          bsp = (struct statvfs *) stackgap_alloc(p, &sg, sizeof (struct statvfs));
   
         CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));          CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
   
Line 397  linux_sys_statfs(l, v, retval)
Line 391  linux_sys_statfs(l, v, retval)
         if ((error = sys_statvfs1(l, &bsa, retval)))          if ((error = sys_statvfs1(l, &bsa, retval)))
                 return error;                  return error;
   
         btmp = STATVFSBUF_GET();          if ((error = copyin((caddr_t) bsp, (caddr_t) &btmp, sizeof btmp)))
         error = copyin(bsp, btmp, sizeof(*btmp));                  return error;
         if (error) {  
                 goto out;          bsd_to_linux_statfs(&btmp, &ltmp);
         }  
         bsd_to_linux_statfs(btmp, &ltmp);          return copyout((caddr_t) &ltmp, (caddr_t) SCARG(uap, sp), sizeof ltmp);
         error = copyout(&ltmp, SCARG(uap, sp), sizeof ltmp);  
 out:  
         STATVFSBUF_PUT(btmp);  
         return error;  
 }  }
   
 int  int
Line 420  linux_sys_fstatfs(l, v, retval)
Line 410  linux_sys_fstatfs(l, v, retval)
                 syscallarg(struct linux_statfs *) sp;                  syscallarg(struct linux_statfs *) sp;
         } */ *uap = v;          } */ *uap = v;
         struct proc *p = l->l_proc;          struct proc *p = l->l_proc;
         struct statvfs *btmp, *bsp;          struct statvfs btmp, *bsp;
         struct linux_statfs ltmp;          struct linux_statfs ltmp;
         struct sys_fstatvfs1_args bsa;          struct sys_fstatvfs1_args bsa;
         caddr_t sg;          caddr_t sg;
         int error;          int error;
   
         sg = stackgap_init(p, 0);          sg = stackgap_init(p, 0);
         bsp = stackgap_alloc(p, &sg, sizeof (struct statvfs));          bsp = (struct statvfs *) stackgap_alloc(p, &sg, sizeof (struct statvfs));
   
         SCARG(&bsa, fd) = SCARG(uap, fd);          SCARG(&bsa, fd) = SCARG(uap, fd);
         SCARG(&bsa, buf) = bsp;          SCARG(&bsa, buf) = bsp;
Line 436  linux_sys_fstatfs(l, v, retval)
Line 426  linux_sys_fstatfs(l, v, retval)
         if ((error = sys_fstatvfs1(l, &bsa, retval)))          if ((error = sys_fstatvfs1(l, &bsa, retval)))
                 return error;                  return error;
   
         btmp = STATVFSBUF_GET();          if ((error = copyin((caddr_t) bsp, (caddr_t) &btmp, sizeof btmp)))
         error = copyin(bsp, btmp, sizeof(*btmp));                  return error;
         if (error) {  
                 goto out;          bsd_to_linux_statfs(&btmp, &ltmp);
         }  
         bsd_to_linux_statfs(btmp, &ltmp);          return copyout((caddr_t) &ltmp, (caddr_t) SCARG(uap, sp), sizeof ltmp);
         error = copyout(&ltmp, SCARG(uap, sp), sizeof ltmp);  
 out:  
         STATVFSBUF_PUT(btmp);  
         return error;  
 }  }
 # endif /* !__amd64__ */  # endif /* !__amd64__ */
   
Line 781  linux_sys_times(l, v, retval)
Line 767  linux_sys_times(l, v, retval)
         } */ *uap = v;          } */ *uap = v;
         struct proc *p = l->l_proc;          struct proc *p = l->l_proc;
         struct timeval t;          struct timeval t;
         int error;          int error, s;
   
         if (SCARG(uap, tms)) {          if (SCARG(uap, tms)) {
                 struct linux_tms ltms;                  struct linux_tms ltms;
Line 798  linux_sys_times(l, v, retval)
Line 784  linux_sys_times(l, v, retval)
                         return error;                          return error;
         }          }
   
         getmicrouptime(&t);          s = splclock();
           timersub(&time, &boottime, &t);
           splx(s);
   
         retval[0] = ((linux_clock_t)(CONVTCK(t)));          retval[0] = ((linux_clock_t)(CONVTCK(t)));
         return 0;          return 0;
Line 831  linux_sys_getdents(l, v, retval)
Line 819  linux_sys_getdents(l, v, retval)
                 syscallarg(struct linux_dirent *) dent;                  syscallarg(struct linux_dirent *) dent;
                 syscallarg(unsigned int) count;                  syscallarg(unsigned int) count;
         } */ *uap = v;          } */ *uap = v;
           struct proc *p = l->l_proc;
         struct dirent *bdp;          struct dirent *bdp;
         struct vnode *vp;          struct vnode *vp;
         caddr_t inp, tbuf;              /* BSD-format */          caddr_t inp, tbuf;              /* BSD-format */
Line 848  linux_sys_getdents(l, v, retval)
Line 837  linux_sys_getdents(l, v, retval)
         int ncookies;          int ncookies;
   
         /* getvnode() will use the descriptor for us */          /* getvnode() will use the descriptor for us */
         if ((error = getvnode(l->l_proc->p_fd, SCARG(uap, fd), &fp)) != 0)          if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
                 return (error);                  return (error);
   
         if ((fp->f_flag & FREAD) == 0) {          if ((fp->f_flag & FREAD) == 0) {
Line 862  linux_sys_getdents(l, v, retval)
Line 851  linux_sys_getdents(l, v, retval)
                 goto out1;                  goto out1;
         }          }
   
         if ((error = VOP_GETATTR(vp, &va, l->l_cred, l)))          if ((error = VOP_GETATTR(vp, &va, p->p_ucred, l)))
                 goto out1;                  goto out1;
   
         nbytes = SCARG(uap, count);          nbytes = SCARG(uap, count);
Line 886  again:
Line 875  again:
         auio.uio_iov = &aiov;          auio.uio_iov = &aiov;
         auio.uio_iovcnt = 1;          auio.uio_iovcnt = 1;
         auio.uio_rw = UIO_READ;          auio.uio_rw = UIO_READ;
           auio.uio_segflg = UIO_SYSSPACE;
           auio.uio_lwp = NULL;
         auio.uio_resid = buflen;          auio.uio_resid = buflen;
         auio.uio_offset = off;          auio.uio_offset = off;
         UIO_SETUP_SYSSPACE(&auio);  
         /*          /*
          * First we read into the malloc'ed buffer, then           * First we read into the malloc'ed buffer, then
          * we massage it into user space, one record at a time.           * we massage it into user space, one record at a time.
Line 1247  linux_sys_getgroups16(l, v, retval)
Line 1237  linux_sys_getgroups16(l, v, retval)
         struct sys_getgroups_args bsa;          struct sys_getgroups_args bsa;
         gid_t *bset, *kbset;          gid_t *bset, *kbset;
         linux_gid_t *lset;          linux_gid_t *lset;
         kauth_cred_t pc = l->l_cred;          struct pcred *pc = p->p_cred;
   
         n = SCARG(uap, gidsetsize);          n = SCARG(uap, gidsetsize);
         if (n < 0)          if (n < 0)
Line 1256  linux_sys_getgroups16(l, v, retval)
Line 1246  linux_sys_getgroups16(l, v, retval)
         bset = kbset = NULL;          bset = kbset = NULL;
         lset = NULL;          lset = NULL;
         if (n > 0) {          if (n > 0) {
                 n = min(kauth_cred_ngroups(pc), n);                  n = min(pc->pc_ucred->cr_ngroups, n);
                 sg = stackgap_init(p, 0);                  sg = stackgap_init(p, 0);
                 bset = stackgap_alloc(p, &sg, n * sizeof (gid_t));                  bset = stackgap_alloc(p, &sg, n * sizeof (gid_t));
                 kbset = malloc(n * sizeof (gid_t), M_TEMP, M_WAITOK);                  kbset = malloc(n * sizeof (gid_t), M_TEMP, M_WAITOK);
                 lset = malloc(n * sizeof (linux_gid_t), M_TEMP, M_WAITOK);                  lset = malloc(n * sizeof (linux_gid_t), M_TEMP, M_WAITOK);
                 if (bset == NULL || kbset == NULL || lset == NULL)                  if (bset == NULL || kbset == NULL || lset == NULL)
                 {                          return ENOMEM;
                         error = ENOMEM;  
                         goto out;  
                 }  
                 SCARG(&bsa, gidsetsize) = n;                  SCARG(&bsa, gidsetsize) = n;
                 SCARG(&bsa, gidset) = bset;                  SCARG(&bsa, gidset) = bset;
                 error = sys_getgroups(l, &bsa, retval);                  error = sys_getgroups(l, &bsa, retval);
Line 1279  linux_sys_getgroups16(l, v, retval)
Line 1266  linux_sys_getgroups16(l, v, retval)
                 error = copyout(lset, SCARG(uap, gidset),                  error = copyout(lset, SCARG(uap, gidset),
                     n * sizeof (linux_gid_t));                      n * sizeof (linux_gid_t));
         } else          } else
                 *retval = kauth_cred_ngroups(pc);                  *retval = pc->pc_ucred->cr_ngroups;
 out:  out:
         if (kbset != NULL)          if (kbset != NULL)
                 free(kbset, M_TEMP);                  free(kbset, M_TEMP);
Line 1313  linux_sys_setgroups16(l, v, retval)
Line 1300  linux_sys_setgroups16(l, v, retval)
         bset = stackgap_alloc(p, &sg, n * sizeof (gid_t));          bset = stackgap_alloc(p, &sg, n * sizeof (gid_t));
         lset = malloc(n * sizeof (linux_gid_t), M_TEMP, M_WAITOK);          lset = malloc(n * sizeof (linux_gid_t), M_TEMP, M_WAITOK);
         kbset = malloc(n * sizeof (gid_t), M_TEMP, M_WAITOK);          kbset = malloc(n * sizeof (gid_t), M_TEMP, M_WAITOK);
         if (bset == NULL || kbset == NULL || lset == NULL)          if (lset == NULL || bset == NULL)
         {                  return ENOMEM;
                 error = ENOMEM;  
                 goto out;  
         }  
         error = copyin(SCARG(uap, gidset), lset, n * sizeof (linux_gid_t));          error = copyin(SCARG(uap, gidset), lset, n * sizeof (linux_gid_t));
         if (error != 0)          if (error != 0)
                 goto out;                  goto out;
Line 1355  linux_sys_setfsuid(l, v, retval)
Line 1339  linux_sys_setfsuid(l, v, retval)
          struct linux_sys_setfsuid_args /* {           struct linux_sys_setfsuid_args /* {
                  syscallarg(uid_t) uid;                   syscallarg(uid_t) uid;
          } */ *uap = v;           } */ *uap = v;
            struct proc *p = l->l_proc;
          uid_t uid;           uid_t uid;
   
          uid = SCARG(uap, uid);           uid = SCARG(uap, uid);
          if (kauth_cred_getuid(l->l_cred) != uid)           if (p->p_cred->p_ruid != uid)
                  return sys_nosys(l, v, retval);                   return sys_nosys(l, v, retval);
          else           else
                  return (0);                   return (0);
Line 1412  linux_sys_getresuid(l, v, retval)
Line 1397  linux_sys_getresuid(l, v, retval)
                 syscallarg(uid_t *) euid;                  syscallarg(uid_t *) euid;
                 syscallarg(uid_t *) suid;                  syscallarg(uid_t *) suid;
         } */ *uap = v;          } */ *uap = v;
         kauth_cred_t pc = l->l_cred;          struct proc *p = l->l_proc;
           struct pcred *pc = p->p_cred;
         int error;          int error;
         uid_t uid;  
   
         /*          /*
          * Linux copies these values out to userspace like so:           * Linux copies these values out to userspace like so:
Line 1423  linux_sys_getresuid(l, v, retval)
Line 1408  linux_sys_getresuid(l, v, retval)
          *      2. If that succeeds, copy out euid.           *      2. If that succeeds, copy out euid.
          *      3. If both of those succeed, copy out suid.           *      3. If both of those succeed, copy out suid.
          */           */
         uid = kauth_cred_getuid(pc);          if ((error = copyout(&pc->p_ruid, SCARG(uap, ruid),
         if ((error = copyout(&uid, SCARG(uap, ruid), sizeof(uid_t))) != 0)                               sizeof(uid_t))) != 0)
                 return (error);                  return (error);
   
         uid = kauth_cred_geteuid(pc);          if ((error = copyout(&pc->pc_ucred->cr_uid, SCARG(uap, euid),
         if ((error = copyout(&uid, SCARG(uap, euid), sizeof(uid_t))) != 0)                               sizeof(uid_t))) != 0)
                 return (error);                  return (error);
   
         uid = kauth_cred_getsvuid(pc);          return (copyout(&pc->p_svuid, SCARG(uap, suid), sizeof(uid_t)));
   
         return (copyout(&uid, SCARG(uap, suid), sizeof(uid_t)));  
 }  }
   
 int  int
Line 1442  linux_sys_ptrace(l, v, retval)
Line 1425  linux_sys_ptrace(l, v, retval)
         void *v;          void *v;
         register_t *retval;          register_t *retval;
 {  {
 #if defined(PTRACE) || defined(_LKM)  
         struct linux_sys_ptrace_args /* {          struct linux_sys_ptrace_args /* {
                 i386, m68k, powerpc: T=int                  i386, m68k, powerpc: T=int
                 alpha, amd64: T=long                  alpha, amd64: T=long
Line 1454  linux_sys_ptrace(l, v, retval)
Line 1436  linux_sys_ptrace(l, v, retval)
         const int *ptr;          const int *ptr;
         int request;          int request;
         int error;          int error;
 #ifdef _LKM  
 #define sys_ptrace (*sysent[SYS_ptrace].sy_call)  
 #endif  
   
         ptr = linux_ptrace_request_map;          ptr = linux_ptrace_request_map;
         request = SCARG(uap, request);          request = SCARG(uap, request);
Line 1498  linux_sys_ptrace(l, v, retval)
Line 1477  linux_sys_ptrace(l, v, retval)
                         ptr++;                          ptr++;
   
         return LINUX_SYS_PTRACE_ARCH(l, uap, retval);          return LINUX_SYS_PTRACE_ARCH(l, uap, retval);
 #else  
         return ENOSYS;  
 #endif /* PTRACE || _LKM */  
 }  }
   
 int  int
Line 1516  linux_sys_reboot(struct lwp *l, void *v,
Line 1492  linux_sys_reboot(struct lwp *l, void *v,
                 syscallarg(int) opt;                  syscallarg(int) opt;
                 syscallarg(char *) bootstr;                  syscallarg(char *) bootstr;
         } */ sra;          } */ sra;
           struct proc *p = l->l_proc;
         int error;          int error;
   
         if ((error = kauth_authorize_generic(l->l_cred,          if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
             KAUTH_GENERIC_ISSUSER, &l->l_acflag)) != 0)  
                 return(error);                  return(error);
   
         if (SCARG(uap, magic1) != LINUX_REBOOT_MAGIC1)          if (SCARG(uap, magic1) != LINUX_REBOOT_MAGIC1)
Line 1632  linux_sys_sysinfo(l, v, retval)
Line 1608  linux_sys_sysinfo(l, v, retval)
         struct linux_sysinfo si;          struct linux_sysinfo si;
         struct loadavg *la;          struct loadavg *la;
   
         si.uptime = time_uptime;          si.uptime = time.tv_sec - boottime.tv_sec;
         la = &averunnable;          la = &averunnable;
         si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;          si.loads[0] = la->ldavg[0] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
         si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;          si.loads[1] = la->ldavg[1] * LINUX_SYSINFO_LOADS_SCALE / la->fscale;
Line 1754  linux_sys_nosys(l, v, retval)
Line 1730  linux_sys_nosys(l, v, retval)
         return (ENOSYS);          return (ENOSYS);
 }  }
   
 int  
 linux_sys_getpriority(l, v, retval)  
         struct lwp *l;  
         void *v;  
         register_t *retval;  
 {  
         struct linux_sys_getpriority_args /* {  
                 syscallarg(int) which;  
                 syscallarg(int) who;  
         } */ *uap = v;  
         struct sys_getpriority_args bsa;  
         int error;  
   
         SCARG(&bsa, which) = SCARG(uap, which);  
         SCARG(&bsa, who) = SCARG(uap, who);  
   
         if ((error = sys_getpriority(l, &bsa, retval)))  
                 return error;  
   
         *retval = NZERO - *retval;  
   
         return 0;  
 }  
   
 #endif /* !COMPAT_LINUX32 */  #endif /* !COMPAT_LINUX32 */

Legend:
Removed from v.1.149.2.1  
changed lines
  Added in v.1.150

CVSweb <webmaster@jp.NetBSD.org>