diff options
Diffstat (limited to 'freebsd/sys/kern/uipc_syscalls.c')
-rw-r--r-- | freebsd/sys/kern/uipc_syscalls.c | 527 |
1 files changed, 28 insertions, 499 deletions
diff --git a/freebsd/sys/kern/uipc_syscalls.c b/freebsd/sys/kern/uipc_syscalls.c index 251f2bbb..a2f7d6f8 100644 --- a/freebsd/sys/kern/uipc_syscalls.c +++ b/freebsd/sys/kern/uipc_syscalls.c @@ -78,9 +78,9 @@ __FBSDID("$FreeBSD$"); static int sendit(struct thread *td, int s, struct msghdr *mp, int flags); static int recvit(struct thread *td, int s, struct msghdr *mp, void *namelenp); -#ifndef __rtems__ static int accept1(struct thread *td, int s, struct sockaddr *uname, socklen_t *anamelen, int flags); +#ifndef __rtems__ static int getsockname1(struct thread *td, struct getsockname_args *uap, int compat); static int getpeername1(struct thread *td, struct getpeername_args *uap, @@ -90,20 +90,29 @@ struct getsockaddr_sockaddr { struct sockaddr header; char data[SOCK_MAXADDRLEN - sizeof(struct sockaddr)]; } __aligned(sizeof(long)); +/* + * The getsockaddr is used else where with an allocation. Having a version + * local that does not alloc is a nice optimisation but we need to maintain + * the exported version. See nfs_mount in nfs_clvfsops.c. + */ +static int +getsockaddr_noalloc(struct sockaddr **namp, const struct sockaddr *uaddr, size_t len) +{ + struct sockaddr *sa; -static int getsockaddr(struct sockaddr **, const struct sockaddr *, size_t); -static int kern_getsockname(struct thread *, int, struct sockaddr **, - socklen_t *); -static int kern_listen(struct thread *, int, int); -static int kern_setsockopt(struct thread *, int, int, int, const void *, - enum uio_seg, socklen_t); -static int kern_shutdown(struct thread *, int, int); -static int kern_socket(struct thread *, int, int, int); -static int kern_socketpair(struct thread *, int, int, int, int *); + if (len > SOCK_MAXADDRLEN) + return (ENAMETOOLONG); + if (len < offsetof(struct sockaddr, sa_data[0])) + return (EINVAL); + sa = memcpy(*namp, uaddr, len); + sa->sa_len = len; + return (0); +} +#define getsockaddr_hold getsockadd +#define getsockaddr getsockaddr_noalloc #endif /* __rtems__ */ static int sockargs(struct mbuf **, char *, socklen_t, int); -#ifndef __rtems__ /* * Convert a user file descriptor to a kernel file entry and check if required * capability rights are present. @@ -131,46 +140,6 @@ getsock_cap(struct thread *td, int fd, cap_rights_t *rightsp, *fpp = fp; return (0); } -#else /* __rtems__ */ -static int -rtems_bsd_getsock(int fd, struct file **fpp, u_int *fflagp) -{ - struct file *fp; - int error; - - if ((uint32_t) fd < rtems_libio_number_iops) { - unsigned int flags; - - fp = rtems_bsd_fd_to_fp(fd); - flags = rtems_libio_iop_hold(&fp->f_io); - if ((flags & LIBIO_FLAGS_OPEN) == 0) { - rtems_libio_iop_drop(&fp->f_io); - fp = NULL; - error = EBADF; - } else if (fp->f_io.pathinfo.handlers != &socketops) { - rtems_libio_iop_drop(&fp->f_io); - fp = NULL; - error = ENOTSOCK; - } else { - if (fflagp != NULL) { - *fflagp = rtems_bsd_libio_flags_to_fflag( - fp->f_io.flags); - } - - error = 0; - } - } else { - fp = NULL; - error = EBADF; - } - - *fpp = fp; - - return (error); -} - -#define getsock_cap(td, fd, rights, fpp, fflagp, havecapsp) rtems_bsd_getsock(fd, fpp, fflagp) -#endif /* __rtems__ */ /* * System call interface to the socket abstraction. @@ -179,9 +148,6 @@ rtems_bsd_getsock(int fd, struct file **fpp, u_int *fflagp) #define COMPAT_OLDSOCK #endif -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_socket(struct thread *td, struct socket_args *uap) { @@ -227,43 +193,10 @@ kern_socket(struct thread *td, int domain, int type, int protocol) (void) fo_ioctl(fp, FIONBIO, &fflag, td->td_ucred, td); td->td_retval[0] = fd; } -#ifndef __rtems__ fdrop(fp, td); -#endif /* __rtems__ */ return (error); } -#ifdef __rtems__ -int -socket(int domain, int type, int protocol) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct socket_args ua = { - .domain = domain, - .type = type, - .protocol = protocol - }; - int error; - if (td != NULL) { - error = sys_socket(td, &ua); - } else { - error = ENOMEM; - } - - if (error == 0) { - return td->td_retval[0]; - } else { - rtems_set_errno_and_return_minus_one(error); - } -} -#endif /* __rtems__ */ - -#ifdef __rtems__ -static int kern_bindat(struct thread *td, int dirfd, int fd, - struct sockaddr *sa); - -static -#endif /* __rtems__ */ int sys_bind(struct thread *td, struct bind_args *uap) { @@ -283,27 +216,6 @@ sys_bind(struct thread *td, struct bind_args *uap) } return (error); } -#ifdef __rtems__ -int -bind(int socket, const struct sockaddr *address, socklen_t address_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct bind_args ua = { - .s = socket, - .name = address, - .namelen = address_len - }; - int error; - - if (td != NULL) { - error = sys_bind(td, &ua); - } else { - error = ENOMEM; - } - - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ int kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr *sa) @@ -366,9 +278,6 @@ sys_bindat(struct thread *td, struct bindat_args *uap) } #endif /* __rtems__ */ -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_listen(struct thread *td, struct listen_args *uap) { @@ -397,31 +306,7 @@ kern_listen(struct thread *td, int s, int backlog) } return (error); } -#ifdef __rtems__ -int -listen(int socket, int backlog) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct listen_args ua = { - .s = socket, - .backlog = backlog - }; - int error; - if (td != NULL) { - error = sys_listen(td, &ua); - } else { - error = ENOMEM; - } - - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ - -#ifdef __rtems__ -static int kern_accept4(struct thread *td, int s, struct sockaddr **name, - socklen_t *namelen, int flags, struct file **fp); -#endif /* __rtems__ */ /* * accept1() */ @@ -464,43 +349,17 @@ accept1(td, s, uname, anamelen, flags) sizeof(namelen)); if (error != 0) fdclose(td, fp, td->td_retval[0]); -#ifndef __rtems__ fdrop(fp, td); -#endif /* __rtems__ */ free(name, M_SONAME); return (error); } -#ifdef __rtems__ -int -accept(int socket, struct sockaddr *__restrict address, - socklen_t *__restrict address_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - int error; - - if (td != NULL) { - error = accept1(td, socket, address, address_len, - ACCEPT4_INHERIT); - } else { - error = ENOMEM; - } - if (error == 0) { - return td->td_retval[0]; - } else { - rtems_set_errno_and_return_minus_one(error); - } -} -#endif /* __rtems__ */ - -#ifndef __rtems__ int kern_accept(struct thread *td, int s, struct sockaddr **name, socklen_t *namelen, struct file **fp) { return (kern_accept4(td, s, name, namelen, ACCEPT4_INHERIT, fp)); } -#endif /* __rtems__ */ int kern_accept4(struct thread *td, int s, struct sockaddr **name, @@ -613,15 +472,12 @@ done: } else *fp = NULL; } -#ifndef __rtems__ if (nfp != NULL) fdrop(nfp, td); -#endif /* __rtems__ */ fdrop(headfp, td); return (error); } -#ifndef __rtems__ int sys_accept(td, uap) struct thread *td; @@ -654,14 +510,7 @@ oaccept(td, uap) ACCEPT4_INHERIT | ACCEPT4_COMPAT)); } #endif /* COMPAT_OLDSOCK */ -#endif /* __rtems__ */ - -#ifdef __rtems__ -static int kern_connectat(struct thread *td, int dirfd, int fd, - struct sockaddr *sa); -static -#endif /* __rtems__ */ int sys_connect(struct thread *td, struct connect_args *uap) { @@ -681,27 +530,6 @@ sys_connect(struct thread *td, struct connect_args *uap) } return (error); } -#ifdef __rtems__ -int -connect(int socket, const struct sockaddr *address, socklen_t address_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct connect_args ua = { - .s = socket, - .name = address, - .namelen = address_len - }; - int error; - - if (td != NULL) { - error = sys_connect(td, &ua); - } else { - error = ENOMEM; - } - - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ int kern_connectat(struct thread *td, int dirfd, int fd, struct sockaddr *sa) @@ -864,21 +692,15 @@ kern_socketpair(struct thread *td, int domain, int type, int protocol, (void) fo_ioctl(fp1, FIONBIO, &fflag, td->td_ucred, td); (void) fo_ioctl(fp2, FIONBIO, &fflag, td->td_ucred, td); } -#ifndef __rtems__ fdrop(fp1, td); fdrop(fp2, td); -#endif /* __rtems__ */ return (0); free4: fdclose(td, fp2, rsv[1]); -#ifndef __rtems__ fdrop(fp2, td); -#endif /* __rtems__ */ free3: fdclose(td, fp1, rsv[0]); -#ifndef __rtems__ fdrop(fp1, td); -#endif /* __rtems__ */ free2: if (so2 != NULL) (void)soclose(so2); @@ -888,9 +710,6 @@ free1: return (error); } -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_socketpair(struct thread *td, struct socketpair_args *uap) { @@ -914,34 +733,7 @@ sys_socketpair(struct thread *td, struct socketpair_args *uap) #endif /* __rtems__ */ return (error); } -#ifdef __rtems__ -int -socketpair(int domain, int type, int protocol, int *socket_vector) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct socketpair_args ua = { - .domain = domain, - .type = type, - .protocol = protocol, - .rsv = socket_vector - }; - int error; - - if (td != NULL) { - error = sys_socketpair(td, &ua); - } else { - error = ENOMEM; - } - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ - -#ifdef __rtems__ -static int -kern_sendit( struct thread *td, int s, struct msghdr *mp, int flags, - struct mbuf *control, enum uio_seg segflg); -#endif /* __rtems__ */ static int sendit(struct thread *td, int s, struct msghdr *mp, int flags) { @@ -1016,9 +808,7 @@ kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags, struct uio auio; struct iovec *iov; struct socket *so; -#ifndef __rtems__ cap_rights_t *rights; -#endif /* __rtems__ */ #ifdef KTRACE struct uio *ktruio = NULL; #endif @@ -1033,6 +823,8 @@ kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags, AUDIT_ARG_SOCKADDR(td, AT_FDCWD, mp->msg_name); rights = &cap_send_connect_rights; } +#else /* __rtems__ */ + rights = NULL; #endif /* __rtems__ */ error = getsock_cap(td, s, rights, &fp, NULL, NULL); if (error != 0) { @@ -1111,9 +903,6 @@ bad: return (error); } -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_sendto(struct thread *td, struct sendto_args *uap) { @@ -1138,34 +927,6 @@ sys_sendto(struct thread *td, struct sendto_args *uap) return (sendit(td, uap->s, &msg, uap->flags)); } #ifdef __rtems__ -ssize_t -sendto(int socket, const void *message, size_t length, int flags, - const struct sockaddr *dest_addr, socklen_t dest_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct sendto_args ua = { - .s = socket, - .buf = (caddr_t) message, - .len = length, - .flags = flags, - .to = dest_addr, - .tolen = dest_len - }; - int error; - - if (td != NULL) { - error = sys_sendto(td, &ua); - } else { - error = ENOMEM; - } - - if (error == 0) { - return td->td_retval[0]; - } else { - rtems_set_errno_and_return_minus_one(error); - } -} - int rtems_bsd_sendto(int socket, struct mbuf *m, int flags, const struct sockaddr *dest_addr) @@ -1175,7 +936,7 @@ rtems_bsd_sendto(int socket, struct mbuf *m, int flags, struct socket *so; int error; - error = getsock_cap(td->td_proc->p_fd, socket, CAP_WRITE, &fp, NULL, NULL); + error = getsock_cap(td, socket, CAP_WRITE, &fp, NULL, NULL); if (error) return (error); so = (struct socket *)fp->f_data; @@ -1232,9 +993,6 @@ osendmsg(struct thread *td, struct osendmsg_args *uap) #endif #endif /* __rtems__ */ -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_sendmsg(struct thread *td, struct sendmsg_args *uap) { @@ -1257,35 +1015,7 @@ sys_sendmsg(struct thread *td, struct sendmsg_args *uap) free(iov, M_IOV); return (error); } -#ifdef __rtems__ -ssize_t -sendmsg(int socket, const struct msghdr *message, int flags) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct sendmsg_args ua = { - .s = socket, - .msg = message, - .flags = flags - }; - int error; - - if (td != NULL) { - error = sys_sendmsg(td, &ua); - } else { - error = ENOMEM; - } - - if (error == 0) { - return td->td_retval[0]; - } else { - rtems_set_errno_and_return_minus_one(error); - } -} -#endif /* __rtems__ */ -#ifdef __rtems__ -static -#endif /* __rtems__ */ int kern_recvit(struct thread *td, int s, struct msghdr *mp, enum uio_seg fromseg, struct mbuf **controlp) @@ -1460,9 +1190,6 @@ recvit(struct thread *td, int s, struct msghdr *mp, void *namelenp) return (error); } -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_recvfrom(struct thread *td, struct recvfrom_args *uap) { @@ -1489,35 +1216,6 @@ sys_recvfrom(struct thread *td, struct recvfrom_args *uap) done2: return (error); } -#ifdef __rtems__ -ssize_t -recvfrom(int socket, void *__restrict buffer, size_t length, int flags, - struct sockaddr *__restrict address, socklen_t *__restrict address_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct recvfrom_args ua = { - .s = socket, - .buf = buffer, - .len = length, - .flags = flags, - .from = address, - .fromlenaddr = address_len - }; - int error; - - if (td != NULL) { - error = sys_recvfrom(td, &ua); - } else { - error = ENOMEM; - } - - if (error == 0) { - return td->td_retval[0]; - } else { - rtems_set_errno_and_return_minus_one(error); - } -} -#endif /* __rtems__ */ #ifndef __rtems__ #ifdef COMPAT_OLDSOCK @@ -1578,9 +1276,6 @@ orecvmsg(struct thread *td, struct orecvmsg_args *uap) #endif #endif /* __rtems__ */ -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_recvmsg(struct thread *td, struct recvmsg_args *uap) { @@ -1609,35 +1304,7 @@ sys_recvmsg(struct thread *td, struct recvmsg_args *uap) free(iov, M_IOV); return (error); } -#ifdef __rtems__ -ssize_t -recvmsg(int socket, struct msghdr *message, int flags) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct recvmsg_args ua = { - .s = socket, - .msg = message, - .flags = flags - }; - int error; - - if (td != NULL) { - error = sys_recvmsg(td, &ua); - } else { - error = ENOMEM; - } - if (error == 0) { - return td->td_retval[0]; - } else { - rtems_set_errno_and_return_minus_one(error); - } -} -#endif /* __rtems__ */ - -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_shutdown(struct thread *td, struct shutdown_args *uap) { @@ -1673,23 +1340,7 @@ kern_shutdown(struct thread *td, int s, int how) } return (error); } -#ifdef __rtems__ -int -shutdown(int socket, int how) -{ - struct shutdown_args ua = { - .s = socket, - .how = how - }; - int error = sys_shutdown(NULL, &ua); - - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ -#ifdef __rtems__ -static -#endif /* __rtems__ */ int sys_setsockopt(struct thread *td, struct setsockopt_args *uap) { @@ -1697,39 +1348,10 @@ sys_setsockopt(struct thread *td, struct setsockopt_args *uap) return (kern_setsockopt(td, uap->s, uap->level, uap->name, uap->val, UIO_USERSPACE, uap->valsize)); } -#ifdef __rtems__ -int -setsockopt(int socket, int level, int option_name, const void *option_value, - socklen_t option_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct setsockopt_args ua = { - .s = socket, - .level = level, - .name = option_name, - .val = __DECONST(void *, option_value), - .valsize = option_len - }; - int error; - - if (td != NULL) { - error = sys_setsockopt(td, &ua); - } else { - error = ENOMEM; - } - - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ int -#ifndef __rtems__ kern_setsockopt(struct thread *td, int s, int level, int name, void *val, enum uio_seg valseg, socklen_t valsize) -#else /* __rtems__ */ -kern_setsockopt(struct thread *td, int s, int level, int name, const void *val, - enum uio_seg valseg, socklen_t valsize) -#endif /* __rtems__ */ { struct socket *so; struct file *fp; @@ -1744,11 +1366,7 @@ kern_setsockopt(struct thread *td, int s, int level, int name, const void *val, sopt.sopt_dir = SOPT_SET; sopt.sopt_level = level; sopt.sopt_name = name; -#ifndef __rtems__ sopt.sopt_val = val; -#else /* __rtems__ */ - sopt.sopt_val = __DECONST(void *, val); -#endif /* __rtems__ */ sopt.sopt_valsize = valsize; switch (valseg) { case UIO_USERSPACE: @@ -1772,12 +1390,6 @@ kern_setsockopt(struct thread *td, int s, int level, int name, const void *val, return(error); } -#ifdef __rtems__ -static int kern_getsockopt( struct thread *td, int s, int level, int name, - void *val, enum uio_seg valseg, socklen_t *valsize); - -static -#endif /* __rtems__ */ int sys_getsockopt(struct thread *td, struct getsockopt_args *uap) { @@ -1797,30 +1409,6 @@ sys_getsockopt(struct thread *td, struct getsockopt_args *uap) error = copyout(&valsize, uap->avalsize, sizeof (valsize)); return (error); } -#ifdef __rtems__ -int -getsockopt(int socket, int level, int option_name, void *__restrict - option_value, socklen_t *__restrict option_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct getsockopt_args ua = { - .s = socket, - .level = level, - .name = option_name, - .val = (caddr_t) option_value, - .avalsize = option_len - }; - int error; - - if (td != NULL) { - error = sys_getsockopt(td, &ua); - } else { - error = ENOMEM; - } - - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ /* * Kernel version of getsockopt. @@ -1898,28 +1486,6 @@ getsockname1(struct thread *td, struct getsockname_args *uap, int compat) error = copyout(&len, uap->alen, sizeof(len)); return (error); } -#ifdef __rtems__ -int -getsockname(int socket, struct sockaddr *__restrict address, - socklen_t *__restrict address_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct getsockname_args ua = { - .fdes = socket, - .asa = address, - .alen = address_len - }; - int error; - - if (td != NULL) { - error = getsockname1(td, &ua, 0); - } else { - error = ENOMEM; - } - - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ int kern_getsockname(struct thread *td, int fd, struct sockaddr **sa, @@ -1960,7 +1526,6 @@ bad: return (error); } -#ifndef __rtems__ int sys_getsockname(struct thread *td, struct getsockname_args *uap) { @@ -1976,13 +1541,7 @@ ogetsockname(struct thread *td, struct getsockname_args *uap) return (getsockname1(td, uap, 1)); } #endif /* COMPAT_OLDSOCK */ -#endif /* __rtems__ */ -#ifdef __rtems__ -static int -kern_getpeername(struct thread *td, int fd, struct sockaddr **sa, - socklen_t *alen); -#endif /* __rtems__ */ /* * getpeername1() - Get name of peer for connected socket. */ @@ -2013,28 +1572,6 @@ getpeername1(struct thread *td, struct getpeername_args *uap, int compat) error = copyout(&len, uap->alen, sizeof(len)); return (error); } -#ifdef __rtems__ -int -getpeername(int socket, struct sockaddr *__restrict address, - socklen_t *__restrict address_len) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - struct getpeername_args ua = { - .fdes = socket, - .asa = address, - .alen = address_len - }; - int error; - - if (td != NULL) { - error = getpeername1(td, &ua, 0); - } else { - error = ENOMEM; - } - - return rtems_bsd_error_to_status_and_errno(error); -} -#endif /* __rtems__ */ int kern_getpeername(struct thread *td, int fd, struct sockaddr **sa, @@ -2080,7 +1617,6 @@ done: return (error); } -#ifndef __rtems__ int sys_getpeername(struct thread *td, struct getpeername_args *uap) { @@ -2097,7 +1633,6 @@ ogetpeername(struct thread *td, struct ogetpeername_args *uap) return (getpeername1(td, (struct getpeername_args *)uap, 1)); } #endif /* COMPAT_OLDSOCK */ -#endif /* __rtems__ */ static int sockargs(struct mbuf **mp, char *buf, socklen_t buflen, int type) @@ -2137,23 +1672,22 @@ sockargs(struct mbuf **mp, char *buf, socklen_t buflen, int type) return (error); } +#ifdef __rtems__ +#undef getsockaddr int -#ifndef __rtems__ -getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len) +_bsd_getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len) #else /* __rtems__ */ -getsockaddr(struct sockaddr **namp, const struct sockaddr *uaddr, size_t len) +int +getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len) #endif /* __rtems__ */ { struct sockaddr *sa; -#ifndef __rtems__ int error; -#endif /* __rtems__ */ if (len > SOCK_MAXADDRLEN) return (ENAMETOOLONG); if (len < offsetof(struct sockaddr, sa_data[0])) return (EINVAL); -#ifndef __rtems__ sa = malloc(len, M_SONAME, M_WAITOK); error = copyin(uaddr, sa, len); if (error != 0) { @@ -2168,11 +1702,6 @@ getsockaddr(struct sockaddr **namp, const struct sockaddr *uaddr, size_t len) *namp = sa; } return (error); -#else /* __rtems__ */ - sa = memcpy(*namp, uaddr, len); - sa->sa_len = len; - return (0); -#endif /* __rtems__ */ } /* |