Author: trasz
Date: Sun Mar 19 14:46:40 2017
New Revision: 315553
URL: https://svnweb.freebsd.org/changeset/base/315553

Log:
  MFC r313018:
  
  Add kern_pread() and kern_pwrite(), and use it in compats instead
  of their sys_*() counterparts. The svr4 is left unchanged.
  
  Sponsored by: DARPA, AFRL

Modified:
  stable/11/sys/compat/freebsd32/freebsd32_misc.c
  stable/11/sys/compat/linux/linux_file.c
  stable/11/sys/kern/sys_generic.c
  stable/11/sys/sys/syscallsubr.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/compat/freebsd32/freebsd32_misc.c
==============================================================================
--- stable/11/sys/compat/freebsd32/freebsd32_misc.c     Sun Mar 19 14:42:16 
2017        (r315552)
+++ stable/11/sys/compat/freebsd32/freebsd32_misc.c     Sun Mar 19 14:46:40 
2017        (r315553)
@@ -1442,25 +1442,17 @@ freebsd4_freebsd32_fhstatfs(struct threa
 int
 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
 {
-       struct pread_args ap;
 
-       ap.fd = uap->fd;
-       ap.buf = uap->buf;
-       ap.nbyte = uap->nbyte;
-       ap.offset = PAIR32TO64(off_t,uap->offset);
-       return (sys_pread(td, &ap));
+       return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
+           PAIR32TO64(off_t, uap->offset)));
 }
 
 int
 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
 {
-       struct pwrite_args ap;
 
-       ap.fd = uap->fd;
-       ap.buf = uap->buf;
-       ap.nbyte = uap->nbyte;
-       ap.offset = PAIR32TO64(off_t,uap->offset);
-       return (sys_pwrite(td, &ap));
+       return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
+           PAIR32TO64(off_t, uap->offset)));
 }
 
 #ifdef COMPAT_43
@@ -1549,25 +1541,17 @@ freebsd32_getdirentries(struct thread *t
 int
 freebsd6_freebsd32_pread(struct thread *td, struct 
freebsd6_freebsd32_pread_args *uap)
 {
-       struct pread_args ap;
 
-       ap.fd = uap->fd;
-       ap.buf = uap->buf;
-       ap.nbyte = uap->nbyte;
-       ap.offset = PAIR32TO64(off_t,uap->offset);
-       return (sys_pread(td, &ap));
+       return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
+           PAIR32TO64(off_t, uap->offset)));
 }
 
 int
 freebsd6_freebsd32_pwrite(struct thread *td, struct 
freebsd6_freebsd32_pwrite_args *uap)
 {
-       struct pwrite_args ap;
 
-       ap.fd = uap->fd;
-       ap.buf = uap->buf;
-       ap.nbyte = uap->nbyte;
-       ap.offset = PAIR32TO64(off_t,uap->offset);
-       return (sys_pwrite(td, &ap));
+       return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
+           PAIR32TO64(off_t, uap->offset)));
 }
 
 int

Modified: stable/11/sys/compat/linux/linux_file.c
==============================================================================
--- stable/11/sys/compat/linux/linux_file.c     Sun Mar 19 14:42:16 2017        
(r315552)
+++ stable/11/sys/compat/linux/linux_file.c     Sun Mar 19 14:46:40 2017        
(r315553)
@@ -998,20 +998,13 @@ linux_fdatasync(td, uap)
 }
 
 int
-linux_pread(td, uap)
-       struct thread *td;
-       struct linux_pread_args *uap;
+linux_pread(struct thread *td, struct linux_pread_args *uap)
 {
-       struct pread_args bsd;
        cap_rights_t rights;
        struct vnode *vp;
        int error;
 
-       bsd.fd = uap->fd;
-       bsd.buf = uap->buf;
-       bsd.nbyte = uap->nbyte;
-       bsd.offset = uap->offset;
-       error = sys_pread(td, &bsd);
+       error = kern_pread(td, uap->fd, uap->buf, uap->nbyte, uap->offset);
        if (error == 0) {
                /* This seems to violate POSIX but linux does it */
                error = fgetvp(td, uap->fd,
@@ -1028,17 +1021,10 @@ linux_pread(td, uap)
 }
 
 int
-linux_pwrite(td, uap)
-       struct thread *td;
-       struct linux_pwrite_args *uap;
-{
-       struct pwrite_args bsd;
-
-       bsd.fd = uap->fd;
-       bsd.buf = uap->buf;
-       bsd.nbyte = uap->nbyte;
-       bsd.offset = uap->offset;
-       return (sys_pwrite(td, &bsd));
+linux_pwrite(struct thread *td, struct linux_pwrite_args *uap)
+{
+
+       return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
 }
 
 int

Modified: stable/11/sys/kern/sys_generic.c
==============================================================================
--- stable/11/sys/kern/sys_generic.c    Sun Mar 19 14:42:16 2017        
(r315552)
+++ stable/11/sys/kern/sys_generic.c    Sun Mar 19 14:46:40 2017        
(r315553)
@@ -220,39 +220,37 @@ struct pread_args {
 };
 #endif
 int
-sys_pread(td, uap)
-       struct thread *td;
-       struct pread_args *uap;
+sys_pread(struct thread *td, struct pread_args *uap)
+{
+
+       return (kern_pread(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
+}
+
+int
+kern_pread(struct thread *td, int fd, void *buf, size_t nbyte, off_t offset)
 {
        struct uio auio;
        struct iovec aiov;
        int error;
 
-       if (uap->nbyte > IOSIZE_MAX)
+       if (nbyte > IOSIZE_MAX)
                return (EINVAL);
-       aiov.iov_base = uap->buf;
-       aiov.iov_len = uap->nbyte;
+       aiov.iov_base = buf;
+       aiov.iov_len = nbyte;
        auio.uio_iov = &aiov;
        auio.uio_iovcnt = 1;
-       auio.uio_resid = uap->nbyte;
+       auio.uio_resid = nbyte;
        auio.uio_segflg = UIO_USERSPACE;
-       error = kern_preadv(td, uap->fd, &auio, uap->offset);
-       return(error);
+       error = kern_preadv(td, fd, &auio, offset);
+       return (error);
 }
 
 #if defined(COMPAT_FREEBSD6)
 int
-freebsd6_pread(td, uap)
-       struct thread *td;
-       struct freebsd6_pread_args *uap;
+freebsd6_pread(struct thread *td, struct freebsd6_pread_args *uap)
 {
-       struct pread_args oargs;
 
-       oargs.fd = uap->fd;
-       oargs.buf = uap->buf;
-       oargs.nbyte = uap->nbyte;
-       oargs.offset = uap->offset;
-       return (sys_pread(td, &oargs));
+       return (kern_pread(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
 }
 #endif
 
@@ -436,39 +434,38 @@ struct pwrite_args {
 };
 #endif
 int
-sys_pwrite(td, uap)
-       struct thread *td;
-       struct pwrite_args *uap;
+sys_pwrite(struct thread *td, struct pwrite_args *uap)
+{
+
+       return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
+}
+
+int
+kern_pwrite(struct thread *td, int fd, const void *buf, size_t nbyte,
+    off_t offset)
 {
        struct uio auio;
        struct iovec aiov;
        int error;
 
-       if (uap->nbyte > IOSIZE_MAX)
+       if (nbyte > IOSIZE_MAX)
                return (EINVAL);
-       aiov.iov_base = (void *)(uintptr_t)uap->buf;
-       aiov.iov_len = uap->nbyte;
+       aiov.iov_base = (void *)(uintptr_t)buf;
+       aiov.iov_len = nbyte;
        auio.uio_iov = &aiov;
        auio.uio_iovcnt = 1;
-       auio.uio_resid = uap->nbyte;
+       auio.uio_resid = nbyte;
        auio.uio_segflg = UIO_USERSPACE;
-       error = kern_pwritev(td, uap->fd, &auio, uap->offset);
+       error = kern_pwritev(td, fd, &auio, offset);
        return(error);
 }
 
 #if defined(COMPAT_FREEBSD6)
 int
-freebsd6_pwrite(td, uap)
-       struct thread *td;
-       struct freebsd6_pwrite_args *uap;
+freebsd6_pwrite(struct thread *td, struct freebsd6_pwrite_args *uap)
 {
-       struct pwrite_args oargs;
 
-       oargs.fd = uap->fd;
-       oargs.buf = uap->buf;
-       oargs.nbyte = uap->nbyte;
-       oargs.offset = uap->offset;
-       return (sys_pwrite(td, &oargs));
+       return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
 }
 #endif
 

Modified: stable/11/sys/sys/syscallsubr.h
==============================================================================
--- stable/11/sys/sys/syscallsubr.h     Sun Mar 19 14:42:16 2017        
(r315552)
+++ stable/11/sys/sys/syscallsubr.h     Sun Mar 19 14:46:40 2017        
(r315553)
@@ -177,11 +177,15 @@ int       kern_posix_fallocate(struct thread *
            off_t len);
 int    kern_procctl(struct thread *td, enum idtype idtype, id_t id, int com,
            void *data);
+int    kern_pread(struct thread *td, int fd, void *buf, size_t nbyte,
+           off_t offset);
 int    kern_preadv(struct thread *td, int fd, struct uio *auio, off_t offset);
 int    kern_pselect(struct thread *td, int nd, fd_set *in, fd_set *ou,
            fd_set *ex, struct timeval *tvp, sigset_t *uset, int abi_nfdbits);
 int    kern_ptrace(struct thread *td, int req, pid_t pid, void *addr,
            int data);
+int    kern_pwrite(struct thread *td, int fd, const void *buf, size_t nbyte,
+           off_t offset);
 int    kern_pwritev(struct thread *td, int fd, struct uio *auio, off_t offset);
 int    kern_readlinkat(struct thread *td, int fd, char *path,
            enum uio_seg pathseg, char *buf, enum uio_seg bufseg, size_t count);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to