summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2017-03-19 14:46:40 +0000
committertrasz <trasz@FreeBSD.org>2017-03-19 14:46:40 +0000
commita43cc8b98dc6738add7832af5e872a83d666a0de (patch)
treeebc11897e21564e3a9bc83f4d97b95455175defa /sys
parentdda33d70766a6fd935229fd6293181d7dae494f7 (diff)
downloadFreeBSD-src-a43cc8b98dc6738add7832af5e872a83d666a0de.zip
FreeBSD-src-a43cc8b98dc6738add7832af5e872a83d666a0de.tar.gz
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
Diffstat (limited to 'sys')
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c32
-rw-r--r--sys/compat/linux/linux_file.c22
-rw-r--r--sys/kern/sys_generic.c67
-rw-r--r--sys/sys/syscallsubr.h4
4 files changed, 48 insertions, 77 deletions
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 7c354c8..8857e91 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -1442,25 +1442,17 @@ freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatf
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 *td,
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
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index b549274..37b8595 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -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;
+linux_pwrite(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));
+ return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
}
int
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index ab875a1..acf05d1 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -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
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index d938563..f9cb3ed 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -177,11 +177,15 @@ int kern_posix_fallocate(struct thread *td, int fd, off_t offset,
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);
OpenPOWER on IntegriCloud