svn commit: r315549 - in stable/11/sys: compat/cloudabi compat/linux kern sys
Edward Tomasz Napierala
trasz at FreeBSD.org
Sun Mar 19 14:25:25 UTC 2017
Author: trasz
Date: Sun Mar 19 14:25:23 2017
New Revision: 315549
URL: https://svnweb.freebsd.org/changeset/base/315549
Log:
MFC r312988:
Add kern_listen(), kern_shutdown(), and kern_socket(), and use them
instead of their sys_*() counterparts in various compats. The svr4
is left untouched, because there's no point.
Sponsored by: DARPA, AFRL
Modified:
stable/11/sys/compat/cloudabi/cloudabi_fd.c
stable/11/sys/compat/cloudabi/cloudabi_sock.c
stable/11/sys/compat/linux/linux_socket.c
stable/11/sys/kern/uipc_syscalls.c
stable/11/sys/sys/syscallsubr.h
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/sys/compat/cloudabi/cloudabi_fd.c
==============================================================================
--- stable/11/sys/compat/cloudabi/cloudabi_fd.c Sun Mar 19 14:12:55 2017 (r315548)
+++ stable/11/sys/compat/cloudabi/cloudabi_fd.c Sun Mar 19 14:25:23 2017 (r315549)
@@ -100,9 +100,6 @@ cloudabi_sys_fd_create1(struct thread *t
struct cloudabi_sys_fd_create1_args *uap)
{
struct filecaps fcaps = {};
- struct socket_args socket_args = {
- .domain = AF_UNIX,
- };
switch (uap->type) {
case CLOUDABI_FILETYPE_POLL:
@@ -113,14 +110,11 @@ cloudabi_sys_fd_create1(struct thread *t
CAP_MMAP_RWX);
return (kern_shm_open(td, SHM_ANON, O_RDWR, 0, &fcaps));
case CLOUDABI_FILETYPE_SOCKET_DGRAM:
- socket_args.type = SOCK_DGRAM;
- return (sys_socket(td, &socket_args));
+ return (kern_socket(td, AF_UNIX, SOCK_DGRAM, 0));
case CLOUDABI_FILETYPE_SOCKET_SEQPACKET:
- socket_args.type = SOCK_SEQPACKET;
- return (sys_socket(td, &socket_args));
+ return (kern_socket(td, AF_UNIX, SOCK_SEQPACKET, 0));
case CLOUDABI_FILETYPE_SOCKET_STREAM:
- socket_args.type = SOCK_STREAM;
- return (sys_socket(td, &socket_args));
+ return (kern_socket(td, AF_UNIX, SOCK_STREAM, 0));
default:
return (EINVAL);
}
Modified: stable/11/sys/compat/cloudabi/cloudabi_sock.c
==============================================================================
--- stable/11/sys/compat/cloudabi/cloudabi_sock.c Sun Mar 19 14:12:55 2017 (r315548)
+++ stable/11/sys/compat/cloudabi/cloudabi_sock.c Sun Mar 19 14:25:23 2017 (r315549)
@@ -35,7 +35,6 @@ __FBSDID("$FreeBSD$");
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/syscallsubr.h>
-#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/un.h>
@@ -165,37 +164,31 @@ int
cloudabi_sys_sock_listen(struct thread *td,
struct cloudabi_sys_sock_listen_args *uap)
{
- struct listen_args listen_args = {
- .s = uap->sock,
- .backlog = uap->backlog,
- };
- return (sys_listen(td, &listen_args));
+ return (kern_listen(td, uap->sock, uap->backlog));
}
int
cloudabi_sys_sock_shutdown(struct thread *td,
struct cloudabi_sys_sock_shutdown_args *uap)
{
- struct shutdown_args shutdown_args = {
- .s = uap->sock,
- };
+ int how;
switch (uap->how) {
case CLOUDABI_SHUT_RD:
- shutdown_args.how = SHUT_RD;
+ how = SHUT_RD;
break;
case CLOUDABI_SHUT_WR:
- shutdown_args.how = SHUT_WR;
+ how = SHUT_WR;
break;
case CLOUDABI_SHUT_RD | CLOUDABI_SHUT_WR:
- shutdown_args.how = SHUT_RDWR;
+ how = SHUT_RDWR;
break;
default:
return (EINVAL);
}
- return (sys_shutdown(td, &shutdown_args));
+ return (kern_shutdown(td, uap->sock, how));
}
int
Modified: stable/11/sys/compat/linux/linux_socket.c
==============================================================================
--- stable/11/sys/compat/linux/linux_socket.c Sun Mar 19 14:12:55 2017 (r315548)
+++ stable/11/sys/compat/linux/linux_socket.c Sun Mar 19 14:25:23 2017 (r315549)
@@ -697,32 +697,26 @@ goout:
int
linux_socket(struct thread *td, struct linux_socket_args *args)
{
- struct socket_args /* {
- int domain;
- int type;
- int protocol;
- } */ bsd_args;
- int retval_socket;
+ int domain, retval_socket, type;
- bsd_args.protocol = args->protocol;
- bsd_args.type = args->type & LINUX_SOCK_TYPE_MASK;
- if (bsd_args.type < 0 || bsd_args.type > LINUX_SOCK_MAX)
+ type = args->type & LINUX_SOCK_TYPE_MASK;
+ if (type < 0 || type > LINUX_SOCK_MAX)
return (EINVAL);
retval_socket = linux_set_socket_flags(args->type & ~LINUX_SOCK_TYPE_MASK,
- &bsd_args.type);
+ &type);
if (retval_socket != 0)
return (retval_socket);
- bsd_args.domain = linux_to_bsd_domain(args->domain);
- if (bsd_args.domain == -1)
+ domain = linux_to_bsd_domain(args->domain);
+ if (domain == -1)
return (EAFNOSUPPORT);
- retval_socket = sys_socket(td, &bsd_args);
+ retval_socket = kern_socket(td, domain, type, args->protocol);
if (retval_socket)
return (retval_socket);
- if (bsd_args.type == SOCK_RAW
- && (bsd_args.protocol == IPPROTO_RAW || bsd_args.protocol == 0)
- && bsd_args.domain == PF_INET) {
+ if (type == SOCK_RAW
+ && (args->protocol == IPPROTO_RAW || args->protocol == 0)
+ && domain == PF_INET) {
/* It's a raw IP socket: set the IP_HDRINCL option. */
int hdrincl;
@@ -738,7 +732,7 @@ linux_socket(struct thread *td, struct l
* For simplicity we do this unconditionally of the net.inet6.ip6.v6only
* sysctl value.
*/
- if (bsd_args.domain == PF_INET6) {
+ if (domain == PF_INET6) {
int v6only;
v6only = 0;
@@ -816,14 +810,8 @@ linux_connect(struct thread *td, struct
int
linux_listen(struct thread *td, struct linux_listen_args *args)
{
- struct listen_args /* {
- int s;
- int backlog;
- } */ bsd_args;
- bsd_args.s = args->s;
- bsd_args.backlog = args->backlog;
- return (sys_listen(td, &bsd_args));
+ return (kern_listen(td, args->s, args->backlog));
}
static int
@@ -1523,14 +1511,8 @@ linux_recvmmsg(struct thread *td, struct
int
linux_shutdown(struct thread *td, struct linux_shutdown_args *args)
{
- struct shutdown_args /* {
- int s;
- int how;
- } */ bsd_args;
- bsd_args.s = args->s;
- bsd_args.how = args->how;
- return (sys_shutdown(td, &bsd_args));
+ return (kern_shutdown(td, args->s, args->how));
}
int
Modified: stable/11/sys/kern/uipc_syscalls.c
==============================================================================
--- stable/11/sys/kern/uipc_syscalls.c Sun Mar 19 14:12:55 2017 (r315548)
+++ stable/11/sys/kern/uipc_syscalls.c Sun Mar 19 14:25:23 2017 (r315549)
@@ -130,13 +130,19 @@ sys_socket(td, uap)
int protocol;
} */ *uap;
{
+
+ return (kern_socket(td, uap->domain, uap->type, uap->protocol));
+}
+
+int
+kern_socket(struct thread *td, int domain, int type, int protocol)
+{
struct socket *so;
struct file *fp;
- int fd, error, type, oflag, fflag;
+ int fd, error, oflag, fflag;
- AUDIT_ARG_SOCKET(uap->domain, uap->type, uap->protocol);
+ AUDIT_ARG_SOCKET(domain, type, protocol);
- type = uap->type;
oflag = 0;
fflag = 0;
if ((type & SOCK_CLOEXEC) != 0) {
@@ -149,8 +155,7 @@ sys_socket(td, uap)
}
#ifdef MAC
- error = mac_socket_check_create(td->td_ucred, uap->domain, type,
- uap->protocol);
+ error = mac_socket_check_create(td->td_ucred, domain, type, protocol);
if (error != 0)
return (error);
#endif
@@ -158,8 +163,7 @@ sys_socket(td, uap)
if (error != 0)
return (error);
/* An extra reference on `fp' has been held for us by falloc(). */
- error = socreate(uap->domain, &so, type, uap->protocol,
- td->td_ucred, td);
+ error = socreate(domain, &so, type, protocol, td->td_ucred, td);
if (error != 0) {
fdclose(td, fp, fd);
} else {
@@ -258,13 +262,20 @@ sys_listen(td, uap)
int backlog;
} */ *uap;
{
+
+ return (kern_listen(td, uap->s, uap->backlog));
+}
+
+int
+kern_listen(struct thread *td, int s, int backlog)
+{
struct socket *so;
struct file *fp;
cap_rights_t rights;
int error;
- AUDIT_ARG_FD(uap->s);
- error = getsock_cap(td, uap->s, cap_rights_init(&rights, CAP_LISTEN),
+ AUDIT_ARG_FD(s);
+ error = getsock_cap(td, s, cap_rights_init(&rights, CAP_LISTEN),
&fp, NULL, NULL);
if (error == 0) {
so = fp->f_data;
@@ -272,10 +283,10 @@ sys_listen(td, uap)
error = mac_socket_check_listen(td->td_ucred, so);
if (error == 0)
#endif
- error = solisten(so, uap->backlog, td);
+ error = solisten(so, backlog, td);
fdrop(fp, td);
}
- return(error);
+ return (error);
}
/*
@@ -1328,17 +1339,24 @@ sys_shutdown(td, uap)
int how;
} */ *uap;
{
+
+ return (kern_shutdown(td, uap->s, uap->how));
+}
+
+int
+kern_shutdown(struct thread *td, int s, int how)
+{
struct socket *so;
struct file *fp;
cap_rights_t rights;
int error;
- AUDIT_ARG_FD(uap->s);
- error = getsock_cap(td, uap->s, cap_rights_init(&rights, CAP_SHUTDOWN),
+ AUDIT_ARG_FD(s);
+ error = getsock_cap(td, s, cap_rights_init(&rights, CAP_SHUTDOWN),
&fp, NULL, NULL);
if (error == 0) {
so = fp->f_data;
- error = soshutdown(so, uap->how);
+ error = soshutdown(so, how);
/*
* Previous versions did not return ENOTCONN, but 0 in
* case the socket was not connected. Some important
Modified: stable/11/sys/sys/syscallsubr.h
==============================================================================
--- stable/11/sys/sys/syscallsubr.h Sun Mar 19 14:12:55 2017 (r315548)
+++ stable/11/sys/sys/syscallsubr.h Sun Mar 19 14:25:23 2017 (r315549)
@@ -136,6 +136,8 @@ int kern_kldstat(struct thread *td, int
int kern_kldunload(struct thread *td, int fileid, int flags);
int kern_linkat(struct thread *td, int fd1, int fd2, char *path1,
char *path2, enum uio_seg segflg, int follow);
+int kern_listen(struct thread *td, int s, int backlog);
+int kern_lseek(struct thread *td, int fd, off_t offset, int whence);
int kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg,
struct timeval *tptr, enum uio_seg tptrseg);
int kern_madvise(struct thread *td, uintptr_t addr, size_t len, int behav);
@@ -224,6 +226,7 @@ int kern_shmat(struct thread *td, int sh
int shmflg);
int kern_shmctl(struct thread *td, int shmid, int cmd, void *buf,
size_t *bufsz);
+int kern_shutdown(struct thread *td, int s, int how);
int kern_sigaction(struct thread *td, int sig, const struct sigaction *act,
struct sigaction *oact, int flags);
int kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss);
@@ -232,6 +235,7 @@ int kern_sigprocmask(struct thread *td,
int kern_sigsuspend(struct thread *td, sigset_t mask);
int kern_sigtimedwait(struct thread *td, sigset_t waitset,
struct ksiginfo *ksi, struct timespec *timeout);
+int kern_socket(struct thread *td, int domain, int type, int protocol);
int kern_statat(struct thread *td, int flag, int fd, char *path,
enum uio_seg pathseg, struct stat *sbp,
void (*hook)(struct vnode *vp, struct stat *sbp));
More information about the svn-src-stable-11
mailing list